-3

我正在研究一个用 PHP 编写的 UDP 欺骗器,我想知道如何伪造这些数据包。任何帮助表示赞赏。谢谢!

4

2 回答 2

0

下面的函数将在 PHP 中创建一个带有端口号的套接字。根据您的欺骗内容,您将需要修改“消息”。在下面的示例中是明文,但应用程序通常以二进制信息的形式传输此信息,需要对其进行保留设计以欺骗它。

function sendUDP($host, $msg, $timeout = 1) {
/* ICMP ping packet with a pre-calculated checksum */
$socket  = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $timeout, 'usec' => 0));

socket_connect($socket, $host, 8000); //Set up to send to port 8000, change to any port

socket_send($socket, $msg, strLen($msg), 0);

$buf = "";
$from = "";
$port = 0; 

@socket_recvfrom($socket , $buf , 24 , 0 , $from , $port );
socket_close($socket); 

return $buf;
}
于 2013-09-16T17:15:22.250 回答
0

只需阅读这些代码:server.php

<?php

//error_reporting( E_ALL );
set_time_limit( 0 );
ob_implicit_flush();
$socket = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
if ( $socket === false ) {
    echo "socket_create() failed:reason:" . socket_strerror( socket_last_error() ) . "\n";
}
$ok = socket_bind( $socket, '202.85.218.133', 11109 );
if ( $ok === false ) {
    echo "socket_bind() failed:reason:" . socket_strerror( socket_last_error( $socket ) );
}
while ( true ) {
    $from = "";
    $port = 0;
    socket_recvfrom( $socket, $buf,1024, 0, $from, $port );
    echo $buf;
    usleep( 1000 );
}
?>

客户端.php

<?php
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
$msg = 'hello';
$len = strlen($msg);
socket_sendto($sock, $msg, $len, 0, '202.85.218.133', 11109);
socket_close($sock);
?>
于 2013-09-16T17:17:54.333 回答