forked from zhuzhibo0/sslcloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkasync.py
113 lines (86 loc) · 2.61 KB
/
checkasync.py
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
#!/usr/bin/env python
# encoding:utf-8
'''
Created on 2016��5��17��
@author: zhuzb
'''
import urllib2
import urllib
import sys
import argparse
import django
import logging
import requests
import json
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE','sslcloud.settings')
import django
django.setup()
from sslcheck.models import checktask
global sslyze_module
sslyze_module = []
def postHttp(url,postdata):
#url编码
postdata=urllib.urlencode(postdata)
#enable cookie
request = urllib2.Request(url,postdata)
response=urllib2.urlopen(request)
print response
def make_parser():
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--domain', help='domain www.baidu.com', dest='domain')
parser.add_argument('-s', '--server', help='server 127.0.0.1', dest='server')
parser.add_argument('-m', '--module', help='module basic/ccs/hsts/heartbleed', dest='module')
parser.add_argument('-i', '--projectid', help='projectid 1', dest='pid')
return parser
define_modules={'basic':'--certinfo_basic ',
'ccs':'--openssl_ccs ',
'hsts':'--hsts ',
'heartbleed':'--heartbleed ',
'poodle':'--poodle ',
}
def indefinemodule(name):
try:
define_modules[name]
return True
except:
return False
def valid_args(args):
if args.domain == None or args.server == None or args.pid == None:
return False
if args.module == None:
return False
global sslyze_module
sslyze_module = args.module.split(',')
for i in sslyze_module:
print i
if not indefinemodule(i):
return False
return True
def main():
global sslyze_module
parser = make_parser()
args = parser.parse_args()
import time
if not valid_args(args):
parser.print_help()
return
task =checktask.objects.filter(project_id=args.pid)
task=task[0]
jsonfilename = args.domain+str(args.pid)+'.json'
cmdarg = ''
for mm in sslyze_module:
cmdarg+=define_modules[mm]
cmd = 'sslyze_cli.py '+cmdarg+args.domain +' --json_out '+'./'+jsonfilename
print '############\n'+ cmd +'\n############\n'
os.system(cmd)
ff = open('./'+jsonfilename)
data = {'domain':args.domain,'project_id':args.pid,'data':ff.read()}
##print data['data']
ff.close()
os.remove('./'+jsonfilename)
postHttp('http://'+args.server+'/project/uploadcheckresult',data)
task.lastcheck= time.time()
task.save()
if __name__ == '__main__':
main()