NetworkおよびWebの基礎(?) - TK-CTF/CTF GitHub Wiki
Webはsoftより(?)
Networkはhardより(?)
Tool
- OWASP ZAP
Reference
代表例
- Protocol: HTTP
- Language: JavaScript PHP
- Format: ASCII JPEG
- Server: nginx Apache
- OS: Linux Windows
OSI参照モデル
各層ごとにHeaderやMetadataを付与する.
階層とその例
- Application Layer..Front-End
- HTTP
- DNS
- Presentation Layer..Cryptography/Format
- ASCII
- JPEG
- Session Layer..CommunicationControl/Start&End
- Transport Layer..ReliabilityAssurance/ErrorHandling
- TCP
- UDP
- Network Layer..AddressResolution
- IPv4
- IPv6
- Data Link Layer..?
- Physical Layer..Back-End
TCP/IPモデル
プロトコル
通信で用いられる共通言語
- TCP
- IP
トラフィック
通信の対象
- ブロードキャスト(->all)
- マルチキャスト(->some)
- ユニキャスト(->one)
IP Address
- ソケットに割り当てられる
- 32 bitのアドレス
- 8 bit毎に
.
で区切られる - サブネットマスクで分割される
1
がグローバルIPアドレス0
がプライベートIPアドレス
Port
- ソケットに割り当てられる
Port | Service |
---|---|
20 | ftp-data |
21 | ftp |
22 | ssh |
23 | telnet |
80 | http |
443 | https |
HTTP
状態を持たない通信を行うためのプロトコル
注目すべきヘッダ
- Content-Type
- Host
- Set-Cookie
- Cookie
HTTPリクエスト
サイトからサーバーへ送られるデータで
- リクエストライン
- ヘッダ
- 空行
- ボディ
がこの順に含まれる
リクエストライン
GET /31/31-001.php HTTP/1.1
- メソッド
GET
- URL(URI)
/31/31-001.php
- プロトコルバージョン
HTTP/1.1
以下のメソッドはよく使われる
- GET
- POST
- HEAD
- (TRACE)
HTTPレスポンス
サーバーからサイトへ送られるデータで
- レスポンスライン
- ヘッダ
- 空行
- ボディ
がこの順に含まれる
レスポンスライン
HTTP/1.1 200 OK
- プロトコルバージョン
HTTP/1.1
- ステータスコード
200
- テキストフレーズ
OK
以下のステータスコードはよく使われる
- 200 OK
- 301 Moved Permanently
- 302 Found
- 404 Not Found
- 500 Internal Server Error
hiddenパラメータ
Cookie
SessionIDや一時データをブラウザ側が保存する機能
認証したタイミングでSessionIDを変更することでID固定化攻撃を対策できる
受動的攻撃
Same Origin Policy
クライアントスクリプトからまたがったアクセスを以下の条件を満たす場合に制限する
- URLのホスト(FQDN:Fully Qualified Domain Name)が一致している
- スキーム(プロトコル)が一致している
- ポート番号が一致している
以下のものではまたがったアクセスを許可されている
- frame/iframe要素
- img要素
- script要素(JSONP)
- CSS(InternetExplorer)
- form要素のaction属性
Cross-Origin Resource Sharing(CORS)
XMLHttpRequestを用いて異なるオリジンに相手側の許可なしに送るHTTPリクエストに以下の条件を課す
- メソッドはGET/HEAD/POSTのいずれか
- XMLHttpRequestオブジェクトのsetRequestHeaderメソッドで設定するリクエストヘッダは以下のいずれか
- Accept
- Accept-Language
- Content-Language
- Content-Type
- Content-Typeヘッダは以下のいずれか
application/x-www-form-urlencoded
multipart/form-data
text/plain
条件を満たさない場合、(相手側の許可を得て)プリフライトリクエストを送る必要がある
認証情報を含むリクエストの場合、さらに以下の条件を課す
- XMLHttpRequestオブジェクトのwithCredentialsプロパティがtrue
- レスポンスヘッダとしてAcess-Control-Arrow-Credentials:trueを返す
入力処理
- encodingを検証
- encodingを変換
- 入力値検証(regexp, range)
a
Null Byte Injection
文字列の終端を示す\00
を混入させる手法
以下はバイナリセーフでない関数
- a
ステータスコード一覧
1xx | Informational | 2xx | Success | 3xx | Redirection |
---|---|---|---|---|---|
100 | Continue | 200 | OK | 300 | Multiple Choices |
101 | Switching Protocols | 201 | Created | 301 | Moved Permanently |
102 | Processing | 202 | Accepted | 302 | Found |
103 | Early Hints | 203 | Non-Authoritative Information | 303 | See Other |
204 | No Content | 304 | Not Modified | ||
205 | Reset Content | 305 | Use Proxy | ||
206 | Partial Content | 307 | Temporary Redirect | ||
207 | Multi-Status | 308 | Permanent Redirect | ||
208 | Already Reported | ||||
226 | IM Used | ||||
4xx | Client Error | 5xx | Server Error | ||
400 | Bad Request | 500 | Internal Server Error | ||
401 | Unauthorized | 501 | Not Implemented | ||
402 | Payment Required | 502 | Bad Gateway | ||
403 | Forbidden | 503 | Service Unavailable | ||
404 | Not Found | 504 | Gateway Timeout | ||
405 | Method Not Allowed | 505 | HTTP Version Not Supported | ||
406 | Not Acceptable | 506 | Variant Also Negotiates | ||
407 | Proxy Authentication Required | 507 | Insufficient Storage | ||
408 | Request Timeout | 508 | Loop Detected | ||
409 | Conflict | 509 | Bandwidth Limit Exceeded | ||
410 | Gone | 510 | Not Extended | ||
411 | Length Required | 511 | Network Authentication Required | ||
412 | Precondition Failed | ||||
413 | Payload Too Large | ||||
414 | URI Too Long | ||||
415 | Unsupported Media Type | ||||
416 | Range Not Satisfiable | ||||
417 | Expectation Failed | ||||
421 | Misdirected Request | ||||
422 | Unprocessable Entity | ||||
423 | Locked | ||||
424 | Failed Dependency | ||||
425 | Too Early | ||||
426 | Upgrade Required | ||||
428 | Precondition Required | ||||
429 | Too Many Requests | ||||
431 | Request Header Fields Too Large | ||||
451 | Unavailable For Legal Reasons |