Automater.py - IP/URL Analysis tool for Intrusion Analysts


SUBMITTED BY: Guest

DATE: March 8, 2013, 7:42 p.m.

FORMAT: Python

SIZE: 18.2 kB

HITS: 2685

  1. #!/usr/bin/python
  2. import httplib2, re, sys, argparse, urllib, urllib2
  3. print '''
  4. ___ _ _
  5. / _ \ | | | |
  6. / /_\ \_ _| |_ ___ _ __ ___ __ _| |_ ___ _ __
  7. | _ | | | | __/ _ \| '_ ` _ \ / _` | __/ _ \ '__|
  8. | | | | |_| | || (_) | | | | | | (_| | || __/ |
  9. \_| |_/\__,_|\__\___/|_| |_| |_|\__,_|\__\___|_|
  10. Welcome to Automater! I have created this tool to help analyst investigate IP Addresses and URLs with the common web based tools. All activity is passive so it will not alert attackers.
  11. Web Tools used are: IPvoid.com, Robtex.com, Fortiguard.com, unshorten.me, Urlvoid.com, Labs.alienvault.com
  12. www.TekDefense.com
  13. @author: 1aN0rmus@TekDefense.com, Ian Ahl
  14. Version 1.2
  15. '''
  16. '''
  17. Changelog:
  18. 1.2.1
  19. [+] Modified regex in Robtex function to pick up "A" records that were being missed.
  20. [+] Alienvault reputation data added by guillermogrande. Thank you!
  21. 1.2
  22. [+] Changed output style to @ViolentPython style
  23. [+] Fixed IPVoid and URLVoid result for new regexes
  24. [+] Fixed form submit for IP's and URLs that were not previously scanned
  25. '''
  26. #urlInput = "tekdefense.com"
  27. #ipInput = (raw_input('Please enter an IP address to be queried: '))
  28. def main():
  29. parser = argparse.ArgumentParser(description='IP and URL Passive Analysis tool')
  30. parser.add_argument('-t', '--target', help='List one IP Addresses to query. Does not support more than one address.')
  31. parser.add_argument('-f', '--file', help='This option is used to import a file that contains IP Addresses or URLs')
  32. parser.add_argument('-o', '--output', help='This option will output the results to a file.')
  33. parser.add_argument('-e', '--expand', help='This option will expand a shortened url using unshort.me')
  34. parser.add_argument('-s', '--source', help='This option will only run the target against a specifc source engine to pull associated domains. Options are robtex, ipvoid, fortinet, urlvoid, alienvault')
  35. args = parser.parse_args()
  36. if args.source == "robtex":
  37. ipInput = str(args.target)
  38. print args.source + " source engine selected"
  39. robtex(ipInput)
  40. if args.source == "ipvoid":
  41. ipInput = str(args.target)
  42. print args.source + " source engine selected"
  43. ipvoid(ipInput)
  44. if args.source == "fortinet":
  45. ipInput = str(args.target)
  46. print args.source + " source engine selected"
  47. fortiURL(ipInput)
  48. if args.source == "urlvoid":
  49. urlInput = str(args.target)
  50. print args.source + " source engine selected"
  51. urlvoid(urlInput)
  52. if args.source == "alienvault":
  53. ipInput = str(args.target)
  54. print args.source + " source engine selected"
  55. alienvault(ipInput)
  56. if args.target:
  57. if args.output != None:
  58. print '[+] Printing results to file:', args.output
  59. output = ""
  60. output = str(args.output)
  61. o = open(output, "w")
  62. sys.stdout = o
  63. if args.source != None:
  64. print "[*] operation complete"
  65. else:
  66. input = args.target
  67. rpd7 = re.compile('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', re.IGNORECASE)
  68. rpdFind7 = re.findall(rpd7,input)
  69. rpdSorted7=sorted(rpdFind7)
  70. rpdSorted7=str(rpdSorted7)
  71. rpdSorted7=rpdSorted7[2:-2]
  72. rpd8 = re.compile('([-a-z0-9A-Z]+\.[-a-z0-9A-Z]*).+', re.IGNORECASE)
  73. rpdFind8 = re.findall(rpd8,input)
  74. rpdSorted8=sorted(rpdFind8)
  75. rpdSorted8=str(rpdSorted8)
  76. rpdSorted8=rpdSorted8[2:-2]
  77. if rpdSorted7 == input:
  78. print '--------------------------------'
  79. print '[*] ' + input + ' is an IP. '
  80. print '[*] Running IP toolset'
  81. ipInput = input
  82. robtex(ipInput)
  83. ipvoid(ipInput)
  84. fortiURL(ipInput)
  85. alienvault(ipInput)
  86. else:
  87. print '--------------------------------'
  88. print '[*] ' + input + ' is a URL. '
  89. print '[*] Running URL toolset'
  90. urlInput = input
  91. unshortunURL(urlInput)
  92. urlvoid(urlInput)
  93. fortiURL(urlInput)
  94. elif args.file:
  95. if args.output != None:
  96. print '[*] Printing results to file:', args.output
  97. output = ""
  98. output = str(args.output)
  99. o = open(output, "w")
  100. sys.stdout = o
  101. li = open(args.file).readlines()
  102. for i in li:
  103. li = str(i)
  104. ipInput = li.strip()
  105. input = ipInput
  106. if args.source != None:
  107. print "[*] operation complete"
  108. else:
  109. rpd7 = re.compile('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', re.IGNORECASE)
  110. rpdFind7 = re.findall(rpd7,input)
  111. rpdSorted7=sorted(rpdFind7)
  112. rpdSorted7=str(rpdSorted7)
  113. rpdSorted7=rpdSorted7[2:-2]
  114. rpd8 = re.compile('([-a-z0-9A-Z]+\.[-a-z0-9A-Z]*).+', re.IGNORECASE)
  115. rpdFind8 = re.findall(rpd8,input)
  116. rpdSorted8=sorted(rpdFind8)
  117. rpdSorted8=str(rpdSorted8)
  118. rpdSorted8=rpdSorted8[2:-2]
  119. if rpdSorted7 == input:
  120. print '--------------------------------'
  121. print '[*] ' + input + ' is an IP. Running IP toolset'
  122. ipInput = input
  123. robtex(ipInput)
  124. ipvoid(ipInput)
  125. fortiURL(ipInput)
  126. alienvault(ipInput)
  127. else:
  128. print '--------------------------------'
  129. print '[*] ' + input + ' is a URL. Running URL toolset'
  130. urlInput = input
  131. urlvoid(urlInput)
  132. unshortunURL(urlInput)
  133. fortiURL(urlInput)
  134. if args.expand != None:
  135. for i in li:
  136. li = str(i)
  137. ipInput = li.strip()
  138. url = ipInput
  139. unshortunURL(url)
  140. elif args.expand:
  141. if args.output != None:
  142. print '[+] Printing results to file:', args.output
  143. output = ""
  144. output = str(args.output)
  145. o = open(output, "w")
  146. sys.stdout = o
  147. url = args.expand
  148. unshortunURL(url)
  149. def robtex(ipInput):
  150. h1 = httplib2.Http(".cache")
  151. resp, content1 = h1.request(("http://robtex.com/" + ipInput), "GET")
  152. content1String = (str(content1))
  153. #print content1String
  154. rpd = re.compile('href\=\"\/\/.+\.robtex\.com\/(.+).html\"\s+\>.+\<\/a\>\s\<\/span\>\<\/td\>\n\<td\sclass\="\w+\"\scolspan\="\d*\"\>a', re.IGNORECASE)
  155. rpdFind = re.findall(rpd,content1String)
  156. rpdSorted=sorted(rpdFind)
  157. i=''
  158. for i in rpdSorted:
  159. if len(i)>4:
  160. if not i == ipInput:
  161. print '[+] A records from Robtex: ' + (i)
  162. if i=='':
  163. print '[-] This IP does not resolve to a domain'
  164. def ipvoid(ipInput):
  165. h2 = httplib2.Http(".cache")
  166. resp, content2 = h2.request(("http://ipvoid.com/scan/" + ipInput), "GET")
  167. content2String = (str(content2))
  168. rpderr = re.compile('An\sError\soccurred', re.IGNORECASE)
  169. rpdFinderr = re.findall(rpderr,content2String)
  170. # print content2String
  171. if "ERROR" in str(rpdFinderr):
  172. ipvoidErr = True
  173. else:
  174. ipvoidErr = False
  175. if ipvoidErr == False:
  176. rpd2 = re.compile('Detected\<\/font\>\<\/td..td..a.rel..nofollow..href.\"(.{6,70})\"\stitle\=\"View', re.IGNORECASE)
  177. rpdFind2 = re.findall(rpd2,content2String)
  178. rpdSorted2=sorted(rpdFind2)
  179. rpd3 = re.compile('ISP\<\/td\>\<td\>(.+)\<\/td\>', re.IGNORECASE)
  180. rpdFind3 = re.findall(rpd3,content2String)
  181. rpdSorted3=sorted(rpdFind3)
  182. rpd4 = re.compile('Country\sCode.+flag\"\s\/\>\s(.+)\<\/td\>', re.IGNORECASE)
  183. rpdFind4 = re.findall(rpd4,content2String)
  184. rpdSorted4=sorted(rpdFind4)
  185. j=''
  186. for j in rpdSorted2:
  187. print ('[+] Host is listed in blacklist at '+ j)
  188. if j=='':
  189. print('[-] IP is not listed in a blacklist')
  190. k=''
  191. for k in rpdSorted3:
  192. print ('[+] The ISP for this IP is: '+ k)
  193. if k=='':
  194. print('[-] No ISP listed')
  195. l=''
  196. for l in rpdSorted4:
  197. print ('[+] Geographic Location: '+ l)
  198. if l=='':
  199. print ('[-] No GEO location listed')
  200. else:
  201. print '[*] Scanning host now on IPVoid.com. May take a few seconds.'
  202. url = ('http://www.ipvoid.com/')
  203. raw_params = {'ip':ipInput,'go':'Scan Now'}
  204. params = urllib.urlencode(raw_params)
  205. request = urllib2.Request(url,params,headers={'Content-type':'application/x-www-form-urlencoded'})
  206. page = urllib2.urlopen(request)
  207. page = page.read()
  208. content2String = str(page)
  209. rpd2 = re.compile('Detected\<\/font\>\<\/td..td..a.rel..nofollow..href.\"(.{6,70})\"\stitle\=\"View', re.IGNORECASE)
  210. rpdFind2 = re.findall(rpd2,content2String)
  211. rpdSorted2=sorted(rpdFind2)
  212. rpd3 = re.compile('ISP\<\/td\>\<td\>(.+)\<\/td\>', re.IGNORECASE)
  213. rpdFind3 = re.findall(rpd3,content2String)
  214. rpdSorted3=sorted(rpdFind3)
  215. rpd4 = re.compile('Country\sCode.+flag\"\s\/\>\s(.+)\<\/td\>', re.IGNORECASE)
  216. rpdFind4 = re.findall(rpd4,content2String)
  217. rpdSorted4=sorted(rpdFind4)
  218. j=''
  219. for j in rpdSorted2:
  220. print ('[+] Host is listed in blacklist at '+ j)
  221. if j=='':
  222. print('[-] IP is not listed in a blacklist')
  223. k=''
  224. for k in rpdSorted3:
  225. print ('[+] The ISP for this IP is: '+ k)
  226. if k=='':
  227. print('[-] No ISP listed')
  228. l=''
  229. for l in rpdSorted4:
  230. print ('[+] Geographic Location: '+ l)
  231. if l=='':
  232. print ('[-] No GEO location listed')
  233. def fortiURL(ipInput):
  234. h3 = httplib2.Http(".cache")
  235. resp, content3 = h3.request(("http://www.fortiguard.com/ip_rep.php?data=" + ipInput + "&lookup=Lookup"), "GET")
  236. content3String = (str(content3))
  237. rpd5 = re.compile('Category:\s\<span\sstyle\=\"font\-size\:200\%\"\>(.+)\<\/span', re.IGNORECASE)
  238. rpdFind5 = re.findall(rpd5,content3String)
  239. rpdSorted5=sorted(rpdFind5)
  240. # print content3String
  241. m=''
  242. for m in rpdSorted5:
  243. print ('[+] FortiGuard URL Categorization: '+ m)
  244. if m=='':
  245. print ('[-] FortiGuard URL Categorization: Uncategorized')
  246. def unshortunURL(url):
  247. h4 = httplib2.Http(".cache")
  248. resp, content4 = h4.request(("http://unshort.me/index.php?r=" + url), "GET")
  249. content4String = (str(content4))
  250. rpd6 = re.compile('result\"\>\s\<a\shref\=\".+\>(.+)\<\/a\>\s', re.IGNORECASE)
  251. rpdFind6 = re.findall(rpd6,content4String)
  252. rpdSorted6=sorted(rpdFind6)
  253. # print content3String
  254. m=''
  255. for m in rpdSorted6:
  256. if url not in m:
  257. print ('[+] ' + url + ' redirects to: ' + m)
  258. else:
  259. print ('[-] ' + url + ' is not a recognized shortened URL.')
  260. def urlvoid(url):
  261. h2 = httplib2.Http(".cache")
  262. resp, content2 = h2.request(("http://urlvoid.com/scan/" + url), "GET")
  263. content2String = (str(content2))
  264. rpderr = re.compile('An\sError\soccurred', re.IGNORECASE)
  265. rpdFinderr = re.findall(rpderr,content2String)
  266. # print content2String
  267. if "ERROR" in str(rpdFinderr):
  268. ipvoidErr = True
  269. else:
  270. ipvoidErr = False
  271. if ipvoidErr == False:
  272. rpd1 = re.compile('(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}).+Scan\swith\s', re.IGNORECASE)
  273. rpdFind1 = re.findall(rpd1,content2String)
  274. rpdSorted1=sorted(rpdFind1)
  275. rpd2 = re.compile('DETECTED.{25,40}href\=\"(.{10,50})\"\stitle', re.IGNORECASE)
  276. rpdFind2 = re.findall(rpd2,content2String)
  277. rpdSorted2=sorted(rpdFind2)
  278. rpd3 = re.compile('latitude\s\/\slongitude.+\<td\>(.+)\<\/td\>', re.IGNORECASE)
  279. rpdFind3 = re.findall(rpd3,content2String)
  280. rpdSorted3=sorted(rpdFind3)
  281. rpd4 = re.compile('alt\=\"flag\".+\>(.+)\<\/td\>', re.IGNORECASE)
  282. rpdFind4 = re.findall(rpd4,content2String)
  283. rpdSorted4=sorted(rpdFind4)
  284. rpd5 = re.compile('Domain\s1st\sRegistered.+\<td\>(.+)\<\/td\>', re.IGNORECASE)
  285. rpdFind5 = re.findall(rpd5,content2String)
  286. rpdSorted5=sorted(rpdFind5)
  287. i=''
  288. for i in rpdSorted1:
  289. print ('[+] Host IP Address is '+ i)
  290. if i=='':
  291. print('[-] IP is not listed')
  292. j=''
  293. for j in rpdSorted2:
  294. print ('[+] Host is listed in blacklist at '+ j)
  295. if j=='':
  296. print('[-] IP is not listed in a blacklist')
  297. k=''
  298. for k in rpdSorted3:
  299. print ('[+] Latitude / Longitude: '+ k)
  300. if k=='':
  301. print('[-] No Latitude / Longitude listed')
  302. l=''
  303. for l in rpdSorted4:
  304. print ('[+] Country: '+ l)
  305. if l=='':
  306. print ('[-] No Country listed')
  307. m=''
  308. for m in rpdSorted5:
  309. print ('[+] Domain creation date: '+ m)
  310. if m=='':
  311. print ('[-] Domain creation date not listed.')
  312. else:
  313. print '[*] Scanning host now on URLVoid.com. May take a few seconds.'
  314. urlvoid = ('http://www.urlvoid.com/')
  315. raw_params = {'url':url,'Check':'Submit'}
  316. params = urllib.urlencode(raw_params)
  317. request = urllib2.Request(urlvoid,params,headers={'Content-type':'application/x-www-form-urlencoded'})
  318. page = urllib2.urlopen(request)
  319. page = page.read()
  320. content2String = str(page)
  321. #print content2String
  322. rpd1 = re.compile('(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}).+Scan\swith\s', re.IGNORECASE)
  323. rpdFind1 = re.findall(rpd1,content2String)
  324. rpdSorted1=sorted(rpdFind1)
  325. rpd2 = re.compile('DETECTED.{25,40}href\=\"(.{10,50})\"\stitle', re.IGNORECASE)
  326. rpdFind2 = re.findall(rpd2,content2String)
  327. rpdSorted2=sorted(rpdFind2)
  328. rpd3 = re.compile('latitude\s\/\slongitude.+\<td\>(.+)\<\/td\>', re.IGNORECASE)
  329. rpdFind3 = re.findall(rpd3,content2String)
  330. rpdSorted3=sorted(rpdFind3)
  331. rpd4 = re.compile('alt\=\"flag\".+\>(.+)\<\/td\>', re.IGNORECASE)
  332. rpdFind4 = re.findall(rpd4,content2String)
  333. rpdSorted4=sorted(rpdFind4)
  334. rpd5 = re.compile('Domain\s1st\sRegistered.+\<td\>(.+)\<\/td\>', re.IGNORECASE)
  335. rpdFind5 = re.findall(rpd5,content2String)
  336. rpdSorted5=sorted(rpdFind5)
  337. i=''
  338. for i in rpdSorted1:
  339. print ('[+] Host IP Address is '+ i)
  340. if i=='':
  341. print('[-] IP is not listed')
  342. j=''
  343. for j in rpdSorted2:
  344. print ('[+] Host is listed in blacklist at '+ j)
  345. if j=='':
  346. print('[-] IP is not listed in a blacklist')
  347. k=''
  348. for k in rpdSorted3:
  349. print ('[+] Latitude / Longitude: '+ k)
  350. if k=='':
  351. print('[-] No Latitude / Longitude listed')
  352. l=''
  353. for l in rpdSorted4:
  354. print ('[+] Country: '+ l)
  355. if l=='':
  356. print ('[-] No Country listed')
  357. m=''
  358. for m in rpdSorted5:
  359. print ('[+] Domain creation date: '+ m)
  360. if m=='':
  361. print ('[-] Domain creation date not listed.')
  362. def alienvault(ipInput):
  363. h1 = httplib2.Http(".cache")
  364. url = "http://labs.alienvault.com/labs/index.php/projects/open-source-ip-reputation-portal/information-about-ip/?ip=" + ipInput
  365. resp, conten1 = h1.request((url), "GET")
  366. content1String = (str(conten1))
  367. rpd = re.compile('.*IP not found.*')
  368. rpdFind = re.findall(rpd,content1String)
  369. if not rpdFind:
  370. print ('[+] IP is listed in AlienVault IP reputation database at ' + url)
  371. else:
  372. print ('[-] IP is not listed in AlienVault IP reputation database')
  373. if __name__ == "__main__":
  374. main()

comments powered by Disqus