Create Binary Analysis VM

Create Binary Analysis VM I created VM for reverse engineering. This is the note at that time. Install Virtual Box To run VMs needs hypervisor. I choose the Virtual Box. Because, Virtual Box is easy to use and free. To install Virtual Box navigate to the this page. https://www.virtualbox.org/wiki/Downloads You choose the package for your system, and download it. Run the installer. If you are using the mac OS, you can install with this command too. ...

October 12, 2019 · 2 min · 244 words · FAMASoon

Create Binary Analysis VM

Create Binary Analysis VM I created VM for reverse engineering. This is the note at that time. Install Virtual Box To run VMs needs hypervisor. I choose the Virtual Box. Because, Virtual Box is easy to use and free. To install Virtual Box navigate to the this page. https://www.virtualbox.org/wiki/Downloads You choose the package for your system, and download it. Run the installer. If you are using the mac OS, you can install with this command too. ...

October 12, 2019 · 2 min · 244 words · FAMASoon

Finding IRP dispatch routine

Environment Windows 10 In VM Attached Windbg How to finding First, show deviceobject structures kd> !drvobj DeviceObj 7 Driver object (ffffa3828a49b060) is for: \Driver\DeviceObj Driver Extension List: (id , addr) Device Object list: ffffa3828c2869f0 DriverEntry: fffff80043a55064 DeviceObj DriverStartIo: 00000000 DriverUnload: fffff800439d1950 DeviceObj AddDevice: 00000000 Dispatch routines: [00] IRP_MJ_CREATE fffff800439d4ff0 DeviceObj+0x4ff0 [01] IRP_MJ_CREATE_NAMED_PIPE fffff800439d4ff0 DeviceObj+0x4ff0 [02] IRP_MJ_CLOSE fffff800439d4ff0 DeviceObj+0x4ff0 [03] IRP_MJ_READ fffff800439d4ff0 DeviceObj+0x4ff0 [04] IRP_MJ_WRITE fffff800439d4ff0 DeviceObj+0x4ff0 [05] IRP_MJ_QUERY_INFORMATION fffff800439d4ff0 DeviceObj+0x4ff0 [06] IRP_MJ_SET_INFORMATION fffff800439d4ff0 DeviceObj+0x4ff0 [07] IRP_MJ_QUERY_EA fffff800439d4ff0 DeviceObj+0x4ff0 [08] IRP_MJ_SET_EA fffff800439d4ff0 DeviceObj+0x4ff0 [09] IRP_MJ_FLUSH_BUFFERS fffff800439d4ff0 DeviceObj+0x4ff0 [0a] IRP_MJ_QUERY_VOLUME_INFORMATION fffff800439d4ff0 DeviceObj+0x4ff0 [0b] IRP_MJ_SET_VOLUME_INFORMATION fffff800439d4ff0 DeviceObj+0x4ff0 [0c] IRP_MJ_DIRECTORY_CONTROL fffff800439d4ff0 DeviceObj+0x4ff0 [0d] IRP_MJ_FILE_SYSTEM_CONTROL fffff800439d4ff0 DeviceObj+0x4ff0 [0e] IRP_MJ_DEVICE_CONTROL fffff800439d5020 DeviceObj+0x5020 [0f] IRP_MJ_INTERNAL_DEVICE_CONTROL fffff800439d4ff0 DeviceObj+0x4ff0 [10] IRP_MJ_SHUTDOWN fffff800439d4ff0 DeviceObj+0x4ff0 [11] IRP_MJ_LOCK_CONTROL fffff800439d4ff0 DeviceObj+0x4ff0 [12] IRP_MJ_CLEANUP fffff800439d4ff0 DeviceObj+0x4ff0 [13] IRP_MJ_CREATE_MAILSLOT fffff800439d4ff0 DeviceObj+0x4ff0 [14] IRP_MJ_QUERY_SECURITY fffff800439d4ff0 DeviceObj+0x4ff0 [15] IRP_MJ_SET_SECURITY fffff800439d4ff0 DeviceObj+0x4ff0 [16] IRP_MJ_POWER fffff800439d4ff0 DeviceObj+0x4ff0 [17] IRP_MJ_SYSTEM_CONTROL fffff800439d4ff0 DeviceObj+0x4ff0 [18] IRP_MJ_DEVICE_CHANGE fffff800439d4ff0 DeviceObj+0x4ff0 [19] IRP_MJ_QUERY_QUOTA fffff800439d4ff0 DeviceObj+0x4ff0 [1a] IRP_MJ_SET_QUOTA fffff800439d4ff0 DeviceObj+0x4ff0 [1b] IRP_MJ_PNP fffff800463238f0 nt!IopInvalidDeviceRequest Device Object stacks: !devstack ffffa3828c2869f0 : !DevObj !DrvObj !DevExt ObjectName > ffffa3828c2869f0 \Driver\DeviceObj 00000000 DeviceObj IRP_MJ_DEVICE_CONTROL is IRP_Dispatch_Routine. IRP_MJ_DEVICE_CONTROL is _IO_STACK_LOCATION IOCTL dispatch routine defined in the follow structre. ...

October 12, 2019 · 8 min · 1553 words · FAMASoon

Golang + Nuxt.js + Kubernetes でWebサービスを作る

Golang でAPIサーバを作る Golang + Nuxt.js + Kubernetes でWebサービスを作るシリーズ第一弾。 まずはGolangでシンプルなAPIサーバを作成してみる。 今回はGETリクエストで渡されたドメインのwhois情報を取得するAPIサーバを書く。 APIサーバのソースコードはGitHubにアップロード済み https://github.com/famasoon/webapp-api まずは適当なディレクトリを作る。 mkdir webapp-api cd webapp-api 次にGoの依存関係を初期化。 GO111MODULE=on go mod init 今回はGo言語のEchoというモジュールでHTTPリクエストを、gowhoisでwhois関連の処理を行う。 必要なモジュールをgo getで取得。 go get github.com/labstack/echo/... go get -u github.com/famasoon/gowhois 下記のmain.goでAPIサーバを書く。 package main import ( "net/http" "github.com/famasoon/gowhois/whois" "github.com/labstack/echo" ) type whoisInfo struct { Domain string `json:"domain"` WhoisResult string `json:"result"` } func main() { e := echo.New() e.GET("/", func(c echo.Context) error { return c.String(http.StatusOK, "OK") }) e.GET("/api/v1/whois/:domain", getWhoisResult) e.Logger.Fatal(e.Start(":8080")) } func getWhoisResult(c echo.Context) error { domain := c.Param("domain") result, err := whois.Whois(domain) if err != nil { return err } return c.JSON(http.StatusOK, whoisInfo{ Domain: domain, WhoisResult: result, }) } APIサーバは本番環境と開発環境を一つのDockerfileで書く。 下記記事を参考にマルチステージ対応のDockerfileを書いた https://qiita.com/po3rin/items/8b57e6c22f2b34751333 ...

October 12, 2019 · 6 min · 1250 words · FAMASoon

Ingressのヘルスチェックに対応する

tl;dr “/“パスへのHTTPリクエストに対し200ステータスを返すように実装すればよい Ingress のヘルスチェック GKEでIngressを使っていた所ヘルスチェックをうまく通過しない。 色々と調べたところIngressのヘルスチェックはreadinessProbe.httpGetを指定しないと、デフォルトでは”/“パスにHTTP GETリクエストを送信し200ステータスが帰ってこない場合は対象ポッドが動作していないとみなすみたい。 https://github.com/kubernetes/ingress-gce/issues/42 readinessProbe.httpGetを指定しても別に良かったが、”/“パスは使っていないし、どうせヘルスチェック用にyamlを書き足しAPIのエンドポイントを作るのだったら、”/“へのリクエストに200返すようなコードを書いておけばいいだろうと思い、下記のGolangコードをエンドポイントに追加して対応した。 package main import ( "net/http" "github.com/labstack/echo" "github.com/labstack/echo/middleware" ) func main() { e := echo.New() e.Use(middleware.Logger()) e.Use(middleware.Recover()) e.GET("/", func(c echo.Context) error { return c.String(http.StatusOK, "OK") }) e.Logger.Fatal(e.Start(":8080")) } 参考 Ingressというよりk8sの話だが、ヘルスチェックについては下記ドキュメントが参考になった https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/ https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/

October 12, 2019 · 1 min · 40 words · FAMASoon

LeetCode TwoSum をテストしながら解く

LeetCodeという競技プログラミングサービスがある。 まだ始めたばかりなのだがとっつきやすい作りになっていて良い。 そんなLeetCodeの問題 TwoSum を解いてみた。 ただ解いてみたというのも面白くないので今回はテストコードも書きながら解答してみる。 TwoSum 問題はへのリンク https://leetcode.com/problems/two-sum/。 問いは下記の通り。 数値の入った配列と整数値targetが与えられるので、配列の中から足すとtargetになる値の組み合わせを見つけ、その要素がどこにあるかを答えよ。 必ず答えは存在するものとする。 また別々の位置の値を必ず使用する事 以下に例を書く Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1]. テストコードを書く コードを弄ってブラウザ上でテストしても問題はないが遅い。 なので今回は手元ですぐに動作するテストコードを書いた。 package twosum import ( "reflect" "testing" ) type testCase struct { array []int target int } func TestTwoSum(t *testing.T) { tests := []struct { input testCase output []int }{ {testCase{[]int{2, 7, 11, 15}, 9}, []int{0, 1}}, {testCase{[]int{2, 3, 4, 11, 15}, 6}, []int{0, 2}}, } for i, tt := range tests { sum := twoSum(tt.input.array, tt.input.target) if !reflect.DeepEqual(sum, tt.output) { t.Errorf("tests[%d] failed - input: %+v - answer: %+v output: %d¥n", i, tt.input.array, tt.output, sum) } } } $GOPATH/src/leetcode/twosum/か何か適当なディレクトリでこれを書きgo test ./twosums/と入力すればお手軽テスト環境の完成。 ...

October 12, 2019 · 1 min · 202 words · FAMASoon

List up populer Tor hidden service with Tor2Web

TL;DR: Access to https://tor2web.tld/antanistaticmap/stats/yesterday, you can collect Tor Hidden services URLs that has tor2web users accessed. There is a thing called Tor Hidden Service that can publish service anonymously. I have written an article in Japanese about how to publish Tor Hidden Service. The Tor Hidden Service can not be accessed from a clear network, but can easily be accessed using a proxy called Tor2Web. Tor2Web The famous Tor2web example: https://tor2web.io/ https://onion.to Tor2web records how much access has been made to which Tor Hidden Service and publishes it. Source This record can be easily obtained by sending an HTTP Get request to “Tor2web’s domain” + “/antanistaticmap/stats/yesterday”. ...

October 12, 2019 · 1 min · 174 words · FAMASoon

Practical Binary Analysisの演習用環境をDockerで作った

三行で Practical Binary Analysis はリバースエンジニアリング入門にはうってつけの本 基本的な演習環境はVMで配布されている Dockerで環境を作るときはバージョンを指定しよう 概要 Practical Binary Analysisはモダンなバイナリ解析について学ぶことができる本。 目次は下記の通り。 Chapter 1: Anatomy of a Binary Chapter 2: The ELF Format Chapter 3: The PE Format: A Brief Introduction Chapter 4: Building a Binary Loader Using libbfd Part II: Binary Analysis Fundamentals Chapter 5: Basic Binary Analysis In Linux Chapter 6: Disassembly and Binary Analysis Fundamentals Chapter 7: Simple Code Injection Techniques for ELF Part III: Advanced Binary Analysis Chapter 8: Customizing Disassembly Chapter 9: Binary Instrumentation Chapter 10: Principles of Dynamic Taint Analysis Chapter 11: Practical Dynamic Taint Analysis with libdft Chapter 12: Principles of Symbolic Execution Chapter 13: Practical Symbolic Execution with Triton Part IV: Appendices Appendix A: A Crash Course on x86 Assembly Appendix B: Implementing PT_NOTE Overwriting Using libelf Appendix C: List of Binary Analysis Tools Appendix D: Further Reading 基礎的なディスアセンブラを実装したり、テイント解析やシンボリック実行をやったりと、今からリバースエンジニアリングをするなら抑えておきたい点を実装して手を動かしながら体系的に学ぶことができる。 ...

October 12, 2019 · 2 min · 346 words · FAMASoon

pwnable.tw hacknote writeup

A good Hacker should always take good notes! nc chall.pwnable.tw 10102 Environment $ uname -a Linux base-debootstrap 4.4.0-159-generic #187-Ubuntu SMP Thu Aug 1 16:28:06 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux Check binary security pwndbg> checksec [*] '/home/vagrant/work/pwnabletw/hacknote/hacknote' Arch: i386-32-little RELRO: Partial RELRO Stack: Canary found NX: NX enabled PIE: No PIE (0x8048000) Findings First, I decompiled some functions using Ghidra. Main routine. AddNote function malloc is called in units of 8 bytes(This chunk is managed by fastbins) DeleteNote ...

October 12, 2019 · 6 min · 1158 words · FAMASoon

pwnable.tw orw Writeup

Read the flag from /home/orw/flag. Only open read write syscall are allowed to use. Environment $ uname -a Linux base-debootstrap 4.4.0-159-generic #187-Ubuntu SMP Thu Aug 1 16:28:06 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux Findings This file is 32bit ELF file. $ file ./orw ./orw: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-, for GNU/Linux 2.6.32, BuildID[sha1]=e60ecccd9d01c8217387e8b77e9261a1f36b5030, not stripped Disassemble result. This file read shellcode and execute it, but since seccomp is used, system calls other than open, read, and write cannot be used. So we need write shellcode that only used open, read, and write. ...

October 12, 2019 · 2 min · 258 words · FAMASoon