HACK WEBSITE THAT HAS GIT

HACK WEBSITE THAT HAS GIT
Git ถือว่าเป็นเครื่องมือสำคัญสำหรับ Developer เพราะ Git Repository ถือว่าเป็นเครื่องมือแหล่งเก็บ source code ที่มิอาจขาดไม่ได้ไปเสียแล้ว ซึ่ง Git นั้นถูกออกแบบโดย Linus Torvalds หรือก็คือผู้สร้าง Linux นั่นเอง
Git ถูกนำมาใช้เก็บ source code ของ project มากมาย โดย Git นั้นจะคล้ายๆกับ Source Code Control ก่อนหน้านี้อย่าง SVN, Mercurcial ซึ่งมีการเก็บ metadata ต่างๆไว้ใน folder (หรือก็คือ directory) ที่เป็น .git ซึ่งเมื่อ folder ขึ้นต้นด้วย . ก็จะกลายเป็น hidden folder (โฟลเดอร์ที่ถูกซ่อน) ในทันที
ประเด็นสำคัญคือหาก developer นั้นพลาด checkout source code จาก Git Repository ไปยัง Production อาจทำให้ระบบตกอยู่ในความเสี่ยงได้ เพราะเนื่องด้วย .git folder จะถูก download ไปใน root folder ของเว็บไซด์เข้าไปด้วยนั่นเอง
โดยใน .git folder ดังกล่าวจะเก็บ file และ folder ย่อยไว้ ดังต่อไปนี้
  • HEAD
  • objects/info/packs
  • description
  • config
  • COMMIT_EDITMSG
  • index
  • packed-refs
  • refs/heads/master
  • refs/remotes/origin/HEAD
  • refs/stash
  • logs/HEAD
  • logs/refs/heads/master
  • logs/refs/remotes/origin/HEAD
  • info/refs
  • info/exclude
โดยการโจมตี Git Repository จะเริ่มต้นด้วย
1. ทำการ download File ทั้งหมด
  • HEAD
  • objects/info/packs
  • description
  • config
  • COMMIT_EDITMSG
  • index
  • packed-refs
  • refs/heads/master
  • refs/remotes/origin/HEAD
  • refs/stash
  • logs/HEAD
  • logs/refs/heads/master
  • logs/refs/remotes/origin/HEAD
  • info/refs
  • info/exclude
2. ตรวจสอบไฟล์  refs/heads/master เพื่อจะดูว่า hash ของ commit คืออะไร ในที่นี้ได้เป็น 93c0c0bac0af9cc8d13d9d9045039164d51638a1
Screen Shot 2562-05-01 at 23.52.55.png
3. ทำการ download commit-object โดยตำแหน่งจะเป็น
.git/objects/93/c0c0bac0af9cc8d13d9d9045039164d51638a1
4. จากนั้นทำการตรวจสอบไฟล์โดยใช้คำสั่ง
git cat-file -p 93c0c0bac0af9cc8d13d9d9045039164d51638a1
Screen Shot 2562-05-01 at 23.53.01.png
จะเห็นรายละเอียดว่าใครเป็นคน commit, commit ดังกล่าว comment ไว้ว่าอย่างไร, tree ต้นทางคือ id อะไร, parent ของ commit นี้คืออะไร
5. Download tree-object แล้วทำการ analysis อีกที
git cat-file -p b165eeaac2089f28e82ba84f44873173847d7662
Screen Shot 2562-05-01 at 23.53.12.png
จะเห็นว่า commit นั้นมีไฟล์อะไรบ้าง
6. เราสามารถดูข้อมูลของไฟล์ดังกล่าวได้โดยใช้คำสั่ง
git cat-file -p 70083268960081072b68b6acfa35cb14af7becd4
Screen Shot 2562-05-01 at 23.53.19.png

ใช้งาน GitTools

อย่างที่เห็นว่าขั้นตอนการทำนั้นค่อนข้างจะตายตัว จึงได้มีการสร้างเครื่องมือขึ้นมาชื่อว่า GitTools เพื่อทำการโจมตีเว็บไซด์ที่เผลอทิ้ง .git folder ไว้ในเว็บไซด์ โดยเราสามารถ download GitTools ได้จากhttps://github.com/internetwache/GitTools ซึ่งเมื่อ download มาแล้วเราสามารถใช้ GitTools ในการ download object และไฟล์สำคัญๆทั้งหมดของ .git โดยขั้นตอนการใช้งานคือ
1. Download GitTools
git clone https://github.com/internetwache/GitTools
2. เข้าไปที่ GitTools/Dumper
cd GitTools/Dumper
3. ใช้คำสั่ง gitdumper.sh เพื่อ download ไฟล์ทั้งหมด
bash gitdumper.sh http://<target>/.git/ <destination folder="">;</destination></target>
เช่น
bash gitdumper.sh http://target.com/.git/
4. เมื่อ Download ไฟล์ทั้งหมดเรียบร้อย เราจะสามารถ checkout source code ออกมาได้ จากนั้นทำการตรวจสอบ source code index.php
git checkout -- .
Screen Shot 2562-05-01 at 23.53.26.png

Comments

Popular Posts