secraft 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- secraft-0.1.0/LICENSE +21 -0
- secraft-0.1.0/PKG-INFO +332 -0
- secraft-0.1.0/README.md +309 -0
- secraft-0.1.0/pyproject.toml +37 -0
- secraft-0.1.0/setup.cfg +4 -0
- secraft-0.1.0/src/secraft/__init__.py +56 -0
- secraft-0.1.0/src/secraft/_guard.py +136 -0
- secraft-0.1.0/src/secraft/batch.py +457 -0
- secraft-0.1.0/src/secraft/brute/__init__.py +148 -0
- secraft-0.1.0/src/secraft/brute/_helper.py +72 -0
- secraft-0.1.0/src/secraft/brute/base.py +279 -0
- secraft-0.1.0/src/secraft/brute/db.py +266 -0
- secraft-0.1.0/src/secraft/brute/http.py +235 -0
- secraft-0.1.0/src/secraft/brute/impacket_proto.py +248 -0
- secraft-0.1.0/src/secraft/brute/mail_ftp.py +257 -0
- secraft-0.1.0/src/secraft/brute/redis_telnet.py +197 -0
- secraft-0.1.0/src/secraft/brute/ssh.py +102 -0
- secraft-0.1.0/src/secraft/cli.py +180 -0
- secraft-0.1.0/src/secraft/crypto.py +215 -0
- secraft-0.1.0/src/secraft/jwt.py +249 -0
- secraft-0.1.0/src/secraft/ledger.py +227 -0
- secraft-0.1.0/src/secraft/net/__init__.py +14 -0
- secraft-0.1.0/src/secraft/net/_synraw.py +215 -0
- secraft-0.1.0/src/secraft/net/banner.py +276 -0
- secraft-0.1.0/src/secraft/net/fingerprint.py +187 -0
- secraft-0.1.0/src/secraft/net/ping.py +192 -0
- secraft-0.1.0/src/secraft/net/portscan.py +378 -0
- secraft-0.1.0/src/secraft/net/stream.py +277 -0
- secraft-0.1.0/src/secraft/net/syn.py +166 -0
- secraft-0.1.0/src/secraft/recon/__init__.py +12 -0
- secraft-0.1.0/src/secraft/recon/dns.py +671 -0
- secraft-0.1.0/src/secraft/recon/subdomain.py +208 -0
- secraft-0.1.0/src/secraft/result.py +381 -0
- secraft-0.1.0/src/secraft/util/__init__.py +9 -0
- secraft-0.1.0/src/secraft/util/codec.py +335 -0
- secraft-0.1.0/src/secraft/util/text.py +156 -0
- secraft-0.1.0/src/secraft/util/wordlist.py +136 -0
- secraft-0.1.0/src/secraft/web/__init__.py +16 -0
- secraft-0.1.0/src/secraft/web/csrf.py +124 -0
- secraft-0.1.0/src/secraft/web/diff.py +103 -0
- secraft-0.1.0/src/secraft/web/fuzz.py +368 -0
- secraft-0.1.0/src/secraft/web/http.py +216 -0
- secraft-0.1.0/src/secraft/web/raw.py +342 -0
- secraft-0.1.0/src/secraft/web/server.py +158 -0
- secraft-0.1.0/src/secraft/web/session.py +170 -0
- secraft-0.1.0/src/secraft.egg-info/PKG-INFO +332 -0
- secraft-0.1.0/src/secraft.egg-info/SOURCES.txt +67 -0
- secraft-0.1.0/src/secraft.egg-info/dependency_links.txt +1 -0
- secraft-0.1.0/src/secraft.egg-info/requires.txt +7 -0
- secraft-0.1.0/src/secraft.egg-info/top_level.txt +1 -0
- secraft-0.1.0/tests/test_batch.py +280 -0
- secraft-0.1.0/tests/test_brute.py +53 -0
- secraft-0.1.0/tests/test_brute_core.py +322 -0
- secraft-0.1.0/tests/test_cli.py +141 -0
- secraft-0.1.0/tests/test_core.py +167 -0
- secraft-0.1.0/tests/test_crypto_db.py +114 -0
- secraft-0.1.0/tests/test_csrf_server_stream.py +139 -0
- secraft-0.1.0/tests/test_fingerprint.py +57 -0
- secraft-0.1.0/tests/test_jwt.py +77 -0
- secraft-0.1.0/tests/test_net.py +196 -0
- secraft-0.1.0/tests/test_ping.py +66 -0
- secraft-0.1.0/tests/test_recon.py +100 -0
- secraft-0.1.0/tests/test_regressions.py +269 -0
- secraft-0.1.0/tests/test_review6.py +194 -0
- secraft-0.1.0/tests/test_round4.py +162 -0
- secraft-0.1.0/tests/test_synraw.py +76 -0
- secraft-0.1.0/tests/test_views.py +73 -0
- secraft-0.1.0/tests/test_web.py +247 -0
- secraft-0.1.0/tests/test_web_session.py +132 -0
secraft-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 guaidao2
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
secraft-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: secraft
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: secraft simplifies the security workflow: port scans, banners, web probing, DNS recon and credential checks as single function calls
|
|
5
|
+
Author: guaidao2
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: security,pentest,recon,scanner,toolkit
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Topic :: Security
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: requests>=2.25
|
|
16
|
+
Requires-Dist: paramiko>=2.7
|
|
17
|
+
Requires-Dist: pymysql>=1.0
|
|
18
|
+
Requires-Dist: psycopg2-binary>=2.9
|
|
19
|
+
Requires-Dist: pymongo>=4.0
|
|
20
|
+
Requires-Dist: impacket>=0.11
|
|
21
|
+
Requires-Dist: cryptoexp>=0.2
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# secraft
|
|
25
|
+
|
|
26
|
+
[中文文档](README.zh-CN.md) · [User guide](docs/guide.md)
|
|
27
|
+
|
|
28
|
+
**secraft simplifies the security workflow.**
|
|
29
|
+
|
|
30
|
+
Port scanning, service banners, web probing, DNS recon, credential checks — each
|
|
31
|
+
is one function call, and every call returns the same `Result` object with three
|
|
32
|
+
clear states: done, done but empty, failed. A one-off script no longer has to
|
|
33
|
+
juggle five libraries and five different ways of deciding whether the thing it
|
|
34
|
+
just did actually worked.
|
|
35
|
+
|
|
36
|
+
It is not a new language like yaklang and not a replacement for nmap, nuclei or
|
|
37
|
+
hydra. It is the glue layer: the common scenarios, each behind a name you can
|
|
38
|
+
remember.
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
import secraft as sec
|
|
42
|
+
|
|
43
|
+
r = sec.portscan("192.168.1.1")
|
|
44
|
+
print(r) # a table you can read
|
|
45
|
+
|
|
46
|
+
if 22 in r.ports:
|
|
47
|
+
sec.ssh("192.168.1.1", user="root", wordlist="pass.txt")
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Use it only on hosts you own or are authorized to test.
|
|
51
|
+
|
|
52
|
+
## Install
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install secraft
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Python 3.10+. Works on Windows, Linux and macOS. There are no extras: HTTP, DNS,
|
|
59
|
+
port scanning, SSH checks and raw packets all ship in the one package.
|
|
60
|
+
|
|
61
|
+
## 30 seconds
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
import secraft as sec
|
|
65
|
+
|
|
66
|
+
# 1. scan ports
|
|
67
|
+
r = sec.portscan("192.168.1.1", ports="1-1024")
|
|
68
|
+
print(r)
|
|
69
|
+
print(r.ports) # [22, 80, 443]
|
|
70
|
+
|
|
71
|
+
# 2. grab banners
|
|
72
|
+
sec.banner("192.168.1.1", ports=r.ports)
|
|
73
|
+
|
|
74
|
+
# 3. send HTTP
|
|
75
|
+
r = sec.http.get("https://example.com")
|
|
76
|
+
print(r.status_code, r.text[:100])
|
|
77
|
+
|
|
78
|
+
# 4. collect subdomains
|
|
79
|
+
sec.subdomain("example.com")
|
|
80
|
+
|
|
81
|
+
# 5. write your own PoC (no YAML to learn)
|
|
82
|
+
r = sec.http.get("http://example.com/index.php?id=1'")
|
|
83
|
+
if "SQL syntax" in r.text:
|
|
84
|
+
print("injection candidate")
|
|
85
|
+
|
|
86
|
+
# 6. wrap up
|
|
87
|
+
print(sec.log()) # what actually ran
|
|
88
|
+
sec.report("report.md") # Markdown you can hand over
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Why the result is not a plain dict
|
|
92
|
+
|
|
93
|
+
Every call returns a `Result` with one of three states:
|
|
94
|
+
|
|
95
|
+
- **done** — finished, and there is a result.
|
|
96
|
+
- **done, empty** — finished, and there really is nothing (host is up, every
|
|
97
|
+
port is closed).
|
|
98
|
+
- **failed** — the library side broke: no permission, no route, a missing
|
|
99
|
+
dependency, a bad argument.
|
|
100
|
+
|
|
101
|
+
Those three lead to different next steps, so they must stay distinguishable.
|
|
102
|
+
`print(r)` tells you which one you are in, why, and what to try next.
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
r.ok / r.found / r.empty / r.failed
|
|
106
|
+
r.data # structured result
|
|
107
|
+
r.raw # the underlying object: requests.Response / bytes / ...
|
|
108
|
+
r.ports # open ports
|
|
109
|
+
22 in r # port membership
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Modules
|
|
113
|
+
|
|
114
|
+
| Name | What it does |
|
|
115
|
+
| --- | --- |
|
|
116
|
+
| `sec.portscan` | TCP connect scan, pure Python, no nmap |
|
|
117
|
+
| `sec.ping` | Host discovery over TCP (open port or RST), no root, no ICMP |
|
|
118
|
+
| `sec.fingerprint` | Parse a banner into product, version and OS |
|
|
119
|
+
| `sec.synscan` | Native SYN half-open scan (Linux + root; falls back to connect elsewhere) |
|
|
120
|
+
| `sec.banner` | Grab the banner of open ports |
|
|
121
|
+
| `sec.http` | HTTP requests (a requests wrapper; `r.raw` is the `Response`) |
|
|
122
|
+
| `sec.web.session` | Persistent session: log in once, cookies and headers carry over |
|
|
123
|
+
| `sec.web.diff` | Compare two responses: status, size, body similarity, and what changed |
|
|
124
|
+
| `sec.Batch` | What a multi-target call returns: `items`, `open_ports[host]`, `counts`, `partial` |
|
|
125
|
+
| `sec.raw` | Send raw HTTP bytes, bypassing requests' normalisation |
|
|
126
|
+
| `sec.fuzz` | Replace one `FUZZ` marker with many payloads and compare each response against a control request |
|
|
127
|
+
| `sec.dns` | Hand-built DNS queries and zone-transfer (AXFR) detection |
|
|
128
|
+
| `sec.subdomain` | Subdomain brute force, with wildcard detection |
|
|
129
|
+
| `sec.ssh` / `sec.ftp` / `sec.smtp` / `sec.pop3` / `sec.imap` / `sec.telnet` / `sec.redis` / `sec.mysql` / `sec.postgres` / `sec.mongodb` / `sec.smb` / `sec.ldap` / `sec.mssql` / `sec.http_basic` / `sec.http_form` | Credential checks; can also be reached through `sec.brute.run("ssh", ...)`. Each accepts a list of hosts and returns a Batch |
|
|
130
|
+
| `sec.crypto` | RSA public-key weakness audit (small modulus, Wiener, shared primes, ...), powered by cryptoexp |
|
|
131
|
+
| `sec.jwt` | Decode, forge `alg=none`, sign and crack HMAC secrets |
|
|
132
|
+
| `sec.csrf` | Turn a captured request into an auto-submitting HTML form |
|
|
133
|
+
| `sec.serve` | Throwaway HTTP server for callbacks and self-tests |
|
|
134
|
+
| `sec.tcp` / `sec.udp` | Raw socket send/recv for services without a client here |
|
|
135
|
+
| `sec.codec` / `sec.text` / `sec.wordlist` | Encoding, text extraction, wordlists |
|
|
136
|
+
| `sec.log` / `sec.report` | Call log and Markdown report |
|
|
137
|
+
|
|
138
|
+
## Sessions, comparison, and many targets
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
with sec.web.session("http://192.168.1.10") as s:
|
|
142
|
+
s.post("/login", data={"user": "admin", "pass": "admin"})
|
|
143
|
+
base = s.get("/item?id=1")
|
|
144
|
+
test = s.get("/item?id=1'")
|
|
145
|
+
print(sec.web.diff(base, test).data) # status, length, similarity, why
|
|
146
|
+
|
|
147
|
+
b = sec.portscan(["192.168.1.1", "192.168.1.2"])
|
|
148
|
+
print(b.open_ports) # {'192.168.1.1': [22, 80]}
|
|
149
|
+
print(b.partial, b.counts) # True {'ok': 1, 'empty': 1, 'error': 0}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
One target returns a `Result`; many targets return a `Batch`. Batch does not
|
|
153
|
+
pretend to be a Result: `b.open_ports[host]` answers "which ports on which
|
|
154
|
+
host", and `"10.0.0.1" in b` asks whether that *target* is in the batch.
|
|
155
|
+
|
|
156
|
+
## A script is also a command
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
# tool.py
|
|
160
|
+
import secraft as sec
|
|
161
|
+
|
|
162
|
+
@sec.cli.command
|
|
163
|
+
def scan(target, ports: str = "", timeout: float = 1.0):
|
|
164
|
+
"""Scan a host for open ports."""
|
|
165
|
+
return sec.portscan(target, ports=ports or None, timeout=timeout)
|
|
166
|
+
|
|
167
|
+
if __name__ == "__main__":
|
|
168
|
+
raise SystemExit(sec.cli.run())
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
`python tool.py scan 10.0.0.5 --ports 1-1024` now works, `--help` comes from
|
|
172
|
+
the signature, `--json` prints the whole Result for `jq`, and the exit code
|
|
173
|
+
follows the three states (0 found, 1 empty, 2 failed). No plugin system, no
|
|
174
|
+
config file: three pieces, the decorator, `run()`, and the output.
|
|
175
|
+
|
|
176
|
+
## Credential checks: one skeleton, fifteen protocols
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
sec.brute.supported()
|
|
180
|
+
# ['ftp', 'http-basic', 'http-form', 'imap', 'ldap', 'mariadb', 'mongo',
|
|
181
|
+
# 'mongodb', 'mssql', 'mysql', 'pop3', 'postgres', 'postgresql', 'redis',
|
|
182
|
+
# 'smb', 'smtp', 'ssh', 'telnet']
|
|
183
|
+
|
|
184
|
+
sec.ssh("10.0.0.5", user="root", wordlist="pass.txt")
|
|
185
|
+
sec.redis("10.0.0.5", wordlist="pass.txt") # also spots "no password set"
|
|
186
|
+
sec.mysql("10.0.0.5", user="root", wordlist="pass.txt")
|
|
187
|
+
sec.brute.run("postgres", "10.0.0.5", user="postgres", passwords=["123456"])
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
The three states are the same everywhere: credentials found is done; tried
|
|
191
|
+
everything and found nothing is done-but-empty; no authentication ever happened
|
|
192
|
+
(protocol mismatch, cannot connect) is failed. A Redis with no password is
|
|
193
|
+
reported as unauthenticated access, never as "no password found".
|
|
194
|
+
|
|
195
|
+
Protocols: ssh, ftp, smtp (including 465/587), pop3, imap, telnet, redis,
|
|
196
|
+
http-basic, http-form, mysql, postgres, mongodb, smb, ldap, mssql.
|
|
197
|
+
|
|
198
|
+
Web, database and SMB checks go through established drivers (requests /
|
|
199
|
+
pymysql / psycopg2 / pymongo / impacket) instead of hand-written wire formats: a
|
|
200
|
+
protocol detail done wrong produces false negatives, and a feature that quietly
|
|
201
|
+
lies is worse than a missing feature.
|
|
202
|
+
|
|
203
|
+
### Concurrency
|
|
204
|
+
|
|
205
|
+
Attempts run in a thread pool. `workers` defaults to 16, the same order of
|
|
206
|
+
magnitude as hydra's `-t`, and every protocol accepts it:
|
|
207
|
+
|
|
208
|
+
```python
|
|
209
|
+
sec.ssh("10.0.0.5", user="root", wordlist="pass.txt", workers=32)
|
|
210
|
+
sec.ftp("10.0.0.5", user="admin", wordlist="pass.txt", workers=1) # one at a time
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
`workers=1` is strictly sequential. Higher values are faster but can trip
|
|
214
|
+
account lockout policies or IDS: that trade-off is yours to make, so it is a
|
|
215
|
+
parameter rather than a hidden decision. `delay` (minimum seconds between
|
|
216
|
+
attempt starts, applied globally) and
|
|
217
|
+
`max_tries` (stop after N pairs) are the other two knobs.
|
|
218
|
+
|
|
219
|
+
VNC (needs the DES challenge) and RDP (NLA) are not implemented.
|
|
220
|
+
|
|
221
|
+
## PoC without YAML
|
|
222
|
+
|
|
223
|
+
nuclei's template syntax exists to serve its command line. Inside a script,
|
|
224
|
+
deciding whether a bug is there is normally three lines:
|
|
225
|
+
|
|
226
|
+
```python
|
|
227
|
+
def thinkphp_rce(url):
|
|
228
|
+
# Raw string on purpose: in a normal string, \t becomes a tab character
|
|
229
|
+
payload = (
|
|
230
|
+
r"/index.php?s=/Index/\think\app/invokefunction"
|
|
231
|
+
"&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=1"
|
|
232
|
+
)
|
|
233
|
+
r = sec.http.get(url.rstrip("/") + payload)
|
|
234
|
+
return r.ok and "PHP Version" in r.text
|
|
235
|
+
|
|
236
|
+
if thinkphp_rce("http://example.com"):
|
|
237
|
+
print("it fired")
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
For malformed packets and raw messages, use `sec.raw`:
|
|
241
|
+
|
|
242
|
+
```python
|
|
243
|
+
def redis_unauth(host, port=6379):
|
|
244
|
+
r = sec.raw.send(host, port, b"PING\r\n")
|
|
245
|
+
return r.ok and "+PONG" in r.text
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
That is freer than YAML and easier to debug: a mistake is a Python traceback
|
|
249
|
+
with a line number. More examples in [examples/poc.py](examples/poc.py).
|
|
250
|
+
|
|
251
|
+
## Dependencies and licence
|
|
252
|
+
|
|
253
|
+
Seven dependencies, all installable on Windows (pure Python or with wheels):
|
|
254
|
+
|
|
255
|
+
| Package | Used for | Licence |
|
|
256
|
+
| --- | --- | --- |
|
|
257
|
+
| requests | HTTP | Apache-2.0 |
|
|
258
|
+
| paramiko | SSH | LGPL-2.1 |
|
|
259
|
+
| pymysql | MySQL / MariaDB | MIT |
|
|
260
|
+
| psycopg2-binary | PostgreSQL | LGPL (with exception) |
|
|
261
|
+
| pymongo | MongoDB | Apache-2.0 |
|
|
262
|
+
| impacket | SMB / LDAP / MSSQL | Apache 1.1 derivative |
|
|
263
|
+
| cryptoexp | public-key weakness audit | MIT |
|
|
264
|
+
|
|
265
|
+
- No scapy, no nmap, no pyyaml, no GPL code. The SYN scan builds IP/TCP
|
|
266
|
+
itself; PoCs are Python, not YAML.
|
|
267
|
+
- The protocol modules import their drivers lazily, so `import secraft` does not
|
|
268
|
+
pay for all of them.
|
|
269
|
+
- A SYN scan needs raw sockets, so it only runs on Linux as root; everywhere
|
|
270
|
+
else it falls back to a connect scan and says so in the result.
|
|
271
|
+
- secraft itself is MIT.
|
|
272
|
+
|
|
273
|
+
## Known limitations
|
|
274
|
+
|
|
275
|
+
- **SYN scan is Linux + root only.** Raw sockets are not available to plain
|
|
276
|
+
Python on Windows or macOS. On any other platform, or without root, the call
|
|
277
|
+
falls back to a connect scan and `r.engine` reads `connect(fallback)`; with
|
|
278
|
+
`fallback=False` you get a failure naming the reason instead.
|
|
279
|
+
- **One CIDR call covers at most 256 addresses.** Larger ranges are refused
|
|
280
|
+
rather than half-scanned.
|
|
281
|
+
- **Banners are a heuristic.** Services that greet on connect are read
|
|
282
|
+
passively; a silent port is then probed as HTTP, or as TLS on TLS ports. A
|
|
283
|
+
service that waits for a protocol-specific request looks silent, and a banner
|
|
284
|
+
is self-reported — it can be wrong or deliberately fake.
|
|
285
|
+
- **`http_form` judges by response differences.** Status code, body length
|
|
286
|
+
(over 50 bytes) and final URL are compared against one deliberately wrong
|
|
287
|
+
login, plus a list of failure phrases. A site that renders success and
|
|
288
|
+
failure identically will fool it in either direction; confirm hits by hand.
|
|
289
|
+
- **`fuzz` reports differences, not findings.** It sends a few control requests
|
|
290
|
+
(the marker set to a harmless value) to learn what "normal" looks like, then
|
|
291
|
+
flags payloads whose status, size or body falls outside that envelope, and
|
|
292
|
+
says which in `row["why"]`. If the controls disagree with each other (a noisy
|
|
293
|
+
page, a rate limit), body comparison is switched off and `r.reason` says so.
|
|
294
|
+
It does not classify a vulnerability; a real finding that changes nothing in
|
|
295
|
+
status, size or body similarity is missed.
|
|
296
|
+
- **`http_basic` treats any 2xx without credentials as unauthenticated
|
|
297
|
+
access.** That is a probe result, not a proof of what the endpoint does.
|
|
298
|
+
- **The DNS resolver is hand-written.** It covers A, AAAA, NS, CNAME, MX, TXT,
|
|
299
|
+
SOA, SRV and PTR, plus AXFR over TCP. No DNSSEC validation, no DoH/DoT.
|
|
300
|
+
- **`subdomain` is a DNS wordlist run.** Wildcard filtering compares one random
|
|
301
|
+
probe, so a wildcard that rotates addresses still produces noise. CNAME-only
|
|
302
|
+
names and names missing from the wordlist are not found.
|
|
303
|
+
- **Some protocol-specific gaps:** Redis AUTH uses the password only (a Redis 6
|
|
304
|
+
ACL user needs `AUTH user pass`); MySQL 8 `caching_sha2_password` is reported
|
|
305
|
+
as a failure, not a wrong password; the LDAP check is port 389 only; SMB,
|
|
306
|
+
MSSQL and LDAP checks do not do Kerberos or integrated authentication.
|
|
307
|
+
- **There is no pivoting.** No SOCKS proxy, no tunnelling, no lateral movement,
|
|
308
|
+
no session handling. One call is one target.
|
|
309
|
+
- **The log is in memory and keeps the last 2000 calls.** `sec.report()` covers
|
|
310
|
+
this process only; calls your own code makes with requests or socket are not
|
|
311
|
+
in it.
|
|
312
|
+
- **It is not a substitute for nmap, nuclei or hydra.** Service/version
|
|
313
|
+
detection, CVE templates, very large wordlists and protocol breadth are their
|
|
314
|
+
job, not this library's.
|
|
315
|
+
|
|
316
|
+
## Roadmap
|
|
317
|
+
|
|
318
|
+
- VNC (DES challenge) and RDP (NLA) credential checks — the two protocols left
|
|
319
|
+
out so far.
|
|
320
|
+
- Structured export beyond Markdown: `Result.to_dict()` exists, a JSON report
|
|
321
|
+
writer does not.
|
|
322
|
+
- DNSSEC awareness and more record types in `sec.dns`.
|
|
323
|
+
- Pivoting and tunnelling are out of scope for a glue layer; they need a
|
|
324
|
+
different design, not another function.
|
|
325
|
+
|
|
326
|
+
## Status
|
|
327
|
+
|
|
328
|
+
v0.1.0.
|
|
329
|
+
|
|
330
|
+
## Licence
|
|
331
|
+
|
|
332
|
+
MIT © guaidao2
|
secraft-0.1.0/README.md
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
# secraft
|
|
2
|
+
|
|
3
|
+
[中文文档](README.zh-CN.md) · [User guide](docs/guide.md)
|
|
4
|
+
|
|
5
|
+
**secraft simplifies the security workflow.**
|
|
6
|
+
|
|
7
|
+
Port scanning, service banners, web probing, DNS recon, credential checks — each
|
|
8
|
+
is one function call, and every call returns the same `Result` object with three
|
|
9
|
+
clear states: done, done but empty, failed. A one-off script no longer has to
|
|
10
|
+
juggle five libraries and five different ways of deciding whether the thing it
|
|
11
|
+
just did actually worked.
|
|
12
|
+
|
|
13
|
+
It is not a new language like yaklang and not a replacement for nmap, nuclei or
|
|
14
|
+
hydra. It is the glue layer: the common scenarios, each behind a name you can
|
|
15
|
+
remember.
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
import secraft as sec
|
|
19
|
+
|
|
20
|
+
r = sec.portscan("192.168.1.1")
|
|
21
|
+
print(r) # a table you can read
|
|
22
|
+
|
|
23
|
+
if 22 in r.ports:
|
|
24
|
+
sec.ssh("192.168.1.1", user="root", wordlist="pass.txt")
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Use it only on hosts you own or are authorized to test.
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install secraft
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Python 3.10+. Works on Windows, Linux and macOS. There are no extras: HTTP, DNS,
|
|
36
|
+
port scanning, SSH checks and raw packets all ship in the one package.
|
|
37
|
+
|
|
38
|
+
## 30 seconds
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
import secraft as sec
|
|
42
|
+
|
|
43
|
+
# 1. scan ports
|
|
44
|
+
r = sec.portscan("192.168.1.1", ports="1-1024")
|
|
45
|
+
print(r)
|
|
46
|
+
print(r.ports) # [22, 80, 443]
|
|
47
|
+
|
|
48
|
+
# 2. grab banners
|
|
49
|
+
sec.banner("192.168.1.1", ports=r.ports)
|
|
50
|
+
|
|
51
|
+
# 3. send HTTP
|
|
52
|
+
r = sec.http.get("https://example.com")
|
|
53
|
+
print(r.status_code, r.text[:100])
|
|
54
|
+
|
|
55
|
+
# 4. collect subdomains
|
|
56
|
+
sec.subdomain("example.com")
|
|
57
|
+
|
|
58
|
+
# 5. write your own PoC (no YAML to learn)
|
|
59
|
+
r = sec.http.get("http://example.com/index.php?id=1'")
|
|
60
|
+
if "SQL syntax" in r.text:
|
|
61
|
+
print("injection candidate")
|
|
62
|
+
|
|
63
|
+
# 6. wrap up
|
|
64
|
+
print(sec.log()) # what actually ran
|
|
65
|
+
sec.report("report.md") # Markdown you can hand over
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Why the result is not a plain dict
|
|
69
|
+
|
|
70
|
+
Every call returns a `Result` with one of three states:
|
|
71
|
+
|
|
72
|
+
- **done** — finished, and there is a result.
|
|
73
|
+
- **done, empty** — finished, and there really is nothing (host is up, every
|
|
74
|
+
port is closed).
|
|
75
|
+
- **failed** — the library side broke: no permission, no route, a missing
|
|
76
|
+
dependency, a bad argument.
|
|
77
|
+
|
|
78
|
+
Those three lead to different next steps, so they must stay distinguishable.
|
|
79
|
+
`print(r)` tells you which one you are in, why, and what to try next.
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
r.ok / r.found / r.empty / r.failed
|
|
83
|
+
r.data # structured result
|
|
84
|
+
r.raw # the underlying object: requests.Response / bytes / ...
|
|
85
|
+
r.ports # open ports
|
|
86
|
+
22 in r # port membership
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Modules
|
|
90
|
+
|
|
91
|
+
| Name | What it does |
|
|
92
|
+
| --- | --- |
|
|
93
|
+
| `sec.portscan` | TCP connect scan, pure Python, no nmap |
|
|
94
|
+
| `sec.ping` | Host discovery over TCP (open port or RST), no root, no ICMP |
|
|
95
|
+
| `sec.fingerprint` | Parse a banner into product, version and OS |
|
|
96
|
+
| `sec.synscan` | Native SYN half-open scan (Linux + root; falls back to connect elsewhere) |
|
|
97
|
+
| `sec.banner` | Grab the banner of open ports |
|
|
98
|
+
| `sec.http` | HTTP requests (a requests wrapper; `r.raw` is the `Response`) |
|
|
99
|
+
| `sec.web.session` | Persistent session: log in once, cookies and headers carry over |
|
|
100
|
+
| `sec.web.diff` | Compare two responses: status, size, body similarity, and what changed |
|
|
101
|
+
| `sec.Batch` | What a multi-target call returns: `items`, `open_ports[host]`, `counts`, `partial` |
|
|
102
|
+
| `sec.raw` | Send raw HTTP bytes, bypassing requests' normalisation |
|
|
103
|
+
| `sec.fuzz` | Replace one `FUZZ` marker with many payloads and compare each response against a control request |
|
|
104
|
+
| `sec.dns` | Hand-built DNS queries and zone-transfer (AXFR) detection |
|
|
105
|
+
| `sec.subdomain` | Subdomain brute force, with wildcard detection |
|
|
106
|
+
| `sec.ssh` / `sec.ftp` / `sec.smtp` / `sec.pop3` / `sec.imap` / `sec.telnet` / `sec.redis` / `sec.mysql` / `sec.postgres` / `sec.mongodb` / `sec.smb` / `sec.ldap` / `sec.mssql` / `sec.http_basic` / `sec.http_form` | Credential checks; can also be reached through `sec.brute.run("ssh", ...)`. Each accepts a list of hosts and returns a Batch |
|
|
107
|
+
| `sec.crypto` | RSA public-key weakness audit (small modulus, Wiener, shared primes, ...), powered by cryptoexp |
|
|
108
|
+
| `sec.jwt` | Decode, forge `alg=none`, sign and crack HMAC secrets |
|
|
109
|
+
| `sec.csrf` | Turn a captured request into an auto-submitting HTML form |
|
|
110
|
+
| `sec.serve` | Throwaway HTTP server for callbacks and self-tests |
|
|
111
|
+
| `sec.tcp` / `sec.udp` | Raw socket send/recv for services without a client here |
|
|
112
|
+
| `sec.codec` / `sec.text` / `sec.wordlist` | Encoding, text extraction, wordlists |
|
|
113
|
+
| `sec.log` / `sec.report` | Call log and Markdown report |
|
|
114
|
+
|
|
115
|
+
## Sessions, comparison, and many targets
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
with sec.web.session("http://192.168.1.10") as s:
|
|
119
|
+
s.post("/login", data={"user": "admin", "pass": "admin"})
|
|
120
|
+
base = s.get("/item?id=1")
|
|
121
|
+
test = s.get("/item?id=1'")
|
|
122
|
+
print(sec.web.diff(base, test).data) # status, length, similarity, why
|
|
123
|
+
|
|
124
|
+
b = sec.portscan(["192.168.1.1", "192.168.1.2"])
|
|
125
|
+
print(b.open_ports) # {'192.168.1.1': [22, 80]}
|
|
126
|
+
print(b.partial, b.counts) # True {'ok': 1, 'empty': 1, 'error': 0}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
One target returns a `Result`; many targets return a `Batch`. Batch does not
|
|
130
|
+
pretend to be a Result: `b.open_ports[host]` answers "which ports on which
|
|
131
|
+
host", and `"10.0.0.1" in b` asks whether that *target* is in the batch.
|
|
132
|
+
|
|
133
|
+
## A script is also a command
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
# tool.py
|
|
137
|
+
import secraft as sec
|
|
138
|
+
|
|
139
|
+
@sec.cli.command
|
|
140
|
+
def scan(target, ports: str = "", timeout: float = 1.0):
|
|
141
|
+
"""Scan a host for open ports."""
|
|
142
|
+
return sec.portscan(target, ports=ports or None, timeout=timeout)
|
|
143
|
+
|
|
144
|
+
if __name__ == "__main__":
|
|
145
|
+
raise SystemExit(sec.cli.run())
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
`python tool.py scan 10.0.0.5 --ports 1-1024` now works, `--help` comes from
|
|
149
|
+
the signature, `--json` prints the whole Result for `jq`, and the exit code
|
|
150
|
+
follows the three states (0 found, 1 empty, 2 failed). No plugin system, no
|
|
151
|
+
config file: three pieces, the decorator, `run()`, and the output.
|
|
152
|
+
|
|
153
|
+
## Credential checks: one skeleton, fifteen protocols
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
sec.brute.supported()
|
|
157
|
+
# ['ftp', 'http-basic', 'http-form', 'imap', 'ldap', 'mariadb', 'mongo',
|
|
158
|
+
# 'mongodb', 'mssql', 'mysql', 'pop3', 'postgres', 'postgresql', 'redis',
|
|
159
|
+
# 'smb', 'smtp', 'ssh', 'telnet']
|
|
160
|
+
|
|
161
|
+
sec.ssh("10.0.0.5", user="root", wordlist="pass.txt")
|
|
162
|
+
sec.redis("10.0.0.5", wordlist="pass.txt") # also spots "no password set"
|
|
163
|
+
sec.mysql("10.0.0.5", user="root", wordlist="pass.txt")
|
|
164
|
+
sec.brute.run("postgres", "10.0.0.5", user="postgres", passwords=["123456"])
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
The three states are the same everywhere: credentials found is done; tried
|
|
168
|
+
everything and found nothing is done-but-empty; no authentication ever happened
|
|
169
|
+
(protocol mismatch, cannot connect) is failed. A Redis with no password is
|
|
170
|
+
reported as unauthenticated access, never as "no password found".
|
|
171
|
+
|
|
172
|
+
Protocols: ssh, ftp, smtp (including 465/587), pop3, imap, telnet, redis,
|
|
173
|
+
http-basic, http-form, mysql, postgres, mongodb, smb, ldap, mssql.
|
|
174
|
+
|
|
175
|
+
Web, database and SMB checks go through established drivers (requests /
|
|
176
|
+
pymysql / psycopg2 / pymongo / impacket) instead of hand-written wire formats: a
|
|
177
|
+
protocol detail done wrong produces false negatives, and a feature that quietly
|
|
178
|
+
lies is worse than a missing feature.
|
|
179
|
+
|
|
180
|
+
### Concurrency
|
|
181
|
+
|
|
182
|
+
Attempts run in a thread pool. `workers` defaults to 16, the same order of
|
|
183
|
+
magnitude as hydra's `-t`, and every protocol accepts it:
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
sec.ssh("10.0.0.5", user="root", wordlist="pass.txt", workers=32)
|
|
187
|
+
sec.ftp("10.0.0.5", user="admin", wordlist="pass.txt", workers=1) # one at a time
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
`workers=1` is strictly sequential. Higher values are faster but can trip
|
|
191
|
+
account lockout policies or IDS: that trade-off is yours to make, so it is a
|
|
192
|
+
parameter rather than a hidden decision. `delay` (minimum seconds between
|
|
193
|
+
attempt starts, applied globally) and
|
|
194
|
+
`max_tries` (stop after N pairs) are the other two knobs.
|
|
195
|
+
|
|
196
|
+
VNC (needs the DES challenge) and RDP (NLA) are not implemented.
|
|
197
|
+
|
|
198
|
+
## PoC without YAML
|
|
199
|
+
|
|
200
|
+
nuclei's template syntax exists to serve its command line. Inside a script,
|
|
201
|
+
deciding whether a bug is there is normally three lines:
|
|
202
|
+
|
|
203
|
+
```python
|
|
204
|
+
def thinkphp_rce(url):
|
|
205
|
+
# Raw string on purpose: in a normal string, \t becomes a tab character
|
|
206
|
+
payload = (
|
|
207
|
+
r"/index.php?s=/Index/\think\app/invokefunction"
|
|
208
|
+
"&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=1"
|
|
209
|
+
)
|
|
210
|
+
r = sec.http.get(url.rstrip("/") + payload)
|
|
211
|
+
return r.ok and "PHP Version" in r.text
|
|
212
|
+
|
|
213
|
+
if thinkphp_rce("http://example.com"):
|
|
214
|
+
print("it fired")
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
For malformed packets and raw messages, use `sec.raw`:
|
|
218
|
+
|
|
219
|
+
```python
|
|
220
|
+
def redis_unauth(host, port=6379):
|
|
221
|
+
r = sec.raw.send(host, port, b"PING\r\n")
|
|
222
|
+
return r.ok and "+PONG" in r.text
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
That is freer than YAML and easier to debug: a mistake is a Python traceback
|
|
226
|
+
with a line number. More examples in [examples/poc.py](examples/poc.py).
|
|
227
|
+
|
|
228
|
+
## Dependencies and licence
|
|
229
|
+
|
|
230
|
+
Seven dependencies, all installable on Windows (pure Python or with wheels):
|
|
231
|
+
|
|
232
|
+
| Package | Used for | Licence |
|
|
233
|
+
| --- | --- | --- |
|
|
234
|
+
| requests | HTTP | Apache-2.0 |
|
|
235
|
+
| paramiko | SSH | LGPL-2.1 |
|
|
236
|
+
| pymysql | MySQL / MariaDB | MIT |
|
|
237
|
+
| psycopg2-binary | PostgreSQL | LGPL (with exception) |
|
|
238
|
+
| pymongo | MongoDB | Apache-2.0 |
|
|
239
|
+
| impacket | SMB / LDAP / MSSQL | Apache 1.1 derivative |
|
|
240
|
+
| cryptoexp | public-key weakness audit | MIT |
|
|
241
|
+
|
|
242
|
+
- No scapy, no nmap, no pyyaml, no GPL code. The SYN scan builds IP/TCP
|
|
243
|
+
itself; PoCs are Python, not YAML.
|
|
244
|
+
- The protocol modules import their drivers lazily, so `import secraft` does not
|
|
245
|
+
pay for all of them.
|
|
246
|
+
- A SYN scan needs raw sockets, so it only runs on Linux as root; everywhere
|
|
247
|
+
else it falls back to a connect scan and says so in the result.
|
|
248
|
+
- secraft itself is MIT.
|
|
249
|
+
|
|
250
|
+
## Known limitations
|
|
251
|
+
|
|
252
|
+
- **SYN scan is Linux + root only.** Raw sockets are not available to plain
|
|
253
|
+
Python on Windows or macOS. On any other platform, or without root, the call
|
|
254
|
+
falls back to a connect scan and `r.engine` reads `connect(fallback)`; with
|
|
255
|
+
`fallback=False` you get a failure naming the reason instead.
|
|
256
|
+
- **One CIDR call covers at most 256 addresses.** Larger ranges are refused
|
|
257
|
+
rather than half-scanned.
|
|
258
|
+
- **Banners are a heuristic.** Services that greet on connect are read
|
|
259
|
+
passively; a silent port is then probed as HTTP, or as TLS on TLS ports. A
|
|
260
|
+
service that waits for a protocol-specific request looks silent, and a banner
|
|
261
|
+
is self-reported — it can be wrong or deliberately fake.
|
|
262
|
+
- **`http_form` judges by response differences.** Status code, body length
|
|
263
|
+
(over 50 bytes) and final URL are compared against one deliberately wrong
|
|
264
|
+
login, plus a list of failure phrases. A site that renders success and
|
|
265
|
+
failure identically will fool it in either direction; confirm hits by hand.
|
|
266
|
+
- **`fuzz` reports differences, not findings.** It sends a few control requests
|
|
267
|
+
(the marker set to a harmless value) to learn what "normal" looks like, then
|
|
268
|
+
flags payloads whose status, size or body falls outside that envelope, and
|
|
269
|
+
says which in `row["why"]`. If the controls disagree with each other (a noisy
|
|
270
|
+
page, a rate limit), body comparison is switched off and `r.reason` says so.
|
|
271
|
+
It does not classify a vulnerability; a real finding that changes nothing in
|
|
272
|
+
status, size or body similarity is missed.
|
|
273
|
+
- **`http_basic` treats any 2xx without credentials as unauthenticated
|
|
274
|
+
access.** That is a probe result, not a proof of what the endpoint does.
|
|
275
|
+
- **The DNS resolver is hand-written.** It covers A, AAAA, NS, CNAME, MX, TXT,
|
|
276
|
+
SOA, SRV and PTR, plus AXFR over TCP. No DNSSEC validation, no DoH/DoT.
|
|
277
|
+
- **`subdomain` is a DNS wordlist run.** Wildcard filtering compares one random
|
|
278
|
+
probe, so a wildcard that rotates addresses still produces noise. CNAME-only
|
|
279
|
+
names and names missing from the wordlist are not found.
|
|
280
|
+
- **Some protocol-specific gaps:** Redis AUTH uses the password only (a Redis 6
|
|
281
|
+
ACL user needs `AUTH user pass`); MySQL 8 `caching_sha2_password` is reported
|
|
282
|
+
as a failure, not a wrong password; the LDAP check is port 389 only; SMB,
|
|
283
|
+
MSSQL and LDAP checks do not do Kerberos or integrated authentication.
|
|
284
|
+
- **There is no pivoting.** No SOCKS proxy, no tunnelling, no lateral movement,
|
|
285
|
+
no session handling. One call is one target.
|
|
286
|
+
- **The log is in memory and keeps the last 2000 calls.** `sec.report()` covers
|
|
287
|
+
this process only; calls your own code makes with requests or socket are not
|
|
288
|
+
in it.
|
|
289
|
+
- **It is not a substitute for nmap, nuclei or hydra.** Service/version
|
|
290
|
+
detection, CVE templates, very large wordlists and protocol breadth are their
|
|
291
|
+
job, not this library's.
|
|
292
|
+
|
|
293
|
+
## Roadmap
|
|
294
|
+
|
|
295
|
+
- VNC (DES challenge) and RDP (NLA) credential checks — the two protocols left
|
|
296
|
+
out so far.
|
|
297
|
+
- Structured export beyond Markdown: `Result.to_dict()` exists, a JSON report
|
|
298
|
+
writer does not.
|
|
299
|
+
- DNSSEC awareness and more record types in `sec.dns`.
|
|
300
|
+
- Pivoting and tunnelling are out of scope for a glue layer; they need a
|
|
301
|
+
different design, not another function.
|
|
302
|
+
|
|
303
|
+
## Status
|
|
304
|
+
|
|
305
|
+
v0.1.0.
|
|
306
|
+
|
|
307
|
+
## Licence
|
|
308
|
+
|
|
309
|
+
MIT © guaidao2
|