webgui.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. #!/usr/bin/python
  2. # -*- coding: iso-8859-15 -*-
  3. """
  4. This file is part of the cintruder project, http://cintruder.03c8.net
  5. Copyright (c) 2012/2019 psy <epsylon@riseup.net>
  6. cintruder is free software; you can redistribute it and/or modify it under
  7. the terms of the GNU General Public License as published by the Free
  8. Software Foundation version 3 of the License.
  9. cintruder is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  12. details.
  13. You should have received a copy of the GNU General Public License along
  14. with cintruder; if not, write to the Free Software Foundation, Inc., 51
  15. Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. """
  17. import socket, threading, re, base64, os, time
  18. import webbrowser, subprocess, urllib, json, sys
  19. from options import CIntruderOptions
  20. from pprint import pprint
  21. from shutil import copyfile
  22. host = "0.0.0.0"
  23. port = 9999
  24. class ClientThread(threading.Thread):
  25. def __init__(self, ip, port, socket):
  26. threading.Thread.__init__(self)
  27. self.ip = ip
  28. self.port = port
  29. self.socket = socket
  30. self.pages = Pages()
  31. def run(self):
  32. req = self.socket.recv(2048)
  33. res = self.pages.get(req)
  34. out = "HTTP/1.0 %s\r\n" % res["code"]
  35. out += "Pragma: no-cache\n"
  36. out += "Expires: Fri, 30 Oct 1998 00:00:01 GMT\n"
  37. out += "Cache-Control: no-cache, must-revalidate\n"
  38. out += "Content-Type: %s\r\n\r\n" % res["ctype"]
  39. out += "%s" % res["html"]
  40. self.socket.send(out)
  41. self.socket.close()
  42. if "run" in res and len(res["run"]):
  43. subprocess.Popen(res["run"], shell=True)
  44. class Pages():
  45. def __init__(self):
  46. self.options = CIntruderOptions()
  47. self.pages = {}
  48. if not os.path.exists("outputs/words/"):
  49. os.mkdir("outputs/words/")
  50. self.pages["/header"] = """
  51. <!DOCTYPE html><html>
  52. <head>
  53. <meta name="author" content="psy">
  54. <meta name="robots" content="noindex, nofollow">
  55. <meta http-equiv="content-type" content="text/xml; charset=utf-8" />
  56. <title>CINTRUDER: OCR Bruteforcing Toolkit</title>
  57. <script type="text/javascript" src="/lib.js"></script>
  58. <script src="js/web.js" type="text/javascript"></script>
  59. <style>
  60. a:link {
  61. color: cyan;
  62. }
  63. a:visited {
  64. color: black;
  65. }
  66. </style>
  67. <style>
  68. input.button {
  69. width: 20em; height: 2em;
  70. }
  71. </style>
  72. """
  73. self.pages["/footer"] = """</body>
  74. </html>
  75. """
  76. self.pages["/"] = self.pages["/header"] + """
  77. <script>loadXMLDoc()</script></head><body bgcolor="blue" text="white" style="monospace;font-size:14px;" >
  78. <center>
  79. <table border="1" cellpadding="10" cellspacing="5" width="90%">
  80. <tr>
  81. <td bgcolor="white"><center><a href="http://cintruder.03c8.net" target="_blank"><img src="images/cintruder.png"></a></center></td>
  82. <td>
  83. <center><h3><a href="https://github.com/epsylon/cintruder" target="_blank">CINTRUDER</a> is an automatic pentesting tool to bypass <a href="https://en.wikipedia.org/wiki/CAPTCHA" target="_blank">captchas</a><br/><br/>
  84. Contact: psy (<a href="mailto:epsylon@riseup.net">epsylon@riseup.net</a>) - [<a href="https://03c8.net" target="_blank">03c8.net</a>]<br><br>
  85. License: <a href="http://www.gnu.org/licenses/quick-guide-gplv3.pdf" target="_blank">GPLv3</a> | Donate: <a href="https://blockchain.info/address/19aXfJtoYJUoXEZtjNwsah2JKN9CK5Pcjw" target="_blank">BTC</a></h3></center>
  86. </td>
  87. </tr></table><br/>
  88. <table cellpadding="10" cellspacing="5" width="90%">
  89. <tr>
  90. <td width="315px">
  91. <center>
  92. <table border="1" cellpadding="10" cellspacing="5">
  93. <tr>
  94. <td>
  95. Track: <input type="radio" onclick="javascript:OptionsCheck();" name="options" id="track"/ CHECKED>
  96. Train: <input type="radio" onclick="javascript:OptionsCheck();" name="options" id="train"/>
  97. Crack: <input type="radio" onclick="javascript:OptionsCheck();" name="options" id="crack"/>
  98. </td>
  99. </tr></table>
  100. </center>
  101. </td>
  102. <td><center>
  103. <div id="ifTrack" style="display:none">
  104. <table border="1" cellpadding="10" cellspacing="5">
  105. <tr>
  106. <td><center><input type="text" name="track_url" id="track_url" size="43" placeholder="Download captchas from url (to: 'inputs/')"></center></td>
  107. <td><center>Num: <input type="text" name="track_num" id="track_num" size="2" value="5"></center></td>
  108. <td><center>TOR: <input type="checkbox" id="tor" name="tor"></center></td>
  109. <td align="right">Debug: <input type="checkbox" name="verbose" id="verbose"></td>
  110. <td><center><input type="submit" value="Download!" onclick="TrackCaptchas()"></center></td>
  111. </tr></table>
  112. </div>
  113. <div id="ifTrain" style="display:none">
  114. <table border="1" cellpadding="5" cellspacing="5">
  115. <tr>
  116. <td><center>
  117. LOCAL: <input type="radio" onclick="javascript:TrainSourcesCheck();" name="training_sources" id="training_local"/ CHECKED>
  118. URL: <input type="radio" onclick="javascript:TrainSourcesCheck();" name="training_sources" id="training_url"/>
  119. <br><br><a href='javascript:runCommandX("cmd_tracklist");javascript:showResults()'>List Last Tracked</a><br><br>
  120. </center></td>
  121. <td>
  122. <div id="ifLocal" style="display:none">
  123. <center>
  124. <table cellpadding="5" cellspacing="5">
  125. <tr>
  126. <td><center><form action='' method='POST' enctype='multipart/form-data'>
  127. <input type='text' size="43" name='SourceFile' id='SourceFile' placeholder="Ex: inputs/test1.gif"></form></center></td>
  128. </tr></table>
  129. </center>
  130. </div>
  131. <div id="ifUrl" style="display:none">
  132. <table cellpadding="2" cellspacing="2">
  133. <tr>
  134. <td><center><input type="text" name="train_url" id="train_url" size="43" placeholder="Apply common OCR techniques to a remote captcha"></center></td>
  135. <td><center>TOR: <input type="checkbox" name="tor2" id="tor2"></center></td>
  136. </tr></table>
  137. </div>
  138. </td>
  139. </tr>
  140. <tr>
  141. <td align="right">Use Module: <input type="checkbox" onclick="javascript:SetTrainModule();" name="set_module" id="set_module"></td>
  142. <td>
  143. <table>
  144. <tr>
  145. <td align="center">
  146. <div id="ifMod_set" style="display:none">
  147. <table cellpadding="5" cellspacing="5">
  148. <tr>
  149. <td>Name: <input type="text" name="use_mod" id="use_mod" size="12" placeholder="Ex: 'easy'"></td>
  150. <td><a href='javascript:runCommandX("cmd_list");javascript:showResults()'>List Modules</a></td>
  151. </tr></table>
  152. </div>
  153. </td>
  154. </tr></table>
  155. </td>
  156. </tr>
  157. <tr>
  158. <td align="right">Advanced OCR: <input type="checkbox" onclick="javascript:SetColourID();" name="set_colour_id" id="set_colour_id"></td>
  159. <td align="center">
  160. <div id="ifMod_colour" style="display:none">
  161. <table cellpadding="5" cellspacing="5">
  162. <tr>
  163. <td>Set Colour ID: <input type="text" name="set_id" id="set_id" size="2" placeholder="Ex: 1"></td>
  164. </tr></table>
  165. </div>
  166. </td>
  167. </tr>
  168. <tr>
  169. <td align="right">Debug: <input type="checkbox" name="verbose2" id="verbose2"></td>
  170. <td><center><input type="submit" class="button" value="Train!" onclick="TrainCaptchas()"></center></td>
  171. </tr>
  172. </table>
  173. </div>
  174. <div id="ifCrack" style="display:none">
  175. <table border="1" cellpadding="5" cellspacing="5">
  176. <tr>
  177. <td><center>
  178. LOCAL: <input type="radio" onclick="javascript:CrackingCheck();" name="cracking_sources" id="cracking_local"/ CHECKED>
  179. URL: <input type="radio" onclick="javascript:CrackingCheck();" name="cracking_sources" id="cracking_url"/>
  180. <br><br><a href='javascript:runCommandX("cmd_tracklist");javascript:showResults()'>List Last Tracked</a><br><br>
  181. </center></td>
  182. <td>
  183. <div id="ifCrackLocal" style="display:none">
  184. <center>
  185. <table cellpadding="5" cellspacing="5">
  186. <tr>
  187. <td><center><form action='' method='POST' enctype='multipart/form-data'>
  188. <input type='text' size="43" name='SourceFile2' id='SourceFile2' placeholder="Ex: inputs/test1.gif"></form></center></td>
  189. </tr>
  190. </table>
  191. </center>
  192. </div>
  193. <div id="ifCrackUrl" style="display:none">
  194. <table cellpadding="5" cellspacing="5">
  195. <tr>
  196. <td><center><input type="text" name="crack_url" id="crack_url" size="43" placeholder="Brute force using local dictionary (from: 'dictionary/')"></center></td>
  197. <td><center>TOR: <input type="checkbox" name="tor3" id="tor3"></center></td>
  198. </tr>
  199. </table>
  200. </div>
  201. </td>
  202. </tr>
  203. <tr>
  204. <td align="right">Use Module: <input type="checkbox" onclick="javascript:SetCrackModule();" name="set_module_crack" id="set_module_crack"></td>
  205. <td>
  206. <table>
  207. <tr>
  208. <td align="center">
  209. <div id="ifMod_set_crack" style="display:none">
  210. <table cellpadding="5" cellspacing="5">
  211. <tr>
  212. <td>Name: <input type="text" name="use_mod_crack" id="use_mod_crack" size="12" placeholder="Ex: 'easy'"></td>
  213. <td><a href='javascript:runCommandX("cmd_list");javascript:showResults()'>List Modules</a></td>
  214. </tr></table>
  215. </div>
  216. </td>
  217. </tr></table>
  218. </td>
  219. </tr>
  220. <tr>
  221. <td align="right">Advanced OCR: <input type="checkbox" onclick="javascript:SetColourID();" name="set_colour_id3" id="set_colour_id3"></td>
  222. <td align="center">
  223. <div id="ifMod_colour2" style="display:none">
  224. <table cellpadding="5" cellspacing="5">
  225. <tr>
  226. <td>Set Colour ID: <input type="text" name="set_id3" id="set_id3" size="2" placeholder="Ex: 1"></td>
  227. </tr></table>
  228. </div>
  229. </td>
  230. </tr>
  231. <tr>
  232. <td align="right">Export to XML: <input type="checkbox" onclick="javascript:SetXML();" name="set_xml" id="set_xml"></td>
  233. <td align="center">
  234. <div id="ifMod_xml" style="display:none">
  235. <table cellpadding="5" cellspacing="5">
  236. <tr>
  237. <td>Filename: <input type="text" name="set_xml_file" id="set_xml_file" size="16" placeholder="Ex: php-captcha.xml"></td>
  238. </tr></table>
  239. </div>
  240. </td>
  241. </tr>
  242. <tr>
  243. <td align="right">Debug: <input type="checkbox" name="verbose3" id="verbose3"></td>
  244. <td><center><input type="submit" class="button" value="Crack it!" onclick="CrackCaptchas()"></center></td>
  245. </tr>
  246. </table>
  247. </div>
  248. </center></td>
  249. </tr>
  250. </table>
  251. <table cellpadding="5" cellspacing="5">
  252. <tr>
  253. <td>
  254. <div id="Results" style="display:none"><table width="100%" border="1" cellpadding="5" cellspacing="5"><th>Shell Info:<tr><td><div id="cmdOut"></div></td></tr></table></div>
  255. </td>
  256. </tr>
  257. <tr>
  258. <td align="center">
  259. <div id="Captcha-IN" style="display:none"><table border="1" width="100%" cellpadding="5" cellspacing="5"><th>Captcha Preview:<tr><td><center><img id="target_captcha_img_path" name="target_captcha_img_path" src=''></center></td></tr></table></div>
  260. </td>
  261. </tr>
  262. <tr>
  263. <td>
  264. <div id="OCR-out" style="display:none">
  265. <table width="100%" height="100%" border="1"><th>OCR Output:<tr>
  266. <td><iframe frameborder="0" id="directory-words" name="directory-words" width="800px" height="300px" src="directory-words"></iframe></td>
  267. </tr></table>
  268. </div>
  269. </td>
  270. </tr>
  271. </table>
  272. </center>
  273. <br /><br/>
  274. """ + self.pages["/footer"]
  275. self.pages["/directory-words"] ="""<!DOCTYPE html><html><head><meta http-equiv="Content-type" content="text/html;charset=UTF-8"><script type="text/javascript" src="/lib.js"></script>
  276. <script language="javascript">
  277. function AddAll(){
  278. var inputs = document.getElementsByClassName('word'),
  279. ws = [].map.call(inputs, function( input ) {
  280. return input.id;
  281. }).join("-");
  282. var array = ws.split('-');
  283. var arrayLength = array.length;
  284. for (var i = 0; i < arrayLength; i++) {
  285. word = array[i];
  286. letter = document.getElementById(word).value;
  287. if(letter == ""){
  288. window.alert("You need to enter ALL dictionary symbols");
  289. return
  290. }
  291. if(word == ""){
  292. word = "off";
  293. }else{
  294. var w = word.substring(word.lastIndexOf('_')+1);
  295. w = "images/previews/ocr/" + w;
  296. params="symbol="+escape(w)+"&letter="+escape(letter);
  297. }
  298. runCommandX("cmd_move_ocr",params);
  299. var s = word.substring(word.lastIndexOf('_')+1);
  300. document.getElementById(s).style.display = "none";
  301. }
  302. document.getElementById("adding").style.display = "none";
  303. document.getElementById("AddAll").style.display = "none";
  304. }
  305. function Reload(word){
  306. var w = word.substring(word.lastIndexOf('/')+1);
  307. document.getElementById(w).style.display = "none";
  308. document.getElementById("discarding").style.display = "none";
  309. }
  310. function Reload_Added(word){
  311. var w = word.substring(word.lastIndexOf('/')+1);
  312. document.getElementById(w).style.display = "none";
  313. document.getElementById("adding").style.display = "none";
  314. }
  315. function MoveOCR(word) {
  316. var w = word.substring(word.lastIndexOf('/')+1);
  317. symbol = "letter_" + w
  318. letter = document.getElementById(symbol).value;
  319. if(letter == ""){
  320. window.alert("You need to enter a valid dictionary symbol (Ex: p)");
  321. return
  322. }
  323. if(word == ""){
  324. word = "off";
  325. }else{
  326. params="symbol="+escape(word)+"&letter="+escape(letter);
  327. }
  328. runCommandX("cmd_move_ocr",params);
  329. setTimeout(function() { Reload_Added(word) }, 2000); // delay 2
  330. }
  331. function RemoveOCR(word) {
  332. if(word == ""){
  333. word = "off";
  334. }else{
  335. params="symbol="+escape(word);
  336. }
  337. runCommandX("cmd_remove_ocr",params);
  338. setTimeout(function() { Reload(word) }, 2000); // delay 2
  339. }
  340. </script>
  341. <script language="javascript">function ViewWord(word) {window.open(word,"_blank","fulscreen=no, titlebar=yes, top=180, left=320, width=720, height=460, resizable=yes", false);}</script></head><body><table width='100%'><tr><td align='center'><font color='white'><div id="cmdOut"></div></font></td></tr><tr><td><br><center><a href='javascript:runCommandX("cmd_dict");'><font color="cyan"><u>View Dictionary Info</u></font></a></center></td></tr><tr><td>"""+str("".join(self.list_words()))+"""</td></tr></table><br><div align='center' style='display:block;' id='AddAll'> <button onclick='AddAll()'>ADD ALL!</button></div></body></html>"""
  342. self.pages["/lib.js"] = """function loadXMLDoc() {
  343. var xmlhttp;
  344. if (window.XMLHttpRequest) {
  345. // code for IE7+, Firefox, Chrome, Opera, Safari
  346. xmlhttp = new XMLHttpRequest();
  347. } else {
  348. // code for IE6, IE5
  349. xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  350. }
  351. xmlhttp.onreadystatechange = function() {
  352. if (xmlhttp.readyState == 4 ) {
  353. if(xmlhttp.status == 200){
  354. document.getElementById("cmdOut").innerHTML = xmlhttp.responseText;
  355. setTimeout("loadXMLDoc()", 3000);
  356. }
  357. }
  358. }
  359. xmlhttp.send();
  360. }
  361. function runCommandX(cmd,params) {
  362. var xmlhttp;
  363. if (window.XMLHttpRequest) {
  364. // code for IE7+, Firefox, Chrome, Opera, Safari
  365. xmlhttp = new XMLHttpRequest();
  366. } else {
  367. // code for IE6, IE5
  368. xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  369. }
  370. xmlhttp.onreadystatechange = function() {
  371. if (xmlhttp.readyState == 4 ) {
  372. if(xmlhttp.status == 200){
  373. if(cmd.indexOf("?")!=-1){
  374. s=cmd.split("?")
  375. cmd=s[0]
  376. params=s[1]
  377. }
  378. document.getElementById("cmdOut").innerHTML = xmlhttp.responseText;
  379. //document.getElementById("cmdOut").scrollIntoView();
  380. newcmd=cmd
  381. if(newcmd=="cmd_remove_ocr" || newcmd=="cmd_move_ocr" || newcmd=="cmd_dict"){ //do not refresh
  382. return;
  383. } else {
  384. if(newcmd=="cmd_list" || newcmd=="cmd_track" || newcmd == "cmd_tracklist" || newcmd=="cmd_crack" || newcmd=="cmd_train") newcmd=newcmd+"_update"
  385. //do not refresh if certain text on response is found
  386. if(newcmd.match(/update/) &&
  387. (
  388. xmlhttp.responseText.match(/Number of tracked captchas/) ||
  389. xmlhttp.responseText.match(/to the correct folder/) ||
  390. xmlhttp.responseText.match(/by the moment/) ||
  391. xmlhttp.responseText.match(/Is that captcha supported?/) ||
  392. xmlhttp.responseText.match(/module not found/) ||
  393. xmlhttp.responseText.match(/No idea/) ||
  394. xmlhttp.responseText.match(/Possible Solution/) ||
  395. xmlhttp.responseText.match(/Internal problems/) ||
  396. xmlhttp.responseText.match(/List end/)
  397. )
  398. ) return;
  399. setTimeout(function(){runCommandX(newcmd,params)}, 3000);
  400. return;}
  401. }
  402. }
  403. }
  404. if(typeof params != "undefined") cmd=cmd+"?"+params
  405. xmlhttp.open("GET", cmd, true);
  406. xmlhttp.send();
  407. }
  408. """
  409. def list_words(self):
  410. m = []
  411. t = os.listdir("outputs/words")
  412. for f in t:
  413. ocr_preview = "<br><table style='display:block;' id='"+f+"' name='"+f+"' border='1' width='100%' cellpadding='5' cellspacing='5'><tr><td align='left' width='100%'><font color='cyan'><u><a onclick=javascript:ViewWord('images/previews/ocr/"+f+"');return false;>"+f+"</a></u></td><td align='center'><a onclick=javascript:ViewWord('images/previews/ocr/"+f+"');return false;><img border='1' style='border-color:red;' src='images/previews/ocr/"+f+"'></a></font></td><td align='center'><input type='text' class='word' name='letter_"+f+"' id='letter_"+f+"' size='2'></td><td align='center'><input type='submit' class='button' value='ADD!' onclick=javascript:MoveOCR('images/previews/ocr/"+f+"');return false;></td><td align='center'><input type='submit' class='button' value='Discard...' onclick=javascript:RemoveOCR('images/previews/ocr/"+f+"');return false;></td></tr></table>"
  414. m.append(ocr_preview)
  415. return m
  416. def convert_size(self, size):
  417. import math
  418. if (size == 0):
  419. return '0B'
  420. size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
  421. i = int(math.floor(math.log(size,1024)))
  422. p = math.pow(1024,i)
  423. s = round(size/p,2)
  424. return '%s %s' % (s,size_name[i])
  425. def buildGetParams(self, request):
  426. params = {}
  427. path = re.findall("^GET ([^\s]+)", request)
  428. if path:
  429. path = path[0]
  430. start = path.find("?")
  431. if start != -1:
  432. for param in path[start+1:].split("&"):
  433. f = param.split("=")
  434. if len(f) == 2:
  435. var = f[0]
  436. value = f[1]
  437. value = value.replace("+", " ")
  438. value = urllib.unquote(value)
  439. params[var] = value
  440. return params
  441. def get(self, request):
  442. cmd_options = ""
  443. runcmd = ""
  444. res = re.findall("^GET ([^\s]+)", request)
  445. if res is None:
  446. return
  447. pGet = {}
  448. page = res[0]
  449. paramStart = page.find("?")
  450. if paramStart != -1:
  451. page = page[:paramStart]
  452. pGet = self.buildGetParams(request)
  453. if page.startswith("/images/") or page.startswith("/js/") or page.startswith("/inputs/"):
  454. if os.path.exists("core/"+page[1:]):
  455. f=open("core/"+page[1:])
  456. self.pages[page]=f.read()
  457. if page == "/cmd_dict": # view dictionary info
  458. path, dirs, files = os.walk("dictionary/").next()
  459. total_dirs = len(dirs)
  460. total_files = len(files)
  461. size = 0
  462. for d in dirs:
  463. path, dirs, files = os.walk("dictionary/"+d).next()
  464. total_files = total_files + len(files)
  465. for f in files:
  466. size += os.path.getsize("dictionary/"+d+"/"+f)
  467. size = self.convert_size(size)
  468. last_update = time.ctime(os.path.getctime("dictionary/"))
  469. self.pages["/cmd_dict"] = "<table align='center' border='1' cellspacing='5' cellpadding='5'><tr><td><u>Creation Date:</u></td><td><u>Size:</u></td><td><u>Total Words:</u></td><td><u>Total Symbols:</u></td></tr><tr><td align='center'>"+str(last_update)+"</td><td align='center'>"+str(size)+"</td><td align='center'>"+str(total_dirs)+"</td><td align='center'>"+str(total_files)+"</td></tr></table>"
  470. if page == "/cmd_remove_ocr": # remove ocr image from previews
  471. if not pGet["symbol"]=="off":
  472. self.pages["/cmd_remove_ocr"] = "<div style='display:block' id='discarding' name='discarding'><pre>[Info] Discarding image from previews...</pre></div>"
  473. symbol = pGet["symbol"]
  474. try:
  475. os.remove("core/" + symbol)
  476. except:
  477. pass
  478. if page == "/cmd_move_ocr": # move ocr image from previews to dictionary
  479. if not pGet["symbol"]=="off":
  480. self.pages["/cmd_move_ocr"] = "<div style='display:block' id='adding' name='adding'><pre>[Info] Adding image from previews to dictionary...</pre></div>"
  481. symbol = pGet["symbol"]
  482. letter = pGet["letter"]
  483. o = "core/" + symbol
  484. d = "dictionary/" + letter
  485. try:
  486. if not os.path.exists(d):
  487. os.makedirs(d)
  488. head, tail = os.path.split(symbol)
  489. final = d + "/" + tail
  490. copyfile(o, final) # copy file to letter on dictionary
  491. os.remove(o) # purge from previews
  492. except:
  493. pass
  494. if page == "/cmd_list": # list mods
  495. self.pages["/cmd_list"] = "<pre>Waiting for a list of available modules...</pre>"
  496. runcmd = "(python -i cintruder --mods-list "+ "|tee /tmp/out) &"
  497. if page == "/cmd_list_update":
  498. if not os.path.exists('/tmp/out'):
  499. open('/tmp/out', 'w').close()
  500. with open('/tmp/out', 'r') as f:
  501. self.pages["/cmd_list_update"] = "<pre>"+f.read()+"<pre>"
  502. if page == "/cmd_track": # tracking
  503. self.pages["/cmd_track"] = "<pre>Waiting for tracking results...</pre>"
  504. if pGet["tor"]=="on":
  505. cmd_options = cmd_options + "--proxy 'http://localhost:8118' "
  506. if pGet["verbose"]=="on":
  507. cmd_options = cmd_options + "--verbose "
  508. runcmd = "(python -i cintruder --track '"+pGet["tracking_source"]+"' --track-num '"+pGet["tracking_num"]+"' " + cmd_options + "|tee /tmp/out) &"
  509. if page == "/cmd_track_update":
  510. if not os.path.exists('/tmp/out'):
  511. open('/tmp/out', 'w').close()
  512. with open('/tmp/out', 'r') as f:
  513. self.pages["/cmd_track_update"] = "<pre>"+f.read()+"<pre>"
  514. if page == "/cmd_tracklist": # list last tracks
  515. self.pages["/cmd_tracklist"] = "<pre>Waiting for a list of last tracks...</pre>"
  516. runcmd = "(python -i cintruder --tracked-list "+ "|tee /tmp/out) &"
  517. if page == "/cmd_tracklist_update":
  518. if not os.path.exists('/tmp/out'):
  519. open('/tmp/out', 'w').close()
  520. with open('/tmp/out', 'r') as f:
  521. self.pages["/cmd_tracklist_update"] = "<pre>"+f.read()+"<pre>"
  522. if page == "/cmd_train": # training
  523. self.pages["/cmd_train"] = "<pre>Waiting for training results...</pre>"
  524. if pGet["tor"]=="on":
  525. cmd_options = cmd_options + "--proxy 'http://localhost:8118' "
  526. if pGet["verbose"]=="on":
  527. cmd_options = cmd_options + "--verbose "
  528. if not pGet["colourID"]=="off":
  529. cmd_options = cmd_options + "--set-id='" + pGet["colourID"] + "' "
  530. if not pGet["module"]=="off":
  531. cmd_options = cmd_options + "--mod='" + pGet["module"] + "' "
  532. if pGet["source_file"]=="off": # from remote url source
  533. runcmd = "(python -i cintruder --train '"+pGet["train_url"]+"' " + cmd_options + "|tee /tmp/out) &"
  534. else: # from local source
  535. source_file = pGet["source_file"]
  536. runcmd = "(python -i cintruder --train '"+source_file+"' " + cmd_options + "|tee /tmp/out) &"
  537. if page == "/cmd_train_update":
  538. if not os.path.exists('/tmp/out'):
  539. open('/tmp/out', 'w').close()
  540. with open('/tmp/out', 'r') as f:
  541. self.pages["/cmd_train_update"] = "<pre>"+f.read()+"<pre>"
  542. if page == "/cmd_crack": # cracking
  543. self.pages["/cmd_crack"] = "<pre>Waiting for cracking (bruteforcing) results...</pre>"
  544. if pGet["tor"]=="on":
  545. cmd_options = cmd_options + "--proxy 'http://localhost:8118' "
  546. if pGet["verbose"]=="on":
  547. cmd_options = cmd_options + "--verbose "
  548. if not pGet["colourID"]=="off":
  549. cmd_options = cmd_options + "--set-id='" + pGet["colourID"] + "' "
  550. if not pGet["module"]=="off":
  551. cmd_options = cmd_options + "--mod='" + pGet["module"] + "' "
  552. if not pGet["xml"]=="off":
  553. cmd_options = cmd_options + "--xml='" + pGet["xml"] + "' "
  554. if pGet["source_file"]=="off": # from remote url source
  555. runcmd = "(python -i cintruder --crack '"+pGet["crack_url"]+"' " + cmd_options + "|tee /tmp/out) &"
  556. else: # from local source
  557. source_file = pGet["source_file"]
  558. runcmd = "(python -i cintruder --crack '"+source_file+"' " + cmd_options + "|tee /tmp/out) &"
  559. if page == "/cmd_crack_update":
  560. if not os.path.exists('/tmp/out'):
  561. open('/tmp/out', 'w').close()
  562. with open('/tmp/out', 'r') as f:
  563. self.pages["/cmd_crack_update"] = "<pre>"+f.read()+"<pre>"
  564. ctype = "text/html"
  565. if page.find(".js") != -1:
  566. ctype = "text/javascript"
  567. elif page.find(".txt") != -1:
  568. ctype = "text/plain"
  569. elif page.find(".ico") != -1:
  570. ctype = "image/x-icon"
  571. elif page.find(".png") != -1:
  572. ctype = "image/png"
  573. elif page.find(".jpeg") != -1:
  574. ctype = "image/jpeg"
  575. elif page.find(".jpg") != -1:
  576. ctype = "image/jpeg"
  577. elif page.find(".gif") != -1:
  578. ctype = "image/gif"
  579. if page in self.pages:
  580. return dict(run=runcmd, code="200 OK", html=self.pages[page], ctype=ctype)
  581. return dict(run=runcmd, code="404 Error", html="404 Error<br><br>Page not found...", ctype=ctype)
  582. class Command(object):
  583. def __init__(self, cmd):
  584. self.cmd = cmd
  585. self.process = None
  586. def run(self, timeout):
  587. def target():
  588. self.process = subprocess.Popen(self.cmd, shell=True)
  589. thread = threading.Thread(target=target)
  590. thread.start()
  591. thread.join(timeout)
  592. if thread.is_alive():
  593. self.process.terminate()
  594. thread.join()
  595. if __name__ == "__main__":
  596. webbrowser.open('http://127.0.0.1:9999', new=1)
  597. tcpsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  598. tcpsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  599. tcpsock.bind((host, port))
  600. while True:
  601. tcpsock.listen(4)
  602. (clientsock, (ip, c_port)) = tcpsock.accept()
  603. newthread = ClientThread(ip, c_port, clientsock)
  604. newthread.start()