code_junkie

How do I use raw sockets in Perl?

Nov 11th, 2011
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. use Socket;
  2.  
  3. socket my $socket, PF_INET, SOCK_RAW, 0 or die "Couldn't create raw socket: $!";
  4.  
  5. send $socket, $message, $flags, $to or die "Couldn't send packet: $!";
  6.  
  7. my $from = recv $socket, $message, $length, $flags or die "Couldn't receive from socket: $!";
  8.  
  9. use Net::RawIP;
  10. $a = new Net::RawIP;
  11. $a->set({ip => {saddr => 'my.target.lan',daddr => 'my.target.lan'},
  12. tcp => {source => 139,dest => 139,psh => 1, syn => 1}});
  13. $a->send;
  14.  
  15. $a->ethnew("eth0");
  16. $a->ethset(source => 'my.target.lan',dest =>'my.target.lan');
  17. $a->ethsend;
  18.  
  19. $p = $a->pcapinit("eth0","dst port 21",1500,30);
  20. $f = dump_open($p,"/my/home/log");
  21. loop $p,10,&dump,$f;
Add Comment
Please, Sign In to add comment