├── .gitignore ├── LICENSE ├── README.md ├── __init__.py ├── lib ├── __init__.py ├── base.py ├── check_proxy.py ├── parse_target.py └── utils.py └── pr0xy.py /.gitignore: -------------------------------------------------------------------------------- 1 | #python 2 | *.pyc 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pr0xy 2 | 教学用多线程扫描框架(代理扫描) 3 | 4 | * 支持插件拓展 5 | * 多线程 6 | * 架构简单 7 | 8 | ## 使用方法 9 | 10 | usage: pr0xy.py [-h] [--ports PORTS] [--type TYPE] IP 11 | 12 | Pr0xy Scan and collect proxy info 13 | 14 | positional arguments: 15 | IP The IP you want to check: INPUT format:\ 1.2.3.4-1.2.5.6 or 16 | 45.67.89.0/24 or 45.78.1.48 17 | 18 | optional arguments: 19 | -h, --help show this help message and exit 20 | --ports PORTS The ports you want to check, Plz input single port or with a 21 | format like: 82,80 or 100-105 22 | --type TYPE Type of scan [Now Just Support proxy] 23 | 24 | * IP 就表示 IP地址,你可以输入单个或者多个(必须是点分十进制),当然形式限制三种: 25 | * 1.单个 IP 地址 26 | * 2.短横线连接符表示的 IP 范围(例如 1.2.3.4-1.2.3.9 这表示 6 个 IP) 27 | * 3.带有掩码的网络范围(例如1.2.3.0/24) 28 | * PORTS 端口:想要扫描的端口 支持格式:单个端口(80),逗号分隔(80,82,83),短横线表范围(80-85) 29 | * TYPE 类型:这里的类型还是有必要解释的,万一以后需要添加其他的功能,就可以直接改动一张表添加新的模块,然后通过指定类型调用。 30 | 31 | ## 结果说明 32 | 如果成功扫描到代理,会在当前目录生成一个 success.txt 的文件,并且在当前 console 中提示,如果没能扫描到,则会出现一个 failed.txt 记录失败的地址。 -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VillanCh/pr0xy/4f339e49517fe6a6ce179f158954ae145e827d3b/__init__.py -------------------------------------------------------------------------------- /lib/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VillanCh/pr0xy/4f339e49517fe6a6ce179f158954ae145e827d3b/lib/__init__.py -------------------------------------------------------------------------------- /lib/base.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | #coding:utf-8 3 | """ 4 | Author: -- 5 | Purpose: Base Class 6 | Created: 2016/12/6 7 | """ 8 | 9 | import unittest 10 | import abc 11 | import types 12 | 13 | ######################################################################## 14 | class PluginBaseClass(object): 15 | """""" 16 | 17 | __metaclass__ = abc.ABCMeta 18 | 19 | #---------------------------------------------------------------------- 20 | def __init__(self): 21 | """Constructor""" 22 | pass 23 | 24 | 25 | #---------------------------------------------------------------------- 26 | @abc.abstractproperty 27 | def name(self): 28 | """""" 29 | return '...' 30 | 31 | #---------------------------------------------------------------------- 32 | @abc.abstractproperty 33 | def description(self): 34 | """""" 35 | return '...' 36 | 37 | #---------------------------------------------------------------------- 38 | @abc.abstractmethod 39 | def _work(self, *args, **kwargs): 40 | """""" 41 | return '...' 42 | 43 | #---------------------------------------------------------------------- 44 | @abc.abstractmethod 45 | def _parse_result(self, result): 46 | """""" 47 | return "..." 48 | 49 | #---------------------------------------------------------------------- 50 | def start(self, *args, **kwargs): 51 | """""" 52 | #print 'cl' 53 | ret = self._work(*args, **kwargs) 54 | #SOMETHING IF NEEDED 55 | return self._parse_result(ret) 56 | 57 | #abc.ABCMeta.register(PluginBaseClass) 58 | ######################################################################## 59 | class Demo(PluginBaseClass): 60 | """""" 61 | 62 | pass 63 | 64 | 65 | 66 | ######################################################################## 67 | class BaseClassTest(unittest.case.TestCase): 68 | """""" 69 | 70 | #---------------------------------------------------------------------- 71 | def runTest(self): 72 | """""" 73 | print 'sss' 74 | BaseClassTest() 75 | Demo() 76 | 77 | 78 | 79 | if __name__ == '__main__': 80 | unittest.main() -------------------------------------------------------------------------------- /lib/check_proxy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | #coding:utf-8 3 | """ 4 | Author: -- 5 | Purpose: check proxy available 6 | Created: 2016/10/31 7 | """ 8 | 9 | import unittest 10 | import requests 11 | from pprint import pprint 12 | 13 | from base import PluginBaseClass 14 | 15 | 16 | ######################################################################## 17 | class CheckProxyPlugin(PluginBaseClass): 18 | """""" 19 | 20 | _name = 'Check Proxy' 21 | _description = 'Check if the specific addr(IP:PORT) is a \ 22 | HTTP(s) proxy' 23 | 24 | #---------------------------------------------------------------------- 25 | def __init__(self, target): 26 | """""" 27 | self.target = target 28 | 29 | #---------------------------------------------------------------------- 30 | @property 31 | def name(self): 32 | """getter for self._name""" 33 | return self._name 34 | 35 | #---------------------------------------------------------------------- 36 | @property 37 | def description(self): 38 | """getter for self._description""" 39 | return self._description 40 | 41 | #---------------------------------------------------------------------- 42 | def _work(self, *args, **kwargs): 43 | """""" 44 | #print 'called' 45 | ret = CheckProxy(self.target) 46 | return ret.test(timeout=int(kwargs['timeout']) if kwargs.has_key('timeout') 47 | else 3) 48 | 49 | #---------------------------------------------------------------------- 50 | def _parse_result(self, result): 51 | """""" 52 | return result 53 | 54 | 55 | 56 | 57 | 58 | ######################################################################## 59 | class CheckProxy(object): 60 | """Check Proxy 61 | 62 | Attributes: 63 | target: A str, the target you want to check. 64 | Example: 44.4.4.4:44""" 65 | 66 | #---------------------------------------------------------------------- 67 | def __init__(self, target): 68 | """Constructor""" 69 | self.target = target 70 | self.ip = target.split(':')[0] 71 | 72 | #---------------------------------------------------------------------- 73 | def test(self, timeout=3): 74 | '''Test the self.target whether is a http proxy addr 75 | 76 | Returns: 77 | A dict: if the result is True: 78 | Example: 79 | { 80 | 'result':True, 81 | 'proxy':{ 82 | 'http':'xxx.xxx.xxx.xx:port', 83 | 'https':'xxx.xxx.xxx.xx:port' 84 | } 85 | } 86 | if the target isn' t the http proxy addr, 87 | the result['proxy'] will be None 88 | ''' 89 | result = {} 90 | result['result'] = False 91 | result['proxy'] = self._check_ip(timeout=timeout) 92 | result['from'] = self.target 93 | return result 94 | 95 | #---------------------------------------------------------------------- 96 | def _check_ip(self, timeout): 97 | """Check IP return the proxy or None 98 | 99 | Returns: 100 | A dict or None: if the result is True(the addr can be a proxy) 101 | the result is the dict like {'http':'http://xx.xx.xx.xx:xx', 102 | 'https':'https://xx.xx.xx.xx:xx'} 103 | And if the https proxy can't be used the key named 'https', 104 | Well, if the result is False(the addr can't be used as a proxy) 105 | the result is None""" 106 | 107 | headers = {} 108 | headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36' 109 | 110 | check_ip_http = 'http://1212.ip138.com/ic.asp' 111 | check_ip_https = 'https://1212.ip138.com/ic.asp' 112 | 113 | addr_proxy = {} 114 | addr_proxy['http'] = 'http://' + self.target 115 | addr_proxy['https'] = 'https://' + self.target 116 | 117 | result = {} 118 | 119 | http_rsp = '' 120 | try: 121 | http_rsp = requests.get(check_ip_http, proxies=addr_proxy, timeout=timeout, 122 | headers=headers).text 123 | except: 124 | pass 125 | 126 | if self.ip in http_rsp: 127 | result['http'] = 'http://' + self.target 128 | 129 | https_rsp = '' 130 | try: 131 | https_rsp = requests.get(check_ip_https, proxies=addr_proxy, 132 | verify=False, timeout=timeout, 133 | headers=headers).text # close https verify 134 | except: 135 | pass 136 | 137 | if self.ip in https_rsp: 138 | result['https'] = 'https://' + self.target 139 | 140 | if result.has_key('http') or result.has_key('https'): 141 | return result 142 | else: 143 | return None 144 | 145 | ######################################################################## 146 | class CheckProxyTest(unittest.case.TestCase): 147 | """Test CheckProxy""" 148 | def test_check_ip(self): 149 | ''' 150 | result should be 151 | { 152 | 'result':True, 153 | 'proxy':{ 154 | 'http':'xxx.xxx.xxx.xx:port', 155 | 'https':'xxx.xxx.xxx.xx:port' 156 | } 157 | } 158 | ''' 159 | print 'API test' 160 | #创建想要测试的实例 161 | master = CheckProxy('78.6.5.45:8080') 162 | result = master.test(3) 163 | 164 | ##对结果进行测试 165 | #测试结果必须是个 dict 类型 166 | self.assertIsInstance(result, dict) 167 | #必须有一个 result 和 proxy 的键 168 | self.assertTrue(result.has_key('result')) 169 | self.assertTrue(result.has_key('proxy')) 170 | #result 键对应的值必须是一个 bool 类型 171 | self.assertIsInstance(result['result'], bool) 172 | #断言测试 result['proxy'] 的类型 173 | if result['result']: 174 | self.assertIsInstance(result['proxy'], dict) 175 | else: 176 | self.assertIsNone(result['proxy']) 177 | print 'API test success!' 178 | 179 | def test_ip_check_function(self): 180 | '''test function''' 181 | print 'function test' 182 | 183 | #首先测试一个正确的实例(已知一定是个代理) 184 | addr = '122.96.59.105:82' 185 | master = CheckProxy(target=addr) 186 | result = master.test(timeout=3) 187 | 188 | #在前一个例子中我们验证了接口 189 | #那么在这里我们只需要验证一下 190 | #一定是完成了代理检测的,而且成功了 191 | proxy = result['proxy'] 192 | #self.assertTrue(proxy.has_key('http')) 193 | 194 | print 'function test success!' 195 | def test_plugin_ins(self): 196 | '''''' 197 | pprint('Plugin Test') 198 | ret = CheckProxyPlugin() 199 | _result = ret.start('45.78.5.48:333') 200 | for _ in _result: 201 | pprint(ret.name) 202 | pprint(ret.description) 203 | pprint(_) 204 | 205 | if __name__ == '__main__': 206 | unittest.main() 207 | -------------------------------------------------------------------------------- /lib/parse_target.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | #coding:utf-8 3 | """ 4 | Author: -- 5 | Purpose: Parse Target 6 | Created: 2016/11/11 7 | """ 8 | 9 | import unittest 10 | import re 11 | import IPy 12 | from IPy import IP 13 | PORTS = ['80', '8080', '8123', '3128', '82'] 14 | 15 | 16 | #---------------------------------------------------------------------- 17 | def generate_target(IPs, ports): 18 | """Generate the target for scanning HTTP proxy""" 19 | 20 | gen = None 21 | if '-' in IPs: 22 | pairs = IPs.split('-') 23 | start = pairs[0] 24 | end = pairs[1] 25 | gen = int2ips(IP(start).int(), IP(end).int()) 26 | else: 27 | gen = IP(IPs) 28 | 29 | for i in gen: 30 | for port in ports: 31 | if isinstance(port, int): 32 | port = str(port) 33 | yield ':'.join([i.__str__(), port]) 34 | 35 | #---------------------------------------------------------------------- 36 | def int2ips(start, end): 37 | """""" 38 | for i in xrange(int(start), int(end)): 39 | yield IPy.intToIp(i, version=4) 40 | 41 | 42 | 43 | 44 | ######################################################################## 45 | class ParseTargetTest(unittest.case.TestCase): 46 | """Test Parse Target""" 47 | 48 | #-------------------------------------------------------------- 49 | def runTest(self): 50 | IPs_1 = '123.1.2.0/24' 51 | IPs_2 = '123.1.2.3-123.1.3.5' 52 | ip_gen = generate_target(IPs_1, PORTS) 53 | for i in ip_gen: 54 | ip_port = i.split(':') 55 | print ip_port 56 | try: 57 | IPy.IP(ip_port[0]) 58 | except ValueError: 59 | pass 60 | 61 | ip_gen = generate_target(IPs_2, PORTS) 62 | for i in ip_gen: 63 | ip_port = i.split(':') 64 | print ip_port 65 | try: 66 | IPy.IP(ip_port[0]) 67 | except ValueError: 68 | pass 69 | 70 | 71 | if __name__ == '__main__': 72 | unittest.main() -------------------------------------------------------------------------------- /lib/utils.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | #coding:utf-8 3 | """ 4 | Author: -- 5 | Purpose: Provide some useful utils 6 | Created: 2016/10/29 7 | """ 8 | import uuid 9 | import time 10 | import unittest 11 | from Queue import Queue 12 | import threading 13 | import multiprocessing 14 | from threading import Thread 15 | 16 | from multiprocessing import Process 17 | 18 | 19 | #---------------------------------------------------------------------- 20 | def start_thread(func, *args, **kwargs): 21 | """""" 22 | Thread(target=func, args=args, kwargs=kwargs).start() 23 | 24 | 25 | ######################################################################## 26 | class Pool(object): 27 | """Thread or Proccess Pool to support the 28 | concurrence of many tasks""" 29 | 30 | #---------------------------------------------------------------------- 31 | def __init__(self, thread_max=50, mode='Thread'): 32 | """Constructor""" 33 | modes = ['thread', 'process'] 34 | self.mode = mode.lower() if mode in modes else 'thread' 35 | 36 | self.task_list = [] 37 | self.result_queue = Queue() 38 | 39 | self.signal_name = self._uuid1_str() 40 | 41 | self.lock = threading.Lock() if self.mode == 'thread' else multiprocessing.Lock() 42 | 43 | self.thread_max = thread_max 44 | self.current_thread_count = 0 45 | 46 | def _uuid1_str(self): 47 | '''Returns: random UUID tag ''' 48 | return str(uuid.uuid1()) 49 | 50 | def add_task(self, func, *args, **argv): 51 | '''Add task to Pool and wait to exec 52 | 53 | Params: 54 | func : A callable obj, the entity of the current task 55 | args : the args of [func] 56 | argv : the argv of [func] 57 | ''' 58 | assert callable(func), '[!] Function can \'t be called' 59 | 60 | ret = {} 61 | ret['func'] = func 62 | ret['args'] = args 63 | ret['argv'] = argv 64 | ret['uuid'] = self.signal_name 65 | self.task_list.append(ret) 66 | 67 | def run(self): 68 | """""" 69 | Thread(target=self._run).start() 70 | 71 | return self.result_queue 72 | 73 | #---------------------------------------------------------------------- 74 | def _run(self): 75 | """""" 76 | for i in self.task_list: 77 | #print self.current_thread_count 78 | while self.thread_max <= self.current_thread_count: 79 | time.sleep(0.3) 80 | self._start_task(i) 81 | 82 | def _start_task(self, task): 83 | """""" 84 | self.current_thread_count = self.current_thread_count + 1 85 | try: 86 | if self.mode == 'thread': 87 | #print 'Start' 88 | Thread(target=self._worker, args=(task,)).start() 89 | elif self.mode == 'process': 90 | Process(target=self._worker, args=(task,)).start() 91 | 92 | except TypeError: 93 | self.current_thread_count = self.current_thread_count - 1 94 | 95 | def _worker(self, dictobj): 96 | """""" 97 | func = dictobj['func'] 98 | args = dictobj['args'] 99 | argv = dictobj['argv'] 100 | 101 | result = func(*args, **argv) 102 | 103 | self.lock.acquire() 104 | self._add_result_to_queue(result=result) 105 | self.lock.release() 106 | 107 | def _add_result_to_queue(self, **kw): 108 | """""" 109 | assert kw.has_key('result'), '[!] Result Error!' 110 | 111 | self.result_queue.put(kw['result']) 112 | self.current_thread_count = self.current_thread_count - 1 113 | 114 | 115 | class UtilsTest(unittest.case.TestCase): 116 | def runTest(self): 117 | ms = inspect.getmembers(self) 118 | ms = map(lambda x: x[0], ms) 119 | for i in ms: 120 | if callable(eval('self.'+i)): 121 | if i.startswith('test_'): 122 | eval('self.' + i + '()') 123 | 124 | def test_pool(self): 125 | def demo_task(*args): 126 | '''simulate the plugin.run''' 127 | print '[!] Computing!' 128 | time.sleep(args[0]) 129 | print '[!] Finished!' 130 | print 131 | returns = 'Runtime Length : %s' % str(args) 132 | return returns 133 | pool = Pool(mode='thread') 134 | pool.add_task(demo_task, 7) 135 | pool.add_task(demo_task, 3) 136 | q = pool.run() 137 | print pool.current_thread_count 138 | self.assertIsInstance(q, Queue) 139 | 140 | r = q.get() 141 | print r 142 | self.assertIsInstance(r, str) 143 | r = q.get() 144 | print r 145 | self.assertIsInstance(r, str) 146 | 147 | print pool.current_thread_count 148 | 149 | 150 | if __name__ == '__main__': 151 | unittest.main() -------------------------------------------------------------------------------- /pr0xy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | #coding:utf-8 3 | """ 4 | Author: -- 5 | Purpose: Pr0xy Main 6 | Created: 2016/12/6 7 | """ 8 | 9 | import types 10 | import time 11 | import json 12 | import os 13 | import sys 14 | import unittest 15 | import argparse 16 | import traceback 17 | from Queue import Empty 18 | from pprint import pprint 19 | 20 | 21 | from lib.utils import Pool 22 | from lib import parse_target 23 | from lib.check_proxy import CheckProxy, CheckProxyPlugin 24 | 25 | 26 | SCAN_TYPE_TABLE = { 27 | 'proxy': {'module':'lib.check_proxy', 28 | 'plugin_class':'CheckProxyPlugin'} 29 | } 30 | 31 | #---------------------------------------------------------------------- 32 | def parse_args(): 33 | """""" 34 | parser = argparse.ArgumentParser(description='Pr0xy Scan and collect proxy info') 35 | parser.add_argument('IP', 36 | help='''The IP you want to check: \nINPUT format:\ 1.2.3.4-1.2.5.6 or 45.67.89.0/24 or 37 | 45.78.1.48''') 38 | parser.add_argument('--ports', dest='ports', 39 | help='The ports you want to check, Plz input single port\ 40 | or with a format like: 82,80 or 100-105') 41 | parser.add_argument('--type', dest='type', 42 | help='Type of scan [Now Just Support proxy]') 43 | 44 | args = parser.parse_args() 45 | args.IP 46 | #print args.ports 47 | #pprint(args) 48 | PORTS = [] 49 | raw_ports = args.ports 50 | if '-' in raw_ports: 51 | _ = raw_ports.split('-') 52 | _min = _[0] 53 | _max = _[1] 54 | PORTS = range(_min, _max) 55 | elif ',' in raw_ports: 56 | _list = raw_ports.split(',') 57 | for _ in _list: 58 | if _.isdigit(): 59 | PORTS.append(int(_)) 60 | else: 61 | pass 62 | #PORTS.append(object) 63 | if PORTS == []: 64 | PORTS = parse_target.PORTS 65 | else: 66 | if raw_ports.isdigit(): 67 | PORTS.append(int(raw_ports)) 68 | else: 69 | PORTS = parse_target.PORTS 70 | 71 | #pprint(args.IP) 72 | #pprint(PORTS) 73 | return (args.IP, PORTS, args.type) 74 | 75 | 76 | #---------------------------------------------------------------------- 77 | def process_result(results): 78 | """""" 79 | if isinstance(results, types.GeneratorType): 80 | for result in results: 81 | #pprint('') 82 | if result['result']: 83 | pprint('Success! %s' % result['from'] ) 84 | os.system('echo %s >> success.txt' % json.dumps(result['proxy'])) 85 | else: 86 | pprint('Failed! %s' % result['from'] ) 87 | os.system('echo %s >> failed.txt' % result['from']) 88 | else: 89 | result = results 90 | if result['result']: 91 | pprint('Success! %s' % result['from'] ) 92 | os.system('echo %s >> success.txt' % json.dumps(result['proxy'])) 93 | else: 94 | pprint('Failed! %s' % result['from'] ) 95 | os.system('echo %s >> failed.txt' % result['from']) 96 | 97 | 98 | #---------------------------------------------------------------------- 99 | def get_pluginclass(type_name): 100 | """""" 101 | try: 102 | try: 103 | plugin_class_path = SCAN_TYPE_TABLE[type_name] 104 | except KeyError: 105 | pprint('[!] No Such Type') 106 | exit() 107 | module_name = plugin_class_path['module'] 108 | plugin_class_name = plugin_class_path['plugin_class'] 109 | module_tmp = __import__(module_name, fromlist=plugin_class_name) 110 | ret = getattr(module_tmp, plugin_class_name) 111 | return ret 112 | except Exception, E: 113 | traceback.format_exc() 114 | exit() 115 | 116 | 117 | #---------------------------------------------------------------------- 118 | def main(): 119 | """Pr0xy main""" 120 | params = parse_args() 121 | IP = params[0] 122 | PORTS = params[1] 123 | pool = Pool() 124 | 125 | plugin_class = get_pluginclass(params[2]) 126 | 127 | for target in parse_target.generate_target(IP, PORTS): 128 | _ = plugin_class(target) 129 | pool.add_task(_.start) 130 | 131 | result_queue = pool.run() 132 | while True: 133 | try: 134 | ret = result_queue.get(timeout=0.3) 135 | process_result(ret) 136 | except Empty: 137 | pass 138 | except KeyboardInterrupt: 139 | pprint('ByeByeBye') 140 | 141 | if __name__ == '__main__': 142 | main() --------------------------------------------------------------------------------