powerfuzzer.py 53.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640
#!/usr/bin/env python

# Powerfuzzer
# Copyright (C) 2008 Marcin Kozlowski
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import lswww,urllib,urllib2,urlparse,socket
import sys,re,getopt,os

import  wx
import  wx.lib.newevent
import wx.richtext as rt

import threading
import time

from wx.lib.wordwrap import wordwrap

import wx.lib.filebrowsebutton as filebrowse

import reportframe



try:
	import cookielib
except ImportError:
	cookielibhere=0
else:
	cookielibhere=1

ID_ABOUT = 101
ID_EXIT  = 102
version = "v1 BETA"




licenseText = "This program is free software; you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation; either version 2 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program; if not, write to the Free Software\nFoundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\n\n"



class worker(threading.Thread):

        root=""
        myls=""
        urls=[]
        forms=[]
        attackedGET=[]
        attackedPOST=[]
        server=""
        proxy={}
        cookie=""
        auth_basic=[]
        color=0
        bad_params=[]
        verbose=2
        doGET=1
        doPOST=1
        doExec=1
        doFileHandling=1
        doInjection=1
        doXSS=1
        doCRLF=1
        timeout=6
	type=""

        box="";
	window=""

        def __init__(self, threadNum, window,URL,type,user,password,cookie,proxy,timeout,verbose,ex_url1,ex_url2,ex_url3,ex_url4):
		#print "worker init"
		#print URL
		#print proxy
                threading.Thread.__init__(self)
                self.threadNum = threadNum
                self.window = window
                self.timeToQuit = threading.Event()
                self.timeToQuit.clear()
                self.root=window.URL
                self.rooturl=window.URL
                self.box=window.rtc
		self.verbose=verbose
		self.timeout=timeout
		self.type=type
		self.window=window

		if len(user):
		  if len(password):
		    self.auth_basic=[user,password]


                if len(cookie):
		  self.cookie=cookie

		if len(proxy):
		  self.proxy=proxy

                

	
		if (ex_url1.find("http://",0)==0) or (ex_url1.find("https://",0)==0):
		  self.addExcludedURL(ex_url1)
                
		if (ex_url2.find("http://",0)==0) or (ex_url2.find("https://",0)==0):
                  self.addExcludedURL(ex_url2)

		if (ex_url3.find("http://",0)==0) or (ex_url3.find("https://",0)==0):
	          self.addExcludedURL(ex_url3)


	        if (ex_url4.find("http://",0)==0) or (ex_url4.find("https://",0)==0):
	          self.addExcludedURL(ex_url4)








                
        def stop(self):
                self.timeToQuit.set()
        def run(self):
		#print "self.rooturl"+self.rooturl
                self.server=urlparse.urlparse(self.rooturl)[1]
                self.myls=lswww.lswww(self.rooturl,self.box,self.timeToQuit)
                self.myls.verbosity(self.verbose)
                socket.setdefaulttimeout(self.timeout)
		self.myls.setTimeOut(self.timeout)

                if len(self.cookie):
                  self.setCookieFile(self.cookie)
                
		if len(self.proxy):	
		  prox={'http':self.proxy}
                  self.setProxy(prox)



                self.myls.setAuthCredentials(self.auth_basic)
                
		if self.type=="GET_XSS":
                  self.setGlobal()
                  self.setGET()
                  self.setXSS()
                elif self.type=="POST_XSS":
                  self.setGlobal()
                  self.setPOST()
                  self.setXSS()
                elif self.type=="GET_ALL":
                  self.setPOST(0)

	         

                if not self.timeToQuit.isSet():
        	  self.browse()
                
		if not self.timeToQuit.isSet():
        	  self.attack()

		wx.CallAfter(self.window.update_status, "Done.")

                wx.CallAfter(self.window.show_rep)

		




	
	def browse(self):
	
               # director = urllib2.OpenerDirector()

               # director.add_handler(urllib2.HTTPHandler())
               # director.add_handler(urllib2.HTTPSHandler())

                if self.cookie!="" and cookielibhere==1:
                        cj = cookielib.LWPCookieJar()
                        if os.path.isfile(self.cookie):
                                cj.load(self.cookie,ignore_discard=True)
                                #director.add_handler(urllib2.HTTPCookieProcessor(cj))
				opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))

                if len(self.proxy):
                        #director.add_handler(urllib2.ProxyHandler(self.proxy))
			opener = urllib2.build_opener(urllib2.ProxyHandler(self.proxy))

		if self.auth_basic!=[]:
			passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
			#print self.root+" "+self.auth_basic[0]+" "+self.auth_basic[1]
			passman.add_password(None, self.root, self.auth_basic[0], self.auth_basic[1])
			#director.add_handler(urllib2.HTTPBasicAuthHandler(passman))
			opener = urllib2.build_opener(urllib2.HTTPBasicAuthHandler(passman))

                #urllib2.install_opener(director)
		try:
			if opener:
                		urllib2.install_opener(opener)
			pass
		except NameError:
			pass
		
		self.myls.go()
		if self.timeToQuit.isSet():
		  return 0
	        self.urls=self.myls.getLinks()
                if self.timeToQuit.isSet():
		  return 0
		self.forms=self.myls.getForms()


	def attack(self):
		if self.urls==[]:
		  #print "Problem scanning website !"
		  #self.box.AppendText("Problem scanning website !")
		  wx.CallAfter(self.window.write_to_box,"Problem scanning website !")


 
		  #sys.exit(1)
		  return
		if self.doGET==1:
		  #print "\nAttacking urls (GET)..."
		  #print  "-----------------------"
                  #self.box.AppendText("\nAttacking urls (GET)...\n")
		  #wx.CallAfter(self.window.write_to_box,"Attacking urls (GET)...")
		  for url in self.urls:
		    if self.timeToQuit.isSet():
		      break
		    if url.find("?")!=-1:
		      self.attackGET(url)
		if self.doPOST==1:
		  #print "\nAttacking forms (POST)..."
		  #print "-------------------------"
		  #self.box.AppendText("\nAttacking forms (POST)...\n")
		  #wx.CallAfter(self.window.write_to_box,"Attacking forms (POST)...");

		  for form in self.forms:
		    if self.timeToQuit.isSet():
		      break
		    if form[1]!={}:
		      self.attackPOST(form)
		if self.doXSS==1:
		  #print "\nLooking for permanent XSS"
		  #print "-------------------------"
		  #self.box.AppendText("\nLooking for permanent XSS\n")
		  wx.CallAfter(self.window.write_to_box,"Looking for permanent XSS")

		  for url in self.urls:
		    if self.timeToQuit.isSet():
		      break
		    self.permanentXSS(url)
		if self.myls.getUploads()!=[]:
			#print "\nUpload scripts found :"
			#print "----------------------"
			#self.box.AppendText("\nUpload scripts found:\n")
			wx.CallAfter(self.window.write_to_box,"Upload scripts found:")
			for url in self.myls.getUploads():
			        if self.timeToQuit.isSet():
				  break
				#print url
				#self.box.AppendText(url+"\n")
				wx.CallAfter(self.window.write_to_box,url+"\n")


	def setTimeOut(self,timeout=6):
		self.timeout=timeout
		self.myls.setTimeOut(self.timeout)

	def setProxy(self,proxy={}):
		self.proxy=proxy
		self.myls.setProxy(proxy)

	def addStartURL(self,url):
		self.myls.addStartURL(url)

	def addExcludedURL(self,url):
		self.myls.addExcludedURL(url)

	def setCookieFile(self,cookie):
	 	self.cookie=cookie
		self.myls.setCookieFile(cookie)

	def setAuthCredentials(self,auth_basic):
		self.auth_basic=auth_basic
		self.myls.setAuthCredentials(auth_basic)

	def addBadParam(self,bad_param):
		self.myls.addBadParam(bad_param)

	def setColor(self):
		self.color=1

	def verbosity(self,vb):
		self.verbose=vb
		self.myls.verbosity(vb)

# following set* functions can be used to create scan modes
	def setGlobal(self,var=0):
	  	"""Activate or desactivate (default) all attacks"""
		self.doGET=var
		self.doPOST=var
		self.doFileHandling=var
		self.doExec=var
		self.doInjection=var
		self.doXSS=var
		self.doCRLF=var

	def setGET(self,get=1):
		self.doGET=get

	def setPOST(self,post=1):
		self.doPOST=post

	def setFileHandling(self,fh=1):
		self.doFileHandling=fh

	def setExec(self,cmds=1):
		self.doExec=cmds

	def setInjection(self,inject=1):
		self.doInjection=inject

	def setXSS(self,xss=1):
		self.doXSS=xss

	def setCRLF(self,crlf=1):
		self.doCRLF=crlf

	def attackGET(self,url):
                wx.CallAfter(self.window.write_to_box,"Attacking urls (GET)...")
		page=url.split('?')[0]
		query=url.split('?')[1]
		params=query.split('&')
		dict={}
		if self.verbose==1:
		  #print "+ attackGET "+url
		  #print "  ",params
		  wx.CallAfter(self.window.write_to_box,"GET attacking "+url+" "+params)

		if query.find("=")>=0:
		  for param in params:
		    dict[param.split('=')[0]]=param.split('=')[1]
		if self.doFileHandling==1: self.attackFileHandling(page,dict)
		if self.doExec==1: self.attackExec(page,dict)
		if self.doInjection==1: self.attackInjection(page,dict)
		if self.doXSS==1: self.attackXSS(page,dict)
		if self.doCRLF==1: self.attackCRLF(page,dict)

	def attackPOST(self,form):
		wx.CallAfter(self.window.write_to_box,"Attacking forms (POST)...")
	  	if self.verbose==1:
		  #print "+ attackPOST "+form[0]
		  #print "  ",form[1]
	          wx.CallAfter(self.window.write_to_box,"POST attacking "+str(form[0])+" "+str(form[1]))
		if self.doFileHandling==1: self.attackFileHandling_POST(form)
		if self.doExec==1: self.attackExec_POST(form)
		if self.doInjection==1: self.attackInjection_POST(form)
		if self.doXSS==1: self.attackXSS_POST(form)

	def attackInjection(self,page,dict):
		payload="\xbf'\"("
		if dict=={}:
		  err=""
		  url=page+"?"+payload
		  if url not in self.attackedGET:
		    if self.verbose==2:
		      #print "+ "+url
                      wx.CallAfter(self.window.write_to_box,"+ "+url)
		    try:
		      req = urllib2.Request(url)
		      u = urllib2.urlopen(req)
		      data=u.read()
		    except (urllib2.URLError,socket.timeout),e:
		      if hasattr(e,'code'):
			data=""
			u = e
		      else:
			return
		    if data.find("You have an error in your SQL syntax")>=0:
		      err="MySQL Injection"
		    if data.find("supplied argument is not a valid MySQL")>0:
		      err="MySQL Injection"
		    if data.find("[Microsoft][ODBC Microsoft Access Driver]")>=0:
		      err="MSSQL Injection"
		    if data.find("java.sql.SQLException: Syntax error or access violation")>=0:
		      err="Java.SQL Injection"
		    if data.find("XPathException")>=0:
		      err="XPath Injection"
	            if data.find("supplied argument is not a valid ldap")>=0 or data.find("javax.naming.NameNotFoundException")>=0:
		      err="LDAP Injection"
		    if err!="":
		      #print err,"(QUERY_STRING) in",page
		      #print "\tEvil url:",url
		      wx.CallAfter(self.window.write_to_box_vuln,err+" (QUERY_STRING) in "+page+" Vulnerable URL:"+url)
		      self.window.findings.append(err+" (QUERY_STRING) in "+page+" Vulnerable URL:"+url)

	            else:
		      if u.code==500:
		        #print "500 HTTP Error code with"
		        #print "\tEvil url:",url
			wx.CallAfter(self.window.write_to_box_vuln,"500 HTTP Error code with Vulnerable URL: "+url)
			self.window.findings.append("500 HTTP Error code with Vulnerable URL: "+url)
		    self.attackedGET.append(url)
		else:
		  for k in dict.keys():
		    if self.timeToQuit.isSet():
		      break

		    err=""
		    tmp=dict.copy()
		    tmp[k]=payload
		    url=page+"?"+urllib.urlencode(tmp)
		    if url not in self.attackedGET:
		      if self.timeToQuit.isSet():
		        break

		      if self.verbose==2:
			#print "+ "+url
			wx.CallAfter(self.window.write_to_box,"+ "+url)
		      try:
			req = urllib2.Request(url)
			u = urllib2.urlopen(req)
			data=u.read()
		      except (urllib2.URLError,socket.timeout),e:
			if hasattr(e,'code'):
			  data=""
			  u = e
			else:
			  continue
		      if data.find("You have an error in your SQL syntax")>=0:
			err="MySQL Injection"
		      if data.find("supplied argument is not a valid MySQL")>0:
			err="MySQL Injection"
		      if data.find("[Microsoft][ODBC Microsoft Access Driver]")>=0:
			err="MSSQL Injection"
		      if data.find("java.sql.SQLException: Syntax error or access violation")>=0:
			err="Java.SQL Injection"
		      if data.find("XPathException")>=0:
		        err="XPath Injection"
		      if data.find("supplied argument is not a valid ldap")>=0 or data.find("javax.naming.NameNotFoundException")>=0:
			err="LDAP Injection"
		      if err!="":
		        if self.color==0:
		          #print err,"("+k+") in",page
		          #print "\tEvil url:",url
			  wx.CallAfter(self.window.write_to_box_vuln,err+" ("+k+") in "+page)
			  wx.CallAfter(self.window.write_to_box_vuln," Vulnerable URL: "+url)
			  self.window.findings.append(err+" ("+k+") in "+page)
			  self.window.findings.append("Vulnerable URL: "+url)
		        else:
		          print err,":",url.replace(k+"=","\033[0;31m"+k+"\033[0;0m=")
		      else:
			if u.code==500:
			  #print "500 HTTP Error code with"
			  #print "\tEvil url:",url
		          wx.CallAfter(self.window.write_to_box_vuln,"500 HTTP Error code with Vulnerable URL"+url)
			  self.window.findings.append("500 HTTP Error code with Vulnerable URL: "+url)
		      self.attackedGET.append(url)

	def attackFileHandling(self,page,dict):
		payloads=["http://www.google.com/",
		          "/etc/passwd", "/etc/passwd\0", "c:\\\\boot.ini", "c:\\\\boot.ini\0",
		          "../../../../../../../../../../etc/passwd", # /.. is similar to / so one such payload is enough :)
		          "../../../../../../../../../../etc/passwd\0", # same with null byte
		          "../../../../../../../../../../boot.ini",
		          "../../../../../../../../../../boot.ini\0"]
		if dict=={}:
		  warn=0
		  inc=0
		  err500=0
		  for payload in payloads:
		    err=""
		    url=page+"?"+urllib.quote(payload)
		    if url not in self.attackedGET:
		      if self.timeToQuit.isSet():
		        break

		      if self.verbose==2:
			#print "+ "+url
			wx.CallAfter(self.window.write_to_box,"+ "+url)
		      self.attackedGET.append(url)
		      if inc==1: continue
		      try:
			req = urllib2.Request(url)
			u = urllib2.urlopen(req)
			data=u.read()
		      except (urllib2.URLError,socket.timeout),e:
			if hasattr(e,'code'):
			  data=""
			  u = e
			else:
			  continue
		      if data.find("root:x:0:0")>=0:
			err="Unix include/fread"
		        inc=1
		      if data.find("[boot loader]")>=0:
		        err="Windows include/fread"
		        inc=1
		      if data.find("<title>Google</title>")>0:
		        err="Remote include"
		        inc=1
		      if data.find("java.io.FileNotFoundException:")>=0 and warn==0:
		        err="Warning Java include/open"
		        warn=1
		      if data.find("fread(): supplied argument is not")>0 and warn==0:
		        err="Warning fread"
		        warn=1
		      if data.find("for inclusion (include_path=")>0 and warn==0:
		        err="Warning include"
		        warn=1
                      if data.find("Failed opening required")>=0 and warn==0:
                        err="Warning require"
                        warn=1
		      if data.find("<b>Warning</b>:  file(")>=0 and warn==0:
			err="Warning file()"
			warn=1
		      if data.find("<b>Warning</b>:  file_get_contents(")>=0:
			err="Warning file_get_contents()"
			warn=1
		      if err!="":
			#print err,"(QUERY_STRING) in",page
			#print "\tEvil url:",url
			wx.CallAfter(self.window.write_to_box_vuln,err+" (QUERY_STRING) in "+page)
			wx.CallAfter(self.window.write_to_box_vuln,"Vulnerable URL: "+url)
			self.window.findings.append(err+" (QUERY_STRING) in "+page)
			self.window.findings.append("Vulnerable URL: "+url)
		      else:
			if u.code==500 and err500==0:
			  err500=1
			  #print "500 HTTP Error code with"
			  #print "\tEvil url:",url
			  wx.CallAfter(self.window.write_to_box_vuln,"500 HTTP Error code with Vulnerable URL: "+url)
			  self.window.findings.append("500 HTTP Error code with Vulnerable URL: "+url)
		for k in dict.keys():
		  warn=0
		  inc=0
		  err500=0
		  for payload in payloads:
		    err=""
		    tmp=dict.copy()
		    tmp[k]=payload
		    url=page+"?"+urllib.urlencode(tmp)
		    if url not in self.attackedGET:
		      if self.timeToQuit.isSet():
		        break

		      if self.verbose==2:
			#print "+ "+url
			wx.CallAfter(self.window.write_to_box,"+ "+url)
		      self.attackedGET.append(url)
		      if inc==1: continue
		      try:
			req = urllib2.Request(url)
			u = urllib2.urlopen(req)
			data=u.read()
		      except (urllib2.URLError,socket.timeout),e:
			if hasattr(e,'code'):
			  data=""
			  u = e
			else:
			  continue
		      if data.find("root:x:0:0")>=0:
			err="Unix include/fread"
		        inc=1
		      if data.find("[boot loader]")>=0:
		        err="Windows include/fread"
		        inc=1
		      if data.find("<title>Google</title>")>0:
		        err="Remote include"
		        inc=1
		      if data.find("java.io.FileNotFoundException:")>=0 and warn==0:
		        err="Warning Java include/open"
		        warn=1
		      if data.find("fread(): supplied argument is not")>0 and warn==0:
		        err="Warning fread"
		        warn=1
		      if data.find("for inclusion (include_path=")>0 and warn==0:
		        err="Warning include"
		        warn=1
                      if data.find("Failed opening required")>=0 and warn==0:
                        err="Warning require"
                        warn=1
		      if data.find("<b>Warning</b>:  file(")>=0 and warn==0:
			err="Warning file()"
			warn=1
		      if data.find("<b>Warning</b>:  file_get_contents(")>=0:
			err="Warning file_get_contents()"
			warn=1
		      if err!="":
		        if self.color==0:
		          #print err,"("+k+") in",page
		          #print "\tEvil url:",url
			  wx.CallAfter(self.window.write_to_box_vuln,err+" ("+k+") in "+page)
			  wx.CallAfter(self.window.write_to_box_vuln,"Vulnerable URL: "+url)
			  self.window.findings.append(err+" ("+k+") in "+page)
			  self.window.findings.append("Vulnerable URL: "+url)
		        else:
		          print err,":",url.replace(k+"=","\033[0;31m"+k+"\033[0;0m=")
		      else:
			if u.code==500 and err500==0:
			  err500=1
			  #print "500 HTTP Error code with"
			  #print "\tEvil url:",url
			  wx.CallAfter(self.window.write_to_box_vuln,"500 HTTP Error code with Vulnerable URL: "+url)
			  self.window.findings.append("500 HTTP Error code with Vulnerable URL: "+url)

	def attackXSS(self,page,dict):
		if dict=={}:
		  err=""
		  payload="<script>var pf_"
		  payload+=page.encode("hex_codec")
		  payload+="_"
		  payload+="QUERYSTRING".encode("hex_codec")
		  payload+="=new Boolean();</script>"
		  url=page+"?"+payload
		  if url not in self.attackedGET:
		    try:
		      if self.verbose==2:
			#print "+ "+url
			wx.CallAfter(self.window.write_to_box,"+ "+url)
		      req = urllib2.Request(url)
		      u = urllib2.urlopen(req)
		      data=u.read()
		    except (urllib2.URLError,socket.timeout),e:
		      if hasattr(e,'code'):
			data=""
			u = e
		      else:
			return
		    if data.find(payload)>=0:
		      #print "XSS (QUERY_STRING) in",page
		      #print "\tEvil url:",url
		      wx.CallAfter(self.window.write_to_box_vuln,"XSS (QUERY_STRING) in "+page+" Evil url: "+url)
		      self.window.findings.append("XSS (QUERY_STRING) in "+page+" Evil url: "+url)
	            else:
		      if u.code==500:
			#print "500 HTTP Error code with"
			#print "\tEvil url:",url
			wx.CallAfter(self.window.write_to_box_vuln,"500 HTTP Error code with Vulnerable URL: "+url)
			self.window.findings.append("500 HTTP Error code with Vulnerable URL: "+url)

		    self.attackedGET.append(url)
		for k in dict.keys():
		  if self.timeToQuit.isSet():
		    break

		  err=""
		  tmp=dict.copy()
		  payload="<script>var pf_"
		  payload+=page.encode("hex_codec")
		  payload+="_"
		  payload+=k.encode("hex_codec")
		  payload+="=new Boolean();</script>"
		  tmp[k]=payload
		  url=page+"?"+urllib.unquote(urllib.urlencode(tmp))
		  if url not in self.attackedGET:
		    if self.verbose==2:
		      #print "+ "+url
		      wx.CallAfter(self.window.write_to_box,"+ "+url)
		    try:
		      req = urllib2.Request(url)
		      u = urllib2.urlopen(req)
		      data=u.read()
		    except (urllib2.URLError,socket.timeout),e:
		      if hasattr(e,'code'):
			data=""
			u = e
		      else:
			continue
		    if data.find(payload)>=0:
		      if self.color==0:
		        #print "XSS ("+k+") in",page
		        #print "\tEvil url:",url
			wx.CallAfter(self.window.write_to_box_vuln,"XSS ("+k+") in "+page)
			wx.CallAfter(self.window.write_to_box_vuln,"Vulnerable URL: "+url)
			self.window.findings.append("XSS ("+k+") in "+page)
			self.window.findings.append("Vulnerable URL: "+url)
		      else:
		        print "XSS",":",url.replace(k+"=","\033[0;31m"+k+"\033[0;0m=")
	            else:
		      if u.code==500:
			#print "500 HTTP Error code with"
			#print "\tEvil url:",url
			wx.CallAfter(self.window.write_to_box_vuln,"500 HTTP Error code with Vulnerable URL: "+url)
			self.window.findings.append("500 HTTP Error code with Vulnerable URL: "+url)

		    self.attackedGET.append(url)

	def attackExec(self,page,dict):
		payloads=["a;env",
		          "a);env",
			  "/e\0"]
		if dict=={}:
		  warn=0
		  cmd=0
		  err500=0
		  for payload in payloads:
		    err=""
		    url=page+"?"+urllib.quote(payload)
		    if url not in self.attackedGET:
		      if self.verbose==2:
			#print "+ "+url
			wx.CallAfter(self.window.write_to_box,"+ "+url)
		      self.attackedGET.append(url)
		      if cmd==1: continue
		      try:
			req = urllib2.Request(url)
			u = urllib2.urlopen(req)
			data=u.read()
		      except (urllib2.URLError,socket.timeout),e:
			if hasattr(e,'code'):
			  data=""
			  u = e
			else:
			  return
		      if data.find("eval()'d code</b> on line <b>")>=0 and warn==0:
			err="Warning eval()"
		        warn=1
		      if data.find("PATH=")>=0 and data.find("PWD=")>=0:
		        err="Command execution"
		        cmd=1
		      if data.find("Cannot execute a blank command in")>=0 and warn==0:
		        err="Warning exec"
		        warn=1
		      if data.find("Fatal error</b>:  preg_replace")>=0 and warn==0:
			err="preg_replace injection"
			warn=1
		      if err!="":
			#print err,"(QUERY_STRING) in",page
			#print "\tEvil url:",url
			wx.CallAfter(self.window.write_to_box_vuln,err+" (QUERY_STRING) in "+page)
			wx.CallAfter(self.window.write_to_box_vuln,"Vulnerable URL: "+url)
			self.window.findings.append(err+" (QUERY_STRING) in "+page)
			self.window.findings.append("Vulnerable URL: "+url)
		      else:
			if u.code==500 and err500==0:
			  err500=1
			  #print "500 HTTP Error code with"
			  #print "\tEvil url:",url
			  wx.CallAfter(self.window.write_to_box_vuln,"500 HTTP Error code with Vulnerable URL: "+url)
			  self.window.findings.append("500 HTTP Error code with Vulnerable URL: "+url)


		for k in dict.keys():
		  if self.timeToQuit.isSet():
		    break

		  warn=0
		  cmd=0
		  err500=0
		  for payload in payloads:
		    err=""
		    tmp=dict.copy()
		    tmp[k]=payload
		    url=page+"?"+urllib.urlencode(tmp)
		    if url not in self.attackedGET:
		      if self.verbose==2:
			#print "+ "+url
			wx.CallAfter(self.window.write_to_box,"+ "+url)
		      self.attackedGET.append(url)
		      if cmd==1: continue
		      try:
			req = urllib2.Request(url)
			u = urllib2.urlopen(req)
			data=u.read()
		      except (urllib2.URLError,socket.timeout),e:
			if hasattr(e,'code'):
			  data=""
			  u = e
			else:
			  continue
		      if data.find("eval()'d code</b> on line <b>")>=0 and warn==0:
			err="Warning eval()"
		        warn=1
		      if data.find("PATH=")>=0 and data.find("PWD=")>=0:
		        err="Command execution"
		        cmd=1
		      if data.find("Cannot execute a blank command in")>0 and warn==0:
		        err="Warning exec"
		        warn=1
		      if data.find("Fatal error</b>:  preg_replace")>=0 and warn==0:
			err="preg_replace injection"
			warn=1
		      if err!="":
		        if self.color==0:
		          #print err,"("+k+") in",page
		          #print "\tEvil url:",url
			  wx.CallAfter(self.window.write_to_box_vuln,err+" ("+k+") in "+page)
			  wx.CallAfter(self.window.write_to_box_vuln,"Vulnerable URL: "+url)
			  self.window.findings.append(err+" ("+k+") in "+page)
			  self.window.findins.append("Vulnerable URL: "+url)
		        else:
		          print err,":",url.replace(k+"=","\033[0;31m"+k+"\033[0;0m=")
		      else:
			if u.code==500 and err500==0:
			  err500=1
			  #print "500 HTTP Error code with"
			  #print "\tEvil url:",url
			  wx.CallAfter(self.window.write_to_box_vuln,"500 HTTP Error code with Vulnerable URL"+url)
			  self.window.findings.append("500 HTTP Error code with Vulnerable URL"+url)
			   

	# Won't work with PHP >= 4.4.2
	def attackCRLF(self,page,dict):
		payload="http://www.google.com\r\nPowerfuzzer: "+version
		if dict=={}:
		  err=""
		  url=page+"?"+payload
		  if url not in self.attackedGET:
		    if self.verbose==2:
		      #print "+ "+url
		      wx.CallAfter(self.window.write_to_box,"+ "+url)
		    try:
		      req = urllib2.Request(url)
		      u = urllib2.urlopen(req)
		      if u.info().has_key('Powerfuzzer'):
			err="CRLF Injection"
		    except (urllib2.URLError,socket.timeout):
		      err=""
		    if err!="":
		      #print err,"(QUERY_STRING) in",page
		      #print "\tEvil url:",url
		      wx.CallAfter(self.window.write_to_box_vuln,err+ "(QUERY_STRING) in "+page)
		      wx.CallAfter(self.window.write_to_box_vuln,"Vulnerable URL: "+url)
		      self.window.findings.append(err+ "(QUERY_STRING) in "+page)
		      self.window.findings.append("Vulnerable URL: "+url)
		    self.attackedGET.append(url)
		else:
		  for k in dict.keys():
		    if self.timeToQuit.isSet():
		      break

		    err=""
		    tmp=dict.copy()
		    tmp[k]=payload
		    url=page+"?"+urllib.urlencode(tmp)
		    if url not in self.attackedGET:
		      if self.verbose==2:
			#print "+ "+url
			wx.CallAfter(self.window.write_to_box,"+ "+url)

		      try:
			req = urllib2.Request(url)
			u = urllib2.urlopen(req)
			if u.info().has_key('Powerfuzzer'):
			  err="CRLF Injection"
		      except (urllib2.URLError,socket.timeout):
			err=""
		      if err!="":
		        if self.color==0:
		          #print err,"("+k+") in",page
		          #print "\tEvil url:",url
			  wx.CallAfter(self.window.write_to_box_vuln,err+" ("+k+") i "+page)
			  wx.CallAfter(self.window.write_to_box_vuln,"Vulnerable URL :"+url)
			  self.window.findings.append(err+" ("+k+") i "+page)
			  self.window.findings.append("Vulnerable URL :"+url)
		        else:
		          print err,":",url.replace(k+"=","\033[0;31m"+k+"\033[0;0m=")
		      self.attackedGET.append(url)

	def attackInjection_POST(self,form):
		payload="\xbf'\"("
		page=form[0]
		dict=form[1]
		err=""
		for k in dict.keys():
		  if self.timeToQuit.isSet():
		    break

		  tmp=dict.copy()
		  tmp[k]=payload
		  if (page,tmp) not in self.attackedPOST:
		    headers={"Accept": "text/plain"}
		    if self.verbose==2:
		      #print "+ "+page
		      #print "  ",tmp
		      wx.CallAfter(self.window.write_to_box,"+ "+page)
		      wx.CallAfter(self.window.write_dic_to_box,tmp)
		    try:
		      req = urllib2.Request(page,urllib.urlencode(tmp),headers)
		      u = urllib2.urlopen(req)
		      data=u.read()
		    except (urllib2.URLError,socket.timeout),e:
		      if hasattr(e,'code'):
			data=""
			u = e
		      else:
			continue
		    if data.find("You have an error in your SQL syntax")>=0:
		      err="MySQL Injection"
		    if data.find("supplied argument is not a valid MySQL")>0:
		      err="MySQL Injection"
		    if data.find("[Microsoft][ODBC Microsoft Access Driver]")>=0:
		      err="MSSQL Injection"
		    if data.find("java.sql.SQLException: Syntax error or access violation")>=0:
		      err="SQL Injection"
		    if data.find("XPathException")>=0:
		      err="XPath Injection"
		    if data.find("supplied argument is not a valid ldap")>=0 or data.find("javax.naming.NameNotFoundException")>=0:
		      err="LDAP Injection"
		    if err!="":
		      #print err,"in",page
		      #print "  with params =",urllib.urlencode(tmp)
		      #print "  coming from",form[2]
		      wx.CallAfter(self.window.write_to_box_vuln,err+" in "+page)
		      wx.CallAfter(self.window.write_to_box_vuln," with params ="+urllib.urlencode(tmp))
		      wx.CallAfter(self.window.write_to_box_vuln," coming from"+form[2])
                      self.window.findings.append(err+" in "+page)
		      self.window.findings.append(" with params ="+urllib.urlencode(tmp))
		      self.window.findings.append(" coming from"+form[2])
	            else:
		      if u.code==500:
			#print "500 HTTP Error code in",page
			#print "  with params =",urllib.urlencode(tmp)
			#print "  coming from",form[2]
			wx.CallAfter(self.window.write_to_box_vuln,"500 HTTP Error code in "+page)
			wx.CallAfter(self.window.write_to_box_vuln,"  with params ="+urllib.urlencode(tmp))
			wx.CallAfter(self.window.write_to_box_vuln," coming from"+form[2])
			self.window.findings.append("500 HTTP Error code in "+page)
			self.window.findings.append("  with params ="+urllib.urlencode(tmp))
			self.window.findings.append(" coming from"+form[2])

	def attackFileHandling_POST(self,form):
		payloads=["http://www.google.com/",
		          "/etc/passwd", "/etc/passwd\0", "c:\\\\boot.ini", "c:\\\\boot.ini\0",
		          "../../../../../../../../../../etc/passwd", # /.. is similar to / so one such payload is enough :)
		          "../../../../../../../../../../etc/passwd\0", # same with null byte
		          "../../../../../../../../../../boot.ini",
		          "../../../../../../../../../../boot.ini\0"]
		page=form[0]
		dict=form[1]
		err=""
		for payload in payloads:
                  warn=0
                  inc=0
		  err500=0
		  for k in dict.keys():
		    if self.timeToQuit.isSet():
		      break

		    tmp=dict.copy()
		    tmp[k]=payload
		    if (page,tmp) not in self.attackedPOST:
		      self.attackedPOST.append((page,tmp))
		      if inc==1: continue
		      headers={"Accept": "text/plain"}
		      if self.verbose==2:
			#print "+ "+page
			#print "  ",tmp
			wx.CallAfter(self.window.write_to_box,"+ "+page)
			wx.CallAfter(self.window.write_dic_to_box,tmp)
			
		      try:
			req = urllib2.Request(page,urllib.urlencode(tmp),headers)
			u = urllib2.urlopen(req)
			data=u.read()
		      except (urllib2.URLError,socket.timeout),e:
			if hasattr(e,'code'):
			  data=""
			  u = e
			else:
			  continue
		      if data.find("root:x:0:0")>=0:
			err="Unix include/fread"
		        inc=1
		      if data.find("[boot loader]")>=0:
		        err="Windows include/fread"
		        inc=1
		      if data.find("<title>Google</title>")>0:
		        err="Remote include"
		        inc=1
		      if data.find("java.io.FileNotFoundException:")>=0 and warn==0:
		        err="Warning Java include/open"
		        warn=1
		      if data.find("fread(): supplied argument is not")>0 and warn==0:
		        err="Warning fread"
		        warn=1
		      if data.find("for inclusion (include_path=")>0 and warn==0:
		        err="Warning include"
		        warn=1
                      if data.find("Failed opening required")>=0 and warn==0:
                        err="Warning require"
                        warn=1
		      if data.find("<b>Warning</b>:  file(")>=0 and warn==0:
			err="Warning file()"
			warn=1
		      if data.find("<b>Warning</b>:  file_get_contents(")>=0:
			err="Warning file_get_contents()"
			warn=1
		      if err!="":
			#print err,"in",page
			#print "  with params =",urllib.urlencode(tmp)
			#print "  coming from",form[2]
			wx.CallAfter(self.window.write_to_box_vuln,err+" in "+page)
			wx.CallAfter(self.window.write_to_box_vuln,"  with params ="+urllib.urlencode(tmp))
			wx.CallAfter(self.window.write_to_box_vuln,"  coming from"+form[2])
			self.window.findings.append(err+" in "+page)
			self.window.findings.append("  with params ="+urllib.urlencode(tmp))
			self.window.findings.append("  coming from"+form[2])
		      else:
			if u.code==500 and err500==0:
			  err500=1
			  #print "500 HTTP Error code in",page
			  #print "  with params =",urllib.urlencode(tmp)
			  #print "  coming from",form[2]
			  wx.CallAfter(self.window.write_to_box_vuln,"500 HTTP Error code in"+page)
			  wx.CallAfter(self.window.write_to_box_vuln," with params ="+urllib.urlencode(tmp))
			  wx.CallAfter(self.window.write_to_box_vuln,"  coming from"+form[2])
			  self.window.findings.append("500 HTTP Error code in"+page)
			  self.window.findings.append(" with params ="+urllib.urlencode(tmp))
			  self.window.findings.append("  coming from "+form[2])

	def attackXSS_POST(self,form):
		page=form[0]
		dict=form[1]
		for k in dict.keys():
		  if self.timeToQuit.isSet():
		    break

		  tmp=dict.copy()
		  payload="<script>var pf_"
		  payload+=page.encode("hex_codec")
		  payload+="_"
		  payload+=k.encode("hex_codec")
		  payload+="=new Boolean();</script>"
		  tmp[k]=payload
		  if (page,tmp) not in self.attackedPOST:
		    headers={"Accept": "text/plain"}
		    if self.verbose==2:
		      #print "+ "+page
		      #print "  ",tmp
		      wx.CallAfter(self.window.write_to_box,"+ "+page)
		      wx.CallAfter(self.window.write_dic_to_box,tmp)
		    try:
		      req = urllib2.Request(page,urllib.unquote(urllib.urlencode(tmp)),headers)
		      u = urllib2.urlopen(req)
		      data=u.read()
		    except (urllib2.URLError,socket.timeout),e:
		      if hasattr(e,'code'):
			data=""
			u = e
		      else:
			continue
		    if data.find(payload)>=0:
		      #print "XSS in",page
		      #print "  with params =",urllib.urlencode(tmp)
		      #print "  coming from",form[2]
		      wx.CallAfter(self.window.write_to_box_vuln,"XSS in "+page)
		      wx.CallAfter(self.window.write_to_box_vuln,"  with params ="+urllib.urlencode(tmp))
		      wx.CallAfter(self.window.write_to_box_vuln,"  coming from "+form[2])
		      self.window.findings.append("XSS in "+page)
		      self.window.findings.append("  with params ="+urllib.urlencode(tmp))
		      self.window.findings.append("  coming from"+form[2])
	            else:
		      if u.code==500:
			#print "500 HTTP Error code in",page
			#print "  with params =",urllib.urlencode(tmp)
			#print "  coming from",form[2]
			wx.CallAfter(self.window.write_to_box_vuln,"500 HTTP Error code in "+page)
			wx.CallAfter(self.window.write_to_box_vuln,"  with params ="+urllib.urlencode(tmp))
			wx.CallAfter(self.window.write_to_box_vuln,"  coming from "+form[2])
			self.window.findings.append("500 HTTP Error code in "+page)
			self.window.findings.append("  with params ="+urllib.urlencode(tmp))
			self.window.findings.append("  coming from "+form[2])
		    self.attackedPOST.append((page,tmp))

	def attackExec_POST(self,form):
		payloads=["a;env",
		          "a);env",
			  "/e\0"]
		page=form[0]
		dict=form[1]
		err=""
		for payload in payloads:
                  warn=0
                  cmd=0
		  err500=0
		  for k in dict.keys():
		    if self.timeToQuit.isSet():
		      break

		    tmp=dict.copy()
		    tmp[k]=payload
		    if (page,tmp) not in self.attackedPOST:
		      self.attackedPOST.append((page,tmp))
		      if cmd==1: continue
		      headers={"Accept": "text/plain"}
		      if self.verbose==2:
			#print "+ "+page
			#print "  ",tmp
			wx.CallAfter(self.window.write_to_box,"+ "+page)
			wx.CallAfter(self.window.write_dic_to_box,tmp)
		      try:
			req = urllib2.Request(page,urllib.urlencode(tmp),headers)
			u = urllib2.urlopen(req)
			data=u.read()
		      except (urllib2.URLError,socket.timeout),e:
			if hasattr(e,'code'):
			  data=""
			  u = e
			else:
			  continue
		      if data.find("eval()'d code</b> on line <b>")>=0 and warn==0:
			err="Warning eval()"
		        warn=1
		      if data.find("PATH=")>=0 and data.find("PWD=")>=0:
		        err="Command execution"
		        cmd=1
		      if data.find("Cannot execute a blank command in")>0 and warn==0:
		        err="Warning exec"
		        warn=1
		      if data.find("Fatal error</b>:  preg_replace")>=0 and warn==0:
			err="preg_replace injection"
			warn=1
		      if err!="":
			#print err,"in",page
			#print "  with params =",urllib.urlencode(tmp)
			#print "  coming from",form[2]
			wx.CallAfter(self.window.write_to_box_vuln,err+" in "+page);
			wx.CallAfter(self.window.write_to_box_vuln,"  with params ="+urllib.urlencode(tmp))
			wx.CallAfter(self.window.write_to_box_vuln,"  coming from "+form[2])
			self.window.findings.append(err+" in "+page)
			self.window.findings.append("  with params ="+urllib.urlencode(tmp))
			self.window.findings.append("  coming from "+form[2])
		      else:
			if u.code==500 and err500==0:
			  err500=1
			  #print "500 HTTP Error code in",page
			  #print "  with params =",urllib.urlencode(tmp)
			  #print "  coming from",form[2]
			  wx.CallAfter(self.window.write_to_box_vuln,"500 HTTP Error code in "+page)
			  wx.CallAfter(self.window.write_to_box_vuln,"  with params ="+urllib.urlencode(tmp))
			  wx.CallAfter(self.window.write_to_box_vuln,"  coming from "+form[2])
			  self.window.findings.append("500 HTTP Error code in "+page)
			  self.window.findings.append("  with params ="+urllib.urlencode(tmp))
			  self.window.findings.append("  coming from "+form[2])

	def permanentXSS(self,url):
		try:
		  req = urllib2.Request(url)
		  u = urllib2.urlopen(req)
		  data=u.read()
		except (urllib2.URLError,socket.timeout):
		  data=""
		p=re.compile("<script>var pf_[0-9a-h]+_[0-9a-h]+=new Boolean\(\);</script>")
		for s in p.findall(data):
		  if self.timeToQuit.isSet():
		    break

		  s=s.split("=")[0].split('_')[1:]
		  #print "Found permanent XSS in",url
		  #print "  attacked by",s[0].decode("hex_codec"),"with field",s[1].decode("hex_codec")
		  wx.CallAfter(self.window.write_to_box_vuln,"Found permanent XSS in "+url)
		  wx.CallAfter(self.window.write_to_box_vuln,"  attacked by "+s[0].decode("hex_codec")+" with field "+s[1].decode("hex_codec"))
		  self.window.findings.append("Found permanent XSS in "+url)
		  self.window.findings.append("  attacked by "+s[0].decode("hex_codec")+" with field "+s[1].decode("hex_codec"))



class MyFrame(wx.Frame):
    def __init__(self, *args, **kwds):

	self.AddRTCHandlers()

        self.go_on=1
        self.threads = []
        self.count = 0

        self.group1_ctrls = []
        self.group2_ctrls = []
        self.URL=""


        self.c1=""
        self.c2=""
        self.c3=""

        self.user=""
        self.password=""

        self.cookie=""

        self.proxy=""

        self.timeout=6

        self.verbose=2
        self.type=""



        self.ex_url1=""
        self.ex_url2=""
        self.ex_url3=""
        self.ex_url4=""

	self.findings=[]


        # begin wxGlade: MyFrame.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)

        # Menu Bar
        self.frame_1_menubar = wx.MenuBar()
        wxglade_tmp_menu = wx.Menu()
        wxglade_tmp_menu.Append(ID_ABOUT, "&About")
        wxglade_tmp_menu.Append(ID_EXIT,"E&xit")
	self.frame_1_menubar.Append(wxglade_tmp_menu, "&File")
        self.SetMenuBar(self.frame_1_menubar)


        # Menu Bar end
        self.frame_1_statusbar = self.CreateStatusBar(1, 0)

        # Tool Bar
        self.frame_1_toolbar = wx.ToolBar(self, -1)
        self.SetToolBar(self.frame_1_toolbar)
        # Tool Bar end
        #self.text_ctrl_2 = wx.TextCtrl(self, -1, "", style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB|wx.TE_MULTILINE|wx.HSCROLL)
        self.rtc = rt.RichTextCtrl(self, style=wx.VSCROLL|wx.HSCROLL);
        wx.CallAfter(self.rtc.SetFocus)




        self.label_2 = wx.StaticText(self, -1, "Credentials")
        self.label_4 = wx.StaticText(self, -1, "User")
        self.text_ctrl_3 = wx.TextCtrl(self, -1, "")
        self.label_5 = wx.StaticText(self, -1, "Password")
        self.text_ctrl_4 = wx.TextCtrl(self, -1, "")
        #self.label_3 = wx.StaticText(self, -1, "Only Perform checks")

        #self.radio_btn_4 = wx.RadioButton(self, -1, "GET", style = wx.RB_GROUP)
        #self.radio_btn_5 = wx.RadioButton(self, -1, "GET XSS")
        #self.radio_btn_6 = wx.RadioButton(self, -1, "POST XSS")
        #self.group2_ctrls.append((self.radio_btn_4))
        #self.group2_ctrls.append((self.radio_btn_5))
        #self.group2_ctrls.append((self.radio_btn_6))
        self.label_6 = wx.StaticText(self, -1, "Verbosity")
        self.radio_btn_1 = wx.RadioButton(self, -1, "Low",  style = wx.RB_GROUP)
        self.radio_btn_2 = wx.RadioButton(self, -1, "Medium")
        self.radio_btn_3 = wx.RadioButton(self, -1, "High")
        self.group1_ctrls.append((self.radio_btn_1))
        self.group1_ctrls.append((self.radio_btn_2))
        self.group1_ctrls.append((self.radio_btn_3))

        #self.label_1 = wx.StaticText(self, -1, "Cookie")
        #self.text_ctrl_1 = wx.TextCtrl(self, -1, "")
	self.fbb = filebrowse.FileBrowseButton(self, -1, labelText='',buttonText='Cookie')
        self.label_10 = wx.StaticText(self, -1, "Target URL")
        self.label_8 = wx.StaticText(self, -1, "Proxy")
        self.text_ctrl_9 = wx.TextCtrl(self, -1, "")
        self.text_ctrl_10 = wx.TextCtrl(self, -1, "")
        self.label_9 = wx.StaticText(self, -1, "Timeout")
        self.spin_ctrl_1 = wx.SpinCtrl(self, -1, "5", min=0, max=100)
        self.button_1 = wx.Button(self, -1, "Scan")
        self.button_2 = wx.Button(self, -1, "Stop")

        self.label_7 = wx.StaticText(self, -1, "Exclude URL(s) or dir", style=wx.ALIGN_CENTRE)
        self.text_ctrl_5 = wx.TextCtrl(self, -1, "")
        self.text_ctrl_6 = wx.TextCtrl(self, -1, "")
        self.text_ctrl_7 = wx.TextCtrl(self, -1, "")
        self.text_ctrl_8 = wx.TextCtrl(self, -1, "")

        self.Bind(wx.EVT_BUTTON, self.do_Scan, self.button_1)
        self.Bind(wx.EVT_BUTTON, self.do_Stop, self.button_2)
	self.Bind(wx.EVT_MENU, self.MenuExit, id=ID_EXIT)
	self.Bind(wx.EVT_MENU, self.MenuAbout, id=ID_ABOUT)


        for radio in self.group1_ctrls:
            self.Bind(wx.EVT_RADIOBUTTON, self.OnGroup1Select, radio )
            radio.SetValue(0)
        #for radio in self.group2_ctrls:
        #    self.Bind(wx.EVT_RADIOBUTTON, self.OnGroup2Select, radio )
        #    radio.SetValue(0)
          
         
        self.radio_btn_3.SetValue(1)
       
        self.__set_properties()
        self.__do_layout()
        # end wxGlade


    def __set_properties(self):
        # begin wxGlade: MyFrame.__set_properties
        self.SetTitle("Powerfuzzer "+version)
        self.SetSize((800, 700))
        self.SetBackgroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_3DFACE))
        self.SetFont(wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "MS Shell Dlg 2"))
        self.frame_1_statusbar.SetStatusWidths([-1])
        # statusbar fields
        frame_1_statusbar_fields = ["Ready"]
        for i in range(len(frame_1_statusbar_fields)):
            self.frame_1_statusbar.SetStatusText(frame_1_statusbar_fields[i], i)
        self.frame_1_toolbar.Realize()
        #self.text_ctrl_2.SetMinSize((800, 150))
        self.rtc.SetMinSize((800,300))
        self.text_ctrl_10.SetMinSize((200, 21))
        self.text_ctrl_5.SetMinSize((200, 21))
        self.text_ctrl_6.SetMinSize((200, 21))
        self.text_ctrl_7.SetMinSize((200, 21))
        self.text_ctrl_8.SetMinSize((200, 21))
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: MyFrame.__do_layout
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        sizer_3 = wx.BoxSizer(wx.VERTICAL)
        grid_sizer_7 = wx.GridSizer(3, 3, 0, 0)
        grid_sizer_6 = wx.GridSizer(3, 3, 0, 0)
        grid_sizer_1 = wx.GridSizer(3, 3, 0, 0)
        grid_sizer_9 = wx.GridSizer(3, 3, 0, 0)
        grid_sizer_8 = wx.GridSizer(3, 3, 0, 0)
        grid_sizer_2 = wx.GridSizer(3, 3, 0, 0)
        grid_sizer_5 = wx.GridSizer(3, 3, 0, 0)
        grid_sizer_4 = wx.GridSizer(3, 3, 0, 0)
        sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
        grid_sizer_3 = wx.GridSizer(3, 3, 0, 0)
        sizer_1.Add(self.rtc, 0, wx.EXPAND, 0)
        grid_sizer_3.Add(self.label_2, 0, 0, 0)
        grid_sizer_3.Add((20, 20), 0, 0, 0)
        grid_sizer_3.Add((20, 20), 0, 0, 0)
        grid_sizer_3.Add(self.label_4, 0, 0, 0)
        grid_sizer_3.Add(self.text_ctrl_3, 0, 0, 0)
        grid_sizer_3.Add((20, 20), 0, 0, 0)
        grid_sizer_3.Add(self.label_5, 0, 0, 0)
        grid_sizer_3.Add(self.text_ctrl_4, 0, 0, 0)
        grid_sizer_3.Add((20, 20), 0, 0, 0)
        sizer_2.Add(grid_sizer_3, 1, wx.EXPAND, 0)
        grid_sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
        #grid_sizer_4.Add(self.label_3, 0, 0, 0)
        grid_sizer_4.Add((20, 20), 0, 0, 0)
        grid_sizer_4.Add((20, 20), 0, 0, 0)
        #grid_sizer_4.Add(self.radio_btn_4, 0, 0, 0)
        #grid_sizer_4.Add(self.radio_btn_5, 0, 0, 0)
        #grid_sizer_4.Add(self.radio_btn_6, 0, 0, 0)
        grid_sizer_4.Add((20, 20), 0, 0, 0)
        grid_sizer_4.Add((20, 20), 0, 0, 0)
        grid_sizer_4.Add((20, 20), 0, 0, 0)
        grid_sizer_1.Add(grid_sizer_4, 1, wx.EXPAND, 0)
        grid_sizer_5.Add(self.label_6, 0, 0, 0)
        grid_sizer_5.Add((20, 20), 0, 0, 0)
        grid_sizer_5.Add((20, 20), 0, 0, 0)
        grid_sizer_5.Add(self.radio_btn_1, 0, 0, 0)
        grid_sizer_5.Add(self.radio_btn_2, 0, 0, 0)
        grid_sizer_5.Add(self.radio_btn_3, 0, 0, 0)
        grid_sizer_5.Add((20, 20), 0, 0, 0)
        grid_sizer_5.Add((20, 20), 0, 0, 0)
        grid_sizer_5.Add((20, 20), 0, 0, 0)
        grid_sizer_1.Add(grid_sizer_5, 1, wx.EXPAND, 0)
        #grid_sizer_2.Add(self.label_1, 0, 0, 0)
        grid_sizer_2.Add(self.fbb, 0, 0, 0)
        grid_sizer_2.Add((20, 20), 0, 0, 0)
        grid_sizer_2.Add((20, 20), 0, 0, 0)
        grid_sizer_2.Add((20, 20), 0, 0, 0)
        grid_sizer_2.Add((20, 20), 0, 0, 0)
        grid_sizer_2.Add((20, 20), 0, 0, 0)
        grid_sizer_2.Add((20, 20), 0, 0, 0)
        grid_sizer_2.Add(self.label_10, 0, 0, 0)
        grid_sizer_1.Add(grid_sizer_2, 1, wx.EXPAND, 0)
        grid_sizer_8.Add(self.label_8, 0, 0, 0)
        grid_sizer_8.Add(self.text_ctrl_9, 0, 0, 0)
        grid_sizer_8.Add((20, 20), 0, 0, 0)
        grid_sizer_8.Add((20, 20), 0, 0, 0)
        grid_sizer_8.Add((20, 20), 0, 0, 0)
        grid_sizer_8.Add((20, 20), 0, 0, 0)
        grid_sizer_8.Add((20, 20), 0, 0, 0)
        grid_sizer_8.Add(self.text_ctrl_10, 0, 0, 0)
        grid_sizer_8.Add((20, 20), 0, 0, 0)
        grid_sizer_1.Add(grid_sizer_8, 1, wx.EXPAND, 0)
        grid_sizer_9.Add(self.label_9, 0, 0, 0)
        grid_sizer_9.Add(self.spin_ctrl_1, 0, 0, 0)
        grid_sizer_9.Add((20, 20), 0, 0, 0)
        grid_sizer_9.Add((20, 20), 0, 0, 0)
        grid_sizer_9.Add((20, 20), 0, 0, 0)
        grid_sizer_9.Add((20, 20), 0, 0, 0)
        grid_sizer_9.Add((20, 20), 0, 0, 0)
        grid_sizer_9.Add(self.button_1, 0, 0, 0)
        grid_sizer_9.Add(self.button_2, 0, 0, 0)
        #grid_sizer_9.Add((20, 20), 0, 0, 0)
        grid_sizer_1.Add(grid_sizer_9, 1, wx.EXPAND, 0)
        sizer_1.Add(grid_sizer_1, 1, wx.EXPAND, 0)
        grid_sizer_6.Add((20, 20), 0, 0, 0)
        grid_sizer_6.Add((20, 20), 0, 0, 0)
        grid_sizer_6.Add((20, 20), 0, 0, 0)
        grid_sizer_6.Add(self.label_7, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
        grid_sizer_6.Add(self.text_ctrl_5, 0, wx.ALIGN_RIGHT, 0)
        grid_sizer_6.Add((20, 20), 0, 0, 0)
        grid_sizer_6.Add((20, 20), 0, 0, 0)
        grid_sizer_6.Add(self.text_ctrl_6, 0, wx.ALIGN_RIGHT, 0)
        grid_sizer_6.Add((20, 20), 0, 0, 0)
        sizer_3.Add(grid_sizer_6, 1, wx.EXPAND, 0)
        grid_sizer_7.Add((20, 20), 0, 0, 0)
        grid_sizer_7.Add(self.text_ctrl_7, 0, wx.ALIGN_RIGHT, 0)
        grid_sizer_7.Add((20, 20), 0, 0, 0)
        grid_sizer_7.Add((20, 20), 0, 0, 0)
        grid_sizer_7.Add(self.text_ctrl_8, 0, wx.ALIGN_RIGHT, 0)
        grid_sizer_7.Add((20, 20), 0, 0, 0)
        grid_sizer_7.Add((20, 20), 0, 0, 0)
        grid_sizer_7.Add((20, 20), 0, 0, 0)
        grid_sizer_7.Add((20, 20), 0, 0, 0)
        sizer_3.Add(grid_sizer_7, 1, wx.EXPAND, 0)
        sizer_1.Add(sizer_3, 1, wx.EXPAND, 0)
        self.SetSizer(sizer_1)
        self.Layout()
        # end wxGlade


    def write_to_box(self,msg):
                #print msg+"\n"
                #wx.Yield()
                self.rtc.Freeze()
                self.rtc.BeginSuppressUndo()

                self.rtc.BeginTextColour((0, 0, 255))
                self.rtc.WriteText(msg)
                self.rtc.EndTextColour()

                self.rtc.Newline()

                self.rtc.EndSuppressUndo()
                self.rtc.Thaw()
                #wx.Yield()

    def write_to_box_vuln(self,msg):
                #print msg+"\n"
                #wx.Yield()
                self.rtc.Freeze()
                self.rtc.BeginSuppressUndo()

                self.rtc.BeginTextColour((255, 0, 0))
                self.rtc.WriteText(msg)
                self.rtc.EndTextColour()

                self.rtc.Newline()

                self.rtc.EndSuppressUndo()
		self.rtc.MoveEnd()
                self.rtc.Thaw()
                #wx.Yield()


    def write_dic_to_box(self,dic):
                self.rtc.Freeze()
                self.rtc.BeginSuppressUndo()

                self.rtc.BeginTextColour((0, 255, 0))
                for x in dic.keys():
                        self.rtc.WriteText("'"+x+"' => '"+dic[x]+"' ")
			self.rtc.Newline()

                self.rtc.EndTextColour()

                self.rtc.Newline()

                self.rtc.EndSuppressUndo()
		self.rtc.MoveEnd()
                self.rtc.Thaw()
	

    def update_status(self,msg):
                self.frame_1_statusbar.SetStatusText(msg)




    def OnGroup1Select( self, event ):
        radio_selected = event.GetEventObject()

        if self.radio_btn_1 is radio_selected:
          self.verbose = 0

        elif self.radio_btn_2 is radio_selected:
          self.verbose = 1

        elif self.radio_btn_3 is radio_selected:
          self.verbose = 2
        else:
          self.verbose = 2

    def OnGroup2Select( self, event ):
        radio_selected = event.GetEventObject()

        if self.radio_btn_4 is radio_selected:
          self.type = "GET_ALL"

        elif self.radio_btn_5 is radio_selected:
          self.type = "GET_XSS"

        elif self.radio_btn_6 is radio_selected:
          self.type = "POST_XSS"
        else:
          print "none"


    def do_Scan(self, event): # wxGlade: MyFrame.<event_handler>
        #print "Event handler `do_Scan' not implemented"


        self.URL = self.text_ctrl_10.GetValue()
	if not len(self.URL):
          wx.MessageBox("Please specify an URL","Missing URL")  
	  return



        self.user = self.text_ctrl_3.GetValue()
        self.password = self.text_ctrl_4.GetValue()

        self.cookie = self.fbb.GetValue()

        self.proxy = self.text_ctrl_9.GetValue()

        self.timeout = int(self.spin_ctrl_1.GetValue())



        self.ex_url1 = self.text_ctrl_5.GetValue()
        self.ex_url2 = self.text_ctrl_6.GetValue()
        self.ex_url3 = self.text_ctrl_7.GetValue()
        self.ex_url4 = self.text_ctrl_8.GetValue()



        self.frame_1_statusbar.SetStatusText("Scanning")
        
        self.count += 1
        thread = worker(self.count, self, self.URL,self.type,self.user,self.password,self.cookie,self.proxy,self.timeout,self.verbose,self.ex_url1,self.ex_url2,self.ex_url3,self.ex_url4)
        self.threads.append(thread)
        thread.start()

    def show_rep(self):

	win = reportframe.ReportFrame(self, -1, "Scan Report",
                            size=(700, 500),
                            style = wx.DEFAULT_FRAME_STYLE)

	win.addFindings(self.findings)
       	win.Show(True)

	


    def do_Stop(self, event): # wxGlade: MyFrame.<event_handler>
        self.StopThreads()

    def MenuExit(self, event):
        self.Destroy()

    def MenuAbout(self, event):

        info = wx.AboutDialogInfo()
        info.Name = "Powerfuzzer"
        info.Version = version
        info.Copyright = "GPL"
        info.Description = wordwrap("Powerfuzzer is a web application vulnerability scanner ",
            350, wx.ClientDC(self))
	info.WebSite = ("http://powerfuzzer.sourceforge.net", "Powerfuzzer homepage")
	info.Developers = [ "Marcin Kozlowski marcinguy (at) yahoo.com"]

        info.License = wordwrap(licenseText, 500, wx.ClientDC(self))

        # Then we call wx.AboutBox giving it that info object
        wx.AboutBox(info)


    def StopThreads(self):
        while self.threads:
          thread = self.threads[0]
          thread.stop()
          self.threads.remove(thread)




    def OnCloseWindow(self, evt):
        self.Destroy()

    
    def AddRTCHandlers(self):
        # make sure we haven't already added them.
        if rt.RichTextBuffer.FindHandlerByType(rt.RICHTEXT_TYPE_HTML) is not None:
            return
        
        # This would normally go in your app's OnInit method.  I'm
        # not sure why these file handlers are not loaded by
        # default by the C++ richtext code, I guess it's so you
        # can change the name or extension if you wanted...
        rt.RichTextBuffer.AddHandler(rt.RichTextHTMLHandler())
        rt.RichTextBuffer.AddHandler(rt.RichTextXMLHandler())

        # ...like this
        rt.RichTextBuffer.AddHandler(rt.RichTextXMLHandler(name="Other XML",
                                                           ext="ox",
                                                           type=99))

        # This is needed for the view as HTML option since we tell it
        # to store the images in the memory file system.
        wx.FileSystem.AddHandler(wx.MemoryFSHandler())


# end of class MyFrame



class MyApp(wx.App):
    def OnInit(self):
        wx.InitAllImageHandlers()
        frame_1 = MyFrame(None, -1, "")
        self.SetTopWindow(frame_1)
        frame_1.Show()
        return 1

# end of class MyApp

if __name__ == "__main__":
    #th = ScanThread("test")
    app = MyApp(0)
    app.MainLoop()