How can I change INVITE message in Asterisk? - asterisk

I am very new in Asterisk. Hope my question is achievable.
My question:
When sip client A calls sip client B through my asterisk server, I want to make a change to the INVITE message which asterisk server send to clientB.
More detail:
The following message is original message sent from Asterisk server to clientB, where "3000" is clientA's userName and "666" is clientA's displayedName (or caller ID in Zoiper APP). I want to swap "3000" and "666" in the message. Either changing .c code or changing .conf is great.
Does anybody could give a hint where to modify SIP INVITE message to sipB when asterisk server receives SIP INVITE from sipA.
INVITE sip:3001#192.168.60.35;transport=UDP SIP/2.0
Via: SIP/2.0/UDP 192.168.60.4:40416;branch=z9hG4bK-524287-1---cfa0bdc915e1bba8;rport
Max-Forwards: 70
Contact: <sip:3000#192.168.60.4:40416;transport=UDP>
To: <sip:3001#192.168.60.35;transport=UDP>
From: "666"<sip:3000#192.168.60.35;transport=UDP>;tag=6a4be72e
Call-ID: DqIzNYN2-TZwiTSB7JdwGQ..
CSeq: 1 INVITE
Allow: INVITE, ACK, CANCEL, BYE, NOTIFY, REFER, MESSAGE, OPTIONS, INFO, SUBSCRIBE
Content-Type: application/sdp
User-Agent: Zoiper rv2.8.40
Allow-Events: presence, kpml, talk
Content-Length: 240

You should do this from dialplan. It's a simple swap of variables:
Set(TEMP=${CALLERID(name)})
Set(CALLERID(name)=${CALLERID(num)})
Set(CALLERID(num)=${TEMP})
Please also refer to the documentation with the CLI command: core show function CALLERID

Related

a2billing sip invite wrong format?

I am trying to implement a2billing for prepaid cards solution , I have tried to make the destination call everything is good , reading the cards and balance , but when I am asked to enter the number I wish to call , the format of sip invite get messed up ,
Example , when I try to call a number XXXX and assuming that my provider ip yy.yy.yy.yy ,phone that I call from zzzzzz, the invite would look like this :
INVITE sip:XXXX%7C60%7CHRrL(8508000%3A61000%3A30000)#yy.yy.yy.yy SIP/2.0
From: <sip:zzzzzz#10.64.4.79>;tag=as07522260
To: <sip:XXXX%7C60%7CHRrL(8508000%3A61000%3A30000)#yy.yy.yy.yy>
Contact: <sip:zzzzzz#10.64.4.79:5060>
Call-ID: 3ea2b73a7d68626070d3a45c4e632749#10.64.4.79:5060
CSeq: 102 INVITE
User-Agent: FPBX-2.11.0(11.20.0)
Date: Thu, 05 Oct 2017 04:28:06 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Content-Type: application/sdp
Content-Length: 277
the problem here is the %7C60%7CHR stuff that is added , can't seem to find the configuration to override them ,
Regards,
First of all you have know, that a2billing is WEB and control part and not deal at all with invites.
Invites is sip part, it is asterisk
In your case however it is more then likly that you have incorrect trunk setup, consult with your provider or linux admin.
After looking into most the problems that you may encounter while using asterisk and a2billing was solved by changing the global system variables,
and for my problem changing the parameter dialcommand_param
Regards,

postfix forwarding mails getting bounced back to original sender

I am using postfix as mail server for "myDomain.com". Further I have installed a forwarding service to gmail. That works fine so far. But when someone sends me an e-mail with e.g. an executable, gmail bounces the mail. This notification mail from gmail will be relayed to the original sender, but not to me.
What I want to accomplish:
"A" sends an executable to my address at "myDomain.com".
The email will be forwarded to gmail. -> gmail bounces the mail back with a notification.
I want to receive this bounced email in my mailbox at "myDomain.com".
the original sender "A" doesn't get anything from gmail.
Any ideas at how to accomplish that?
Thank You!
The email will be forwarded to gmail. -> gmail bounces the mail back with a notification.
I want to receive this bounced email in my mailbox at "myDomain.com".
the original sender "A" doesn't get anything from gmail.
Gmail is not sending a bounce to the original sender.
The communications flow is like this:
Step 1: Original sender mail server communicates with your server (lets call it mx.example.com)
HELO originalsendermx
250 mx.example.com
MAIL FROM: originalsender#spammy.example
250 2.1.0 Ok
RCPT TO: a#example.com
250 2.1.5 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
Subject: this is a virus in an executable for a#example.com
<base64encodedvirusexe>
.
250 2.0.0 Ok: queued as C9F786427FA
QUIT
221 2.0.0 Bye
Step 2: your postfix server has a rule to forward all mail to a#example.com to b#example.org, so it connects to mx.example.org:
HELO mx.example.com
250 mx.example.org
MAIL FROM originalsender#spammy.example
250 2.1.0 Ok
RCPT TO: b#example.org
250 2.1.5 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
Subject: this is a virus in an executable for a#example.com
<base64encodedvirusexe>
.
550 5.2.3 The content of this message is not allowed
QUIT
221 2.0.0 Bye
So your server accepted the mail from original sender, but example.org (or gmail in your case) didn't accept the mail from your server. According to RFC 2821 your server should generate a Non-Delivery notification and send it to original sender:
If an SMTP server has accepted the task of relaying the mail and later
finds that the destination is incorrect or that the mail cannot be
delivered for some other reason, then it MUST construct an
"undeliverable mail" notification message and send it to the
originator of the undeliverable mail.
And this is the default behaviour of postfix. OTOH, common sense dictates you shouldn't send a bounce in this situation, and RFC5321 agrees.
The fastest way to accomplish this would be to modify master.cf to never send bounces:
bounce unix - - n - 0 discard
But it's a little extreme and probably undoable in many environments. You could use header_checks to narrow it down a little.
The important bit is that gmail isn't bouncing anything, it's just rejecting it. Your server is the one bouncing it.
I've had more or less the same problem; I've noticed that Gmail uses the SMTP response code 421 in this case. Since it's not a 5xx code, that means that the mail is queued for a later retry and sits in the deferred queue. So I built a cronjob to clear these mails out of the queue every hour, running the following command:
mailq | egrep -i -B 1 'google.com.*421-4.7.0.*gsmtp' | egrep -v '^\(|--' | cut -d' ' -f1 | postsuper -v -d -
Exact error message format may vary, but 421-4.7.0 seems to be the common denominator.

SIP/2.0 400 Sip message body is shorter that is indicated by the content length

During SIP communicating between my application, Freeswitch, and nextiva trunk, I am getting the following error message from 208.73.146.95:
SIP/2.0 400 Sip message body is shorter that is indicated by the content length
The previous message is one INCOMING to FS ans is
SIP/2.0 100 Trying
And before previous message is
INVITE sip:MYNUMBER#208.73.146.95 SIP/2.0
which content length is exactly correct. Many more previous messages are without contents, and long before message is again has exact length.
What this message can mean?
This is actually a Bad request message for larger Content Length than the body of a SIP message. If you send it over UDP the receiving party will respond with 400 Bad Request error, if you send it over TCP, receiving party will wait for more data for a certain period of time. Let's have an example:
INVITE sip:user#example.com SIP/2.0
Via: SIP/2.0/UDP host5.example.com;branch=z9hG4bK-39234-23523
Max-Forwards: 80
To: sip:j.user#example.com
From: sip:caller#example.net;tag=93942939o2
Contact: <sip:caller#hungry.example.net>
Call-ID: clerr.0ha0isndaksdjweiafasdk3
CSeq: 11 INVITE
Content-Type: application/sdp
Content-Length: 10000
v=0
o=mhandley 29739 7272939 IN IP4 208.73.146.95
c=IN IP4 208.73.146.95
t=0 0
m=audio 49217 RTP/AVP 0 12
m=video 3227 RTP/AVP 31
a=rtpmap:31 LPC
Here is an example of SIP message for which receiving party will respond with such Bad request. Because "Contnt-Length: 10000" is not a valid header information in this SIP message. To calculate actual Content-Length, you should count characters of the body part of this message. Here body part is starting from "v=0.......a=rtpmap:31 LPC". You can easily count the characters of this body part using a online character counting tool such as http://www.charactercountonline.com/ .
So, actual header information should be with "Content-Length: 145" for this sip message. The reference of this information is https://www.rfc-editor.org/rfc/rfc4475 .
Hope this answer will be helpful to someone.

HTTPListener response - how to define packet boundaries

I am using the HTTPListener class to implement a basic web server. My response uses a Content-Type of "multipart/x-mixed-replace" to return a stream of JPEG images. I am able to construct my response correctly, however my web client does not properly interpret the response due to the way in which the response is broken across IP packet boundaries.
Using a separate server implemented in python, I am able to generate a good, working case. The response to the client's HTTP GET request looks like this:
packet 1:
HTTP/1.1 200 OK
packet 2:
Server: (myServer)
Date: (the date)
Connection: close
(other header info)
Content-Type: multipart/x-mixed-replace; boundary=myboundary
packet 3:
--myboundary
Content-Length: 1042
Content-Type: image/jpeg
(jpeg data)
In the failed case, using the HTTPListener, everything gets sent in a single packet
packet 1:
HTTP/1.1 200 OK
Server: (myServer)
Date: (the date)
Connection: close
(other header info)
Content-Type: multipart/x-mixed-replace; boundary=myboundary
--myboundary
Content-Length: 1042
Content-Type: image/jpeg
(jpeg data)
So my question is, how do I manipulate the HTTPListenerResponse's OutputStream to force a packet boundary? I want to be able to specify some data, manually tell the OutputStream to push out a packet, then specify some more data and push out another packet. Does the HTTPListener offer this level of control, or do I need to instead use a TCPListener? I've not been able to find a solution; please help!
If your client doesn't work because of IP packet boundaries it is severely broken. Fix the client, don't add crutches for it in a place where there isn't a problem. HTTP is defined over TCP, and TCP is a byte-stream protocol. Period. Any correctly written TCP program, let alone an HTTP client, doesn't care where the packet boundaries are. If your client misbehaves in this way it will misbehave in other ways as well. Fix it.

HTTP Packets, Whats Happening?

basically, i was wiresharking packets on my PS3 while viewing Motorstorm Leaderboards. The leaderboards are sent to my ps3 in XML format but only after i have been authorised. So can someone please tell me what is happening between these three packets and how i could replicate it in a browser?
Packet 1 From my PS3 to Sony Servers
POST /ranking_view/func/get_player_rank HTTP/1.1
Host: ranking-view-a01.u0.np.community.playstation.net
Connection: Keep-Alive
Content-Length: 213
Authorization: Digest username="c7y-ranking01", realm="c7y-ranking", nonce="2SpsV4WABAA=47a2b36030cd94de1190f6b9f05db1bd5584bc2a", uri="/ranking_view/func/get_player_rank", qop="auth", nc="00000001", cnonce="d4eb1eb60ab4efaea1476869d83a6e0b", response="96b55c6e79f84dd41b46eb66bed1c167"
Accept-Encoding: identity
User-Agent: PS3Community-agent/1.0.0 libhttp/1.0.0
<?xml version="1.0" encoding="utf-8"?><ranking platform="ps3" sv="3.15"><titleid>NPWR00012_00</titleid><board>7</board><jid>Panzerborn#a5.gb.np.playstation.net</jid><option message="false" info="false"/></ranking>
Packet 2 Sony Server Response to my PS3
Date: Fri, 26 Feb 2010 19:06:12 GMT
WWW-Authenticate: Digest realm="c7y-ranking", nonce="a3PFl4WABAA=6d375259676ec79641448a8032a795b8e12ccae4", algorithm=MD5, stale=true, qop="auth"
Content-Length: 401
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>401 Authorization Required</title>
</head><body>
<h1>Authorization Required</h1>
<p>This server could not verify that you
are authorized to access the document
requested. Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p>
</body></html>
Packet 3 PS3 response to Sony Servers last packet
POST /ranking_view/func/get_player_rank HTTP/1.1
Host: ranking-view-a01.u0.np.community.playstation.net
Connection: Keep-Alive
Authorization: Digest username="c7y-ranking01", realm="c7y-ranking", nonce="a3PFl4WABAA=6d375259676ec79641448a8032a795b8e12ccae4", uri="/ranking_view/func/get_player_rank", qop="auth", nc="00000001", cnonce="58869490a891002d8c56573496274a3a", response="ca3d6f252d4e398b8f751c201a3f8f08"
Accept-Encoding: identity
User-Agent: PS3Community-agent/1.0.0 libhttp/1.0.0
<?xml version="1.0" encoding="utf-8"?><ranking platform="ps3" sv="3.15"><titleid>NPWR00012_00</titleid><board>7</board><jid>Panzerborn#a5.gb.np.playstation.net</jid><option message="false" info="false"/></ranking>
I tried to replicate this in Firefox and tamper headers as well as in PHP cURL but im getting nowhere. I assume it is to do with the nonce, cnonce and responce variables that keep changing >< please help =)
Nonce, cnonce and so on are related to HTTP Digest Authentication, which is an authentication mechanism that enables authentication without sending a password in plain text. So if you want to cheat in your PS3 game, you'll first have to hack that password out of the MD5 hash, I guess.
And it's not called HTTP packets, on layer 7 you would usually say request/response or similar.
The nonce an nonce and cnonce look like hash codes.
One possible defense mechanism against cheaters could be this:
def ps3client_send_score():
score = "bazillion points"
nonce = md5(score + "something you don't know about")
send_to_server(score, nonce)
On the server side:
def get_client_score(score, nonce):
if md5(score+"something you don't know about")==nonce:
accept_score(score)
else:
reject_score_and_ban_the_fool_if_he_continues_this()
So unless you want to spend weeks trying to find the salt deep in your game, forget it.

Resources