roy4801
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
      • No invitee
    • Publish Note

      Publish Note

      Everyone on the web can find and read all notes of this public team.
      Once published, notes can be searched and viewed by anyone online.
      See published notes
      Please check the box to agree to the Community Guidelines.
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
No invitee
Publish Note

Publish Note

Everyone on the web can find and read all notes of this public team.
Once published, notes can be searched and viewed by anyone online.
See published notes
Please check the box to agree to the Community Guidelines.
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
--- title: 網站應用程式安全 王凱慶 --- # 網站應用程式安全 王凱慶 ###### tags: `筆記` `ais3` `2019` [toc] ## 服務探索 * IP範圍探索 * nmap * port、服務、版本 * IP列舉(慢) * AWS * https://ip-ranges.amazonaws.com/ip-ranges.json * GCP * https://cloud.google.com/compute/docs/faq#where_ca * Azure * https://www.microsoft.com/en-us/download/details.aspx?id=41653 * 網域 // TODO * 搜尋引擎 * Google * Bing * Yahoo * 百度 * Yandex * [crt.sh](https://crt.sh/) * 證書透明度查詢,僅有效憑證資訊 * [VirtusTotal](https://www.virustotal.com/gui/), [SecurityTrails](https://securitytrails.com/), [DNSTable](https://dnstable.com/) * 紀錄曾經解析過的網域,分析網域過往行為 * [dnsdumpster.com](https://dnsdumpster.com/) * DNS資訊關聯圖,分析DNS紀錄 * [Censys](https://censys.io/), [Shodan](https://www.shodan.io/), [zoomeye](https://www.zoomeye.org/) * 搜尋網路主機資訊 * 暴力列舉 * Sublist3r * bj4 * Content Security Policy * 指定網站資源的有效域,用於抵禦XSS攻擊,但被列在上頭的網域就代表和目標有關係 ## 弱點掃描 * 主機弱掃 * Nessus * nexpose * OpenVAS * 網頁弱掃 * Acunetix * AppScan * WebInspect ## 弱點驗證 * 是否為誤判 * 評估衝擊 --- ## EC2 這個session講者主要講EC2的細節和可能的問題,雲端和一般主機有相同風險,但除了這些之外,還可能有來源疑慮(AMI Market),以及雲端環境與一般環境不同的機制。 > AMI - Amazon Machine Image > AMI 封裝方式:主系統(加密)、儲存區 雲端主機部署通常是大量的,那要怎麼設定主機?EC2是在每個instance上跑[`cloud-init`](https://cloudinit.readthedocs.io/en/latest/index.html)從metadata service獲取設定並設定該主機。而[metadata service](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html#instancedata-data-retrieval)就可能給入侵者透露某些重要資訊。眾多雲端服務提供商皆是以此種形式設定Instance * Metadata Service * hostname, host-ID, host IP * Network Information * SSH public key * startup script * Security Credentials 如果要存取Metadata Service,通常要在該容器裡存取某特定IP位置,以獲取metadata: * AWS/GCP/Azure/Digital Ocean/Helion/Open Stack * `169.254.169.254` * Oracle * `192.0.0.192` * Alibaba * `100.100.100.200` 除了GCP之外,其他的存取方式都差不多 * `http://169.254.169.254/latest/meta-data/` * `http://169.254.169.254/latest/user-data` * `http://169.254.169.254/latest/meta-data/iam/security-credentials/` * `http://169.254.169.254/latest/meta-data/identity-credentials/` GCP存取metadata要設定header,感覺稍微增加了一點複雜度(? 設定header`X-Google-Metadata-Request: True`訪問`http://169.254.169.254/computeMetadata/v1/`;但奇怪的事竟然存在不用設定header也能訪問的:`http://metadata.google.internal/computeMetadata/v1beta1/` 從metadata可以拿到特定RoleName的敏感內容:`http://169.254.169.254/latest/meta-data/iam/security-credentials/RoleName` ![](https://i.imgur.com/pHJoJYc.png) 上頭的RoleName其實是IAM Role,而IAM(Identity and Access Management)是AWS用於管理服務、資源存取的權限,可以建立使用者、群組來管理存取AWS的權限 ![](https://i.imgur.com/LkG5KVv.png) ![](https://i.imgur.com/IdligQg.png) 可以發現從metadata可以拿到特定role的`AccessKeyId`, `SecretAccessKey`跟`Token`,我們的目的就是要拿到metadata中的敏感資料。可以利用以下手法拿取: * get shell直接拿 * command injection (跟上一項差不多) * SSRF --- ## SSRF 接下來講者說根據pre-exam的情況,他詳細介紹SSRF的細節:攻擊面、成因。 ![](https://i.imgur.com/rOB9BBK.png) ![](https://i.imgur.com/X8sfdLg.png) * SSRF (Server-Side Request Forgery) * 攻擊者構造payload使得服務端發起請求,目的在於存取服務端的內網 * 攻擊面 * 探索內部服務(port scan) * 攻擊內部服務(struct2, redis, ElasticSearch) * 讀取檔案(/etc/passwd) * 辨別服務框架/架構(Banner) * 什麼地方會有SSRF? * 能發起網路請求的地方 * 呼叫其他服務 * 請求遠端資源(下載、快取...) * 服務內建功能(Oracle, MSSQL, CouchDB...) * 文件處理(ffmpeg, ImageMagick, doc, xlsx, pdf, xml) * 其他漏洞利用(command injection, SQLi, XSS, SSTI) * 保護繞過 * 302 redirect * `Location: scheme://IP:Port/Path` * IP變形 * `127.1` * `127.0x0.0x00.1` * `2130706433` decimal * `[::]` * `0000::1` * 網域解析 * [nip.io](https://nip.io/) * [xip.io](http://xip.io/) * DNS rebind * `A.1.1.1.1.1time.127.0.0.1.1times.repeat.rebind.network` <== 這是一串網址 * https://github.com/brannondorsey/whonow ``` <?php $domain='xxx.com'; // 1.1.1.1 (pass) $ip=gethostbyname($domain); if(!in_blacklist($ip)) { $content=file_getcontents($domain); // 127.0.0.1 } ``` * 解析不一致 * 不同的url parser可能有不同的行為 ![](https://i.imgur.com/QRZM7xF.png) 接著便有兩題lab題,都是SSRF去拿metadata資料 ![](https://i.imgur.com/QNMrdUL.png) --- ## PACU ![](https://i.imgur.com/5Y7UJAX.png) 拿到了IAM Security Credentials之後,檢查Role的權限,好使用此role去存取別的服務。如果**有**IAM查閱權,則可以直接用API獲得權限表;反之,如果**沒有**查閱權,則可以遍歷所有API。講者也介紹了一個工具:[PACU - AWS exploitation framework](https://github.com/RhinoSecurityLabs/pacu),用於exploit AWS的服務。 ![](https://i.imgur.com/DUBhopP.png) 在使用PACU之前,得先匯入role的資訊到`~/.aws/credentials`可以直接新建一個檔案,或是使用[aws-cli](https://aws.amazon.com/tw/cli/)來新建credentails,匯入的key等資訊就填入先前從metadata獲得的資訊即可。 ![](https://i.imgur.com/VbiaVWw.png) `python3 pacu.py`打開PACU後,`import_keys <profile name>`匯入先前設定的credential至PACU中,可以用`whoami`檢查是否有成功匯入 ![](https://i.imgur.com/18XZGVV.png) `list`可以查看可用的功能,執行`run iam__bruteforce_permissions`枚舉可用的權限 * 提權 * 這個部分講師並沒有詳細的說,只是稍微帶過而已,而且lab他也擋掉了提權 ![](https://i.imgur.com/cbIF4Jp.png) * honeytoken * <a href="https://zh.wikipedia.org/wiki/%E8%9C%9C%E7%BD%90_(%E9%9B%BB%E8%85%A6%E7%A7%91%E5%AD%B8)">蜜罐</a> * 產生誘餌token,誘使入侵者使用,則發出警報通知 * http://canarytokens.org/generate# --- ## Container * 安全風險 * 逃逸(escape)弱點 * https://twitter.com/_fel1x/status/1151487051986087936 * image來源疑慮(dockerhub) --- ## S3 * 資料儲存服務 * 用API進行操作 * 雲端環境中的角色 * 資料長時間儲存 * 資料交換 * 儲存備份資料 * 安全問題 * 權限配置 * 意外存取 如果S3的權限沒設定好,則可能造成資料外洩:[s3-leaks](https://github.com/nagwww/s3-leaks)。而有人也提供了一個服務,可以搜尋網路上公開的s3:https://buckets.grayhatwarfare.com/ ![](https://i.imgur.com/fYEx0hq.png) ### s3規則 * bucket 名稱**唯一** * 網址格式 * `<bucket name>.s3-地區.amazonaws.com` * `s3-地區.amazonaws.com/<bucket name>` * e.g.: `ais3-sample.s3-ap-northeast-1.amazonaws.com` * 地區列表: https://docs.aws.amazon.com/en_us/general/latest/gr/rande.html#s3_region * 如果網站是自訂網域? * 使用`img.ais3.org`,而不是`ais3.s3.amazonaws.com` * `img.ais3.org.s3-地區.amazonaws.com` * 觀察header * ![](https://i.imgur.com/2dv1eve.png) ### 列舉s3 * 字典檔 * 手動 * 公司名稱 * 參考實際使用名稱 * 參考 DevOps 的命名方式 * 自動 * [Smeegescrape](https://github.com/SmeegeSec/SmeegeScrape) * [CeWL](https://www.freebuf.com/articles/network/190128.html) * AWSBucketDump * 全自動列舉公開的AWS S3 * 自動下載檔案 * usage: `python AWSBucketDump.py -l 字典檔 -g 關鍵字 -D -m 大小限制 -t 4` 接著小lab,用工具爆破兩個s3 bucket。 ## Serverless TOOD

Import from clipboard

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Upgrade to Prime

  • Edit verison name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare with
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Upgrade

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Upgrade

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully