Skip to content

Commit

Permalink
[+] v2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
WangYihang committed Jul 9, 2019
1 parent 6c5cd98 commit ce01e71
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 47 deletions.
2 changes: 2 additions & 0 deletions SourceLeakHacker.py
Expand Up @@ -40,7 +40,9 @@ def main():
prompt.show(sys.argv[0])
exit(1)
listFile = open('list.txt', 'r')

dispatcher.start(website, threadNumber, listFile, timeout)

output.asTable()
output.asCSV("result.csv")

Expand Down
9 changes: 6 additions & 3 deletions lib/core/dispatcher.py
Expand Up @@ -29,16 +29,19 @@ def start(website, threadNumber, listFile, timeout):
logger.detail("%d tasks dispatched, starting threads..." % (len(threads)))

# Start threads
counter = 0
# counter = 0
for thread in threads:
if context.CTRL_C_FLAG:
break
# print("[%d / %d] Finished" % (counter, len(threads)))
# logger.detail("[%d / %d] Finished" % (counter, len(threads)))
thread.start()
thread.join()
while True:
if context.CTRL_C_FLAG:
break
# -1 for main thread
if ((len(threading.enumerate()) - 1) < threadNumber):
break
counter += 1
# counter += 1


40 changes: 15 additions & 25 deletions lib/core/spider.py
Expand Up @@ -14,47 +14,37 @@ def sniff(url, timeout):

def check(url, timeout):
try:
context.screenLock.acquire()

if timeout <= 0:
timeout = 4
start_time = time.time()
response = requests.head(url, timeout = timeout)
logger.correct(response.status_code)

end_time = time.time()

code = response.status_code
content_length = int(response.headers["Content-Length"])
content_type = response.headers["Content-Type"]
if "Content-Length" in response.headers:
content_length = response.headers["Content-Length"]
else:
content_length = "0"
if "Content-Type" in response.headers:
content_type = response.headers["Content-Type"]
else:
content_type = "UNKNOWN"
time_used = end_time - start_time

context.result[url] = {
"code":code,
"headers":response.headers,
"time":time_used,
"Content-Length": content_length,
"Content-Type": content_type,
}

if (code / 100) == 1:
logger.http("[%d]\t%d\t%02f\t%s\t%s" % (code, content_length, time_used, content_type, url), code)
elif (code / 100) == 2:
logger.http("[%d]\t%d\t%02f\t%s\t%s" % (code, content_length, time_used, content_type, url), code)
# Some site use one response for pages not exists.
# Try to avoid that situation
if "404" in response.text:
logger.error(url + "\tMaybe every page same!")
elif (code / 100) == 3:
logger.http("[%d]\t%d\t%02f\t%s\t%s" % (code, content_length, time_used, content_type, url), code)
elif (code / 100) == 4:
logger.http("[%d]\t%d\t%02f\t%s\t%s" % (code, content_length, time_used, content_type, url), code)
elif (code / 100) == 5:
logger.http("[%d]\t%d\t%02f\t%s\t%s" % (code, content_length, time_used, content_type, url), code)
else:
logger.error("[%d]\t%d\t%02f\t%s\t%s" % (code, content_length, time_used, content_type, url))

logger.http("[%d]\t%s\t%02f\t%s\t%s" % (code, content_length, time_used, content_type, url), code)
except Exception as e:
context.screenLock.acquire()
logger.error(e)
finally:
logger.detail(e)
pass
context.screenLock.release()

class Spider(threading.Thread):
def __init__(self, url, timeout):
Expand Down
10 changes: 5 additions & 5 deletions lib/util/color.py
@@ -1,15 +1,15 @@
from termcolor import colored

def colorProjection(code):
if (code / 100) == 1:
if int(code / 100) == 1:
return ("blue", "on_grey")
elif (code / 100) == 2:
elif int(code / 100) == 2:
return ("green", "on_grey")
elif (code / 100) == 3:
elif int(code / 100) == 3:
return ("yellow", "on_grey")
elif (code / 100) == 4:
elif int(code / 100) == 4:
return ("red", "on_grey")
elif (code / 100) == 5:
elif int(code / 100) == 5:
return ("magenta", "on_grey")
else:
return ("cyan", "on_grey")
Expand Down
18 changes: 16 additions & 2 deletions lib/util/logger.py
@@ -1,18 +1,32 @@
from termcolor import colored
from lib.util import color
from lib.context import context

def error(content):
context.screenLock.acquire()
print(colored(content, 'red', 'on_grey'))
context.screenLock.release()

def correct(content):
context.screenLock.acquire()
print(colored(content, 'green', 'on_grey'))
context.screenLock.release()


def detail(content):
context.screenLock.acquire()
print(colored(content, 'blue', 'on_grey'))
context.screenLock.release()


def plain(content):
print(colored(content, 'cyan', 'on_grey'))
context.screenLock.acquire()
print(colored(content, 'white', 'on_grey'))
context.screenLock.release()


def http(content, code):
context.screenLock.acquire()
color_config = color.colorProjection(code)
print(colored(content, color_config[0], color_config[1]))
print(colored(content, color_config[0], color_config[1]))
context.screenLock.release()
24 changes: 13 additions & 11 deletions lib/util/output.py
Expand Up @@ -3,6 +3,7 @@

from lib.util import string
from lib.util import color
from lib.util import logger
from lib.context import context

headers = ["Code", "Length", "Time", "Type", "URL"]
Expand All @@ -11,21 +12,22 @@ def asTable():
table = prettytable.PrettyTable()
table.field_names = headers
for k, v in context.result.items():
if v["code"] != 404:
table.add_row([
# color.colorByStatusCode(v["code"], v["code"]),
v["code"],
v["headers"]["Content-Length"],
v["time"],
v["headers"]["Content-Type"],
string.fixLength(k, 0x20)]
)
# if v["code"] != 404:
table.add_row([
color.colorByStatusCode(v["code"], v["code"]),
# v["code"],
v["Content-Length"],
"%02f" % v["time"],
v["Content-Type"],
# string.fixLength(k, 0x20)
k,
])
table.set_style(prettytable.MSWORD_FRIENDLY)
print(table)
logger.plain(table)

def asCSV(filename):
with open(filename, 'w') as f:
cvs_writer = csv.writer(f)
cvs_writer.writerow(headers)
for k, v in context.result.items():
cvs_writer.writerow([v["code"], v["headers"]["Content-Length"], v["time"], v["headers"]["Content-Type"], k])
cvs_writer.writerow([v["code"], v["Content-Length"], v["time"], v["Content-Type"], k])
3 changes: 2 additions & 1 deletion lib/util/terminal.py
@@ -1,8 +1,9 @@
import subprocess
import platform
import sys

def clear():
if platform.system()=="Windows":
subprocess.Popen("cls", shell=True).communicate()
else:
print("\033c", end="")
sys.stdout.write("\033c")

0 comments on commit ce01e71

Please sign in to comment.