Make your own SMS sender in LINUX!!! [Warid, Telenor Added]
-
- Lieutenant Colonel
- Posts: 660
- Joined: Sat Jul 06, 2002 12:35 pm
- Location: Islamabad
- Contact:
PHP Code Problem
Salamz guys;
I was wondering if someone on this forum could have a look at the following code. It is basically a function used to send sms to Ufone mobiles only. It is based on the code contributed by Mr. Masud. All the credit is his and his alone, I just ported it to PHP .
This code in question was working fine a few days ago, but is not working now, maybe I am not doing something correctly. Please tolerate the fact that I am a novice php socket programmer( I have been programming in php for the last 2 years. Working on sockets for the last 15 days ...).
Here is the code:
function send_sms_ufone($num,$nick,$message)
{
$address = "202.125.152.246";
$port = "5000";
$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP) ;
$res=socket_recv($socket,$buf,20,0);
for($i=0;$i<=strlen($buf);$i++)
{
if($i>10)
$id.=$buf[$i];
}
$d=sprintf("ID_RECIVED 0 0 0 0 %s wht",$id);
socket_write($socket,$d,strlen($d));
$msgfin=sprintf("Message MobileServer %s 0 %s %s: %s",$num,$id,$nick,$message);
socket_write($socket,$msgfin,strlen($msgfin));
socket_close($socket);
}
I was wondering if someone on this forum could have a look at the following code. It is basically a function used to send sms to Ufone mobiles only. It is based on the code contributed by Mr. Masud. All the credit is his and his alone, I just ported it to PHP .
This code in question was working fine a few days ago, but is not working now, maybe I am not doing something correctly. Please tolerate the fact that I am a novice php socket programmer( I have been programming in php for the last 2 years. Working on sockets for the last 15 days ...).
Here is the code:
function send_sms_ufone($num,$nick,$message)
{
$address = "202.125.152.246";
$port = "5000";
$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP) ;
$res=socket_recv($socket,$buf,20,0);
for($i=0;$i<=strlen($buf);$i++)
{
if($i>10)
$id.=$buf[$i];
}
$d=sprintf("ID_RECIVED 0 0 0 0 %s wht",$id);
socket_write($socket,$d,strlen($d));
$msgfin=sprintf("Message MobileServer %s 0 %s %s: %s",$num,$id,$nick,$message);
socket_write($socket,$msgfin,strlen($msgfin));
socket_close($socket);
}
sure
salamz!
sorry i was in maree and just came now, i will study and impliment it tomorrow and reply u soon
ALLAHHAFIZ
sorry i was in maree and just came now, i will study and impliment it tomorrow and reply u soon
ALLAHHAFIZ
--SP--
was this working on your side?
output with these errors.
Code: Select all
-Warning: socket_recv() unable to read from socket [107]: Transport endpoint is not connected in /tmp/a.php on line 8
$res=socket_recv($socket,$buf,20,0);
-Warning: socket_write() unable to write to socket [32]: Broken pipe in /tmp/a.php on line 18
$res=socket_write($socket,$d,strlen($d));
-Warning: socket_write() unable to write to socket [32]: Broken pipe in /tmp/a.php on line 22
socket_write($socket,$msgfin,strlen($msgfin));
reg linux user #298274
Hello everyone,
now array would point to array_byte0, and &array would point to the array_reference. But you wouldn't always be lucky enough to have the reference and array at the same place, so watch your code.
IMHO, the problems with gets is not at all related to local process or a privileged one. The reason you were not geting a segfault was that your array was located just after the pointer to that array (by which you refer to it). I gues this diagram would allow you to understand:althoug u already given answer in ur question LOL
all we need is address and second thing about that gets()
you can use dat stuff in a local process , i mean the process whic is run by you, but for the process which hosts users and run by any privilage user then u already hav an exelent defination given bye "zaeemarshad"
Code: Select all
&array --------------> | array | --------|
| array_byte0 | <------|
| array_byte1 |
"I think therefore I am" --- Rene Descartes
salamz!!!
thnx for ur little peice of information!!
Any process which is locally running cant be balmed for buffer overflow, because every one has to use it locally and no interaction between network users, procces run by a user and if he buffer overflow it with any any malicious code it will be run under his privilages.
Privilaged proccess, a procces run by a any privilage user like "root" can be buffer overflowed using gets() function, because of its no boundry check. and any person with un priviliged access can use gets() input to have any work done under privilage user using that gets() function.
thnx for ur little peice of information!!
IMHO read it again, we were discussing gets() usage against buffer overflows, and why we are welcomed by the message of " warning " while using gets(). Althoug this part is informative for meIMHO, the problems with gets is not at all related to local process or a privileged one. The reason you were not geting a segfault was that your array was located just after the pointer to that array (by which you refer to it). I gues this diagram would allow you to understand:
and now some thing about local processes and privilage processes for those who didnt get what we were discussing,now array would point to array_byte0, and &array would point to the array_reference. But you wouldn't always be lucky enough to have the reference and array at the same place, so watch your code.
Any process which is locally running cant be balmed for buffer overflow, because every one has to use it locally and no interaction between network users, procces run by a user and if he buffer overflow it with any any malicious code it will be run under his privilages.
Privilaged proccess, a procces run by a any privilage user like "root" can be buffer overflowed using gets() function, because of its no boundry check. and any person with un priviliged access can use gets() input to have any work done under privilage user using that gets() function.
--SP--
Hello again,
Now that you write your messages in english, we are able to comprehend it. There were more than one queries regarding gets and I didn't know which one you replied to. The query i thought you replied to was regarding the legitimacy of passing &buf instead of buf to gets, which doesn't have anything to do with buffer-overflow.
Now that you write your messages in english, we are able to comprehend it. There were more than one queries regarding gets and I didn't know which one you replied to. The query i thought you replied to was regarding the legitimacy of passing &buf instead of buf to gets, which doesn't have anything to do with buffer-overflow.
"I think therefore I am" --- Rene Descartes
PHP code problem resolved
Dear All;
Salamz;
Sorry could not post this early. The Ufone PHP sending script I posted earlier is not faulty and is working correctly. The problem was with the firewall deployed on the server. It was blocking PHP's attempts to connect to target addresses.
The problem is now resolved.
Thanks to all who contributed to the effort.
Allah Hafiz.
Salamz;
Sorry could not post this early. The Ufone PHP sending script I posted earlier is not faulty and is working correctly. The problem was with the firewall deployed on the server. It was blocking PHP's attempts to connect to target addresses.
The problem is now resolved.
Thanks to all who contributed to the effort.
Allah Hafiz.
hi
salamz!
wtiwana wrote:
I am posting my two working code of PHP here, using fsockopen and socket_connect methods, and they are working perfectly,
second one
practicle example:
http://aosp.net/sms/ufone.htm
http://aosp.net/sms/ufone1.htm
wtiwana wrote:
no your code is not working. "Kdaemon" pointed out some thing in his post as well and the thing which is causing all this problem is that your code dont have socket_connect call.Sorry could not post this early. The Ufone PHP sending script I posted earlier is not faulty and is working correctly. The problem was with the firewall deployed on the server. It was blocking PHP's attempts to connect to target addresses.
The problem is now resolved.
I am posting my two working code of PHP here, using fsockopen and socket_connect methods, and they are working perfectly,
Code: Select all
<?php
if(!($sock = fsockopen("202.125.152.246",5000)))
{
echo "connection failed";
exit();
}
$buf=fread($sock,100);
for($i=0;$i< (strlen($buf)-11);$i++)
{
$id.=$buf[11+$i];
}
$ver=sprintf("ID_RECIVED 0 0 0 0 %s wht",$id);
fputs($sock,$ver);
$msg=sprintf("Message MobileServer %s 0 %s %s: %s",$num,$id,$nick,$message);
fputs($sock,$msg);
fclose($sock);
echo " your message has been send";
?>
Code: Select all
<?php
$address = "202.125.152.246";
$port = 5000;
$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
if (!socket_connect($socket,$address,$port)) {
socket_close($socket);
die("Sock_Error: Socket was unable to bind.\n");
}
$res=socket_recv($socket,$buf,20,0);
for($i=0;$i<=strlen($buf);$i++)
{
if($i>10)
$id.=$buf[$i];
}
$d=sprintf("ID_RECIVED 0 0 0 0 %s wht",$id);
socket_write($socket,$d,strlen($d));
$msgfin=sprintf("Message MobileServer %s 0 %s %s: %s",$num,$id,$nick,$message);
socket_write($socket,$msgfin,strlen($msgfin));
socket_close($socket);
echo " your message has been send";
?>
http://aosp.net/sms/ufone.htm
http://aosp.net/sms/ufone1.htm
--SP--
Sorry about the code
Dear All,
Salamz;
Sorry to all. Yes that is correct, the code I had posted does not have a connect call. I corrected it but forgot to post the right code,,
The code I am using right now is:
function send_sms_ufone($mob,$nick,$message)
{
$address = "202.125.152.246";
$port = "5000";
$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP) ;
$result = socket_connect( $socket, $address, $port);
$res=socket_recv($socket,$buf,20,0);
for($i=0;$i<=strlen($buf);$i++)
{
if($i>10)
$id.=$buf[$i];
}
$sendd=sprintf("ID_RECIVED 0 0 0 0 %s wht",$id);
socket_write($socket,$sendd,strlen($sendd));
$msgfin=sprintf("Message MobileServer %s 0 %s %s: %s",$mob,$id,$nick,$message);
socket_write($socket,$msgfin,strlen($msgfin));
socket_close($socket);
}
The above is the correct one. Hope it is correct
Anyway, I am thinking of implementing a system in which we can be sure that the message has reached or has been delivered to the mobile device. Something like a message delivered notification. The reason for this that if the message has been lost in the way and has not reached its destination then we can resend it.
Any ideas on this.....
Keep up the good work.
Allah Hafiz
P.S. Thanks to Masud and Kdeamon for helping me with the code and thanks to all those who thought about posting a reply but felt lazy enough to type. thanks to ALL. Keep it real Guyz
Salamz;
Sorry to all. Yes that is correct, the code I had posted does not have a connect call. I corrected it but forgot to post the right code,,
The code I am using right now is:
function send_sms_ufone($mob,$nick,$message)
{
$address = "202.125.152.246";
$port = "5000";
$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP) ;
$result = socket_connect( $socket, $address, $port);
$res=socket_recv($socket,$buf,20,0);
for($i=0;$i<=strlen($buf);$i++)
{
if($i>10)
$id.=$buf[$i];
}
$sendd=sprintf("ID_RECIVED 0 0 0 0 %s wht",$id);
socket_write($socket,$sendd,strlen($sendd));
$msgfin=sprintf("Message MobileServer %s 0 %s %s: %s",$mob,$id,$nick,$message);
socket_write($socket,$msgfin,strlen($msgfin));
socket_close($socket);
}
The above is the correct one. Hope it is correct
Anyway, I am thinking of implementing a system in which we can be sure that the message has reached or has been delivered to the mobile device. Something like a message delivered notification. The reason for this that if the message has been lost in the way and has not reached its destination then we can resend it.
Any ideas on this.....
Keep up the good work.
Allah Hafiz
P.S. Thanks to Masud and Kdeamon for helping me with the code and thanks to all those who thought about posting a reply but felt lazy enough to type. thanks to ALL. Keep it real Guyz
salamz!
its already done in the code, how?
1) we are using TCP and the main concept of TCP is to make a three way handshake with the server before sending any information/data. Its work is not over, because after this, it has to control the transmition in which windowing , retransmition, packets numbering etc..... each packet has an ID/number and reciver after taking the packet return the ID number as an acknowledgement of packet has been recived successfully. IF sender recieves no ACK packet then it will resend the packet again and we dont have to do any thing else beacause TCP is doing hard work for us already.
now as you said about how we know weather the sms is delivered or not is little hard when mobile sever(any mobile server) give you an ACK packet and your code will always complete successfully.
second thing is, dont repeat the same message again beacause it wount be delivered, it will show you delivered but in reality it isnt. thats the only check they do.
now one thing left and that is,,, after sending message to the user ask him to mis call you hehehe:):):):)
if any one else have another idea please post it.
wtiwana:: i try my best to explain you the reason of why we cant make such a system. try it ur self u always have a positive responce from a server but that server is not performing its duty then its not over fault .
its already done in the code, how?
1) we are using TCP and the main concept of TCP is to make a three way handshake with the server before sending any information/data. Its work is not over, because after this, it has to control the transmition in which windowing , retransmition, packets numbering etc..... each packet has an ID/number and reciver after taking the packet return the ID number as an acknowledgement of packet has been recived successfully. IF sender recieves no ACK packet then it will resend the packet again and we dont have to do any thing else beacause TCP is doing hard work for us already.
now as you said about how we know weather the sms is delivered or not is little hard when mobile sever(any mobile server) give you an ACK packet and your code will always complete successfully.
second thing is, dont repeat the same message again beacause it wount be delivered, it will show you delivered but in reality it isnt. thats the only check they do.
now one thing left and that is,,, after sending message to the user ask him to mis call you hehehe:):):):)
if any one else have another idea please post it.
wtiwana:: i try my best to explain you the reason of why we cant make such a system. try it ur self u always have a positive responce from a server but that server is not performing its duty then its not over fault .
--SP--