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....

<span title='2019-10-12 00:00:00 +0000 UTC'>October 12, 2019</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;202 words&nbsp;·&nbsp;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:...

<span title='2019-10-12 00:00:00 +0000 UTC'>October 12, 2019</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;174 words&nbsp;·&nbsp;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 基礎的なディスアセンブラを実装したり、テイント解析やシンボリック実行をやったりと、今からリバースエンジニアリングをするなら抑えておきたい点を実装して手を動かしながら体系的に学ぶことができる。...

<span title='2019-10-12 00:00:00 +0000 UTC'>October 12, 2019</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;346 words&nbsp;·&nbsp;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 Calls the free() but does not store null pointer(Maybe can use Use After Free) PrintNote Execute the value received from the heap as a function....

<span title='2019-10-12 00:00:00 +0000 UTC'>October 12, 2019</span>&nbsp;·&nbsp;6 min&nbsp;·&nbsp;1158 words&nbsp;·&nbsp;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....

<span title='2019-10-12 00:00:00 +0000 UTC'>October 12, 2019</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;258 words&nbsp;·&nbsp;FAMASoon

pwnable.tw start writeup

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 $ gdb --version GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1 Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details....

<span title='2019-10-12 00:00:00 +0000 UTC'>October 12, 2019</span>&nbsp;·&nbsp;4 min&nbsp;·&nbsp;808 words&nbsp;·&nbsp;FAMASoon

Tor Hidden Service でウェブサイトを公開してみる

まえがき ダークウェブについて という記事を読んだ。 内容はダークウェブ、主にTor Hidden Service(以下 “HS”)に的を絞って解説しているものだ。 HSについては先の記事でも書かれているようにTor Bundle Browserを用いれば簡単にアクセスが可能。 有名なHSはFacebookやThe New York Timesが挙げられる。 さて、そんなHSだがアクセスするだけでなくサイトの開設も簡単だったりする。 自分でサーバをたててサイトを開いたことがあれば誰でもできるような内容だ。 早速やってみるとしよう。 環境 $ uname -a Linux instance-2 4.10.0-40-generic #44~16.04.1-Ubuntu SMP Thu Nov 9 15:37:44 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04.3 LTS Release: 16.04 Codename: xenial Tor のセッティング 何はともあれ Tor をインストールしなければ始まらない。 Ubuntu 16.04 では apt で簡単にインストールできる。 $ sudo apt install tor $ sudo systemctl start tor Tor 公式ドキュメントである https://www....

<span title='2019-10-12 00:00:00 +0000 UTC'>October 12, 2019</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;150 words&nbsp;·&nbsp;FAMASoon

windbgとVirtualBox を用いた Windows カーネルデバッグ

シリアルポート経由でカーネルデバッグした時に実施した手順です。 VM側のWindowsで実施する手順 Windows上で管理者権限でPowershellを起動 下記コマンドを入力 bcdedit /debug on bcdedit /dbgsettings serial debugport:1 baudrate:115200 Windowsをシャットダウン ホスト側のWinodwsで実施する手順 VirtualBoxでVMの設定を開き下記の画像のように設定 “シリアルポートを有効化"にチェックを入れる “ポートモード"を"ホストにパイプ"にする “パス/アドレス"を”\.\pipe\com1"にする VMを起動する ストア からWinDbg Previewをインストールする(なぜか自分の環境ではWDKのWinDbgだとカーネルでバッグをしようにも"debuggee not connected"と表示され使えなかったためWinDbg Previewを使う) WinDbg Preview を開いたら"ファイル"タブから"Attach to kernel"を選択し下記設定をする “Pipe"にチェックを入れる “Reconnect"にチェックを入れる “Port"を”\.\pipe\com1"にする VMを起動 これでカーネルでバッグが実施可能になる。

<span title='2019-10-12 00:00:00 +0000 UTC'>October 12, 2019</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;35 words&nbsp;·&nbsp;FAMASoon