#!/usr/local/bin/perl ######################################################### # wwwpost - A WWW http poster. # # # # POST saved raw form data to a url (cgi script). # # URL to post to and datafile taken from command line. # # # # Usage: wwwpost http://domain.com/form.cgi datafile # # # # The first line of the datafile should be a random # # string like "--ThisRandomString000000000000000--" # # where the zeros are any 15 digit random number as # # long as the same number is used throughout the file. # # That same string should be used at the end of each # # form data as a separator (I figured this was safest, # # I really didn't know what might be in a text area). # # # # --ThisRandomString521929407957940-- # # realname=David+Efflandt&username=efflandt@xnet.com # # --ThisRandomString521929407957940-- # # realname=Joe+Blow&username=joe@bit.bucket.com # # --ThisRandomString521929407957940-- # # # # 15 digit random number can be generated in perl with: # # srand; $n = int(rand 1E15) - 1; # # # ######################################################### # Written by David Efflandt (efflandt@xnet.com) 7/13/97 # # Based on wwwgrab # # Written by Jeff Ballard (ballard@cae.wisc.edu) 7/2/95 # # URL: http://www.engr.wisc.edu/~ballard/ # ######################################################### # This program is freeware. *NO* warranty is expressed,# # implied, nor granted to you in any way. Use of this # # program is at your own risk. # ######################################################### # Log POST reply to this file (uncomment to log results). # $postlog = 'post.log'; # Required for perl5. use Socket; # Given an http address, rip it into its coresponding parts. ($_, $datafile) = @ARGV; if (!$_) { print "Usage: $0 http://www.any.site/form.cgi datafile\n"; print " Where datafile is raw form data to post.\n"; print " Begin the datafile and follow each form with:\n"; print " --ThisRandomString521929407957940--\n"; die " where any 15 digit number is the same thoughout.\n"; } /http:\/\/([^\/]*)\/*([^ ]*)/; $site = $1; $file = "/$2"; if (!$site) { die "Incorrect URL in command line\n"; } $_ = $site; /^([^:]*):*([^ ]*)/; $site = $1; $port = $2; $port = 80 unless $port; $hostname = $site; #print STDERR "[$site] [$port] [$file]\n"; print "$datafile is empty or does not exist\n" unless (-s $datafile); open (IN, "<$datafile") || die "Can't open $datafile: $!\n"; $sep = ; chop($sep); unless ($sep =~ /^--ThisRandomString\d{15}--$/) { print "Form separator string is missing from $datafile\n"; exit; } while () { chop; $line = $_; if ($line ne $sep) { $form .= $line; } else { $len = (length $form); &post_form if $form; $form = ''; sleep(2); # optional } } # Open a socket and post the data sub post_form { ($sockaddr,$there,$response,$tries) = ("Snc4x8"); $there = pack($sockaddr,2,$port, &getaddress($hostname)); ($a, $b, $c, $d) = unpack('C4', $hostaddr); $proto = (getprotobyname ('tcp'))[2]; if (!socket(S,AF_INET,SOCK_STREAM,$proto)) { die "Socket Error: $!\n";} if (!connect(S,$there)) { die "Can't connect: $!\n"; } select(S);$|=1; select(STDOUT); print S "POST $file HTTP/1.0\n"; print S "Content-Type: application/x-www-form-urlencoded\n"; print S "Content-Length: $len\n\n"; print S "$form"; if ($postlog) { open(OUT,">>$postlog") || warn "Can't open $postlog: $!\n"; } while($line = ) { print OUT $line if ($postlog); print $line; } close(S); print "\n"; if ($postlog) { print OUT "\n"; close(OUT); } } sub getaddress { local($host) = @_; local(@ary); @ary = gethostbyname($host); return(unpack("C4",$ary[4])); }