Saturday, May 09, 2026 AM03:21:24 HKT
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
dnl based on
|
||||
dnl http://www.php.net/manual/en/internals2.buildsys.configunix.php
|
||||
|
||||
|
||||
PHP_ARG_ENABLE(libinjection, for libinjection support,
|
||||
[ --enable-libinjection Include libinjection])
|
||||
|
||||
dnl Check whether the extension is enabled at all
|
||||
if test "$PHP_LIBINJECTION" != "no"; then
|
||||
dnl Finally, tell the build system about the extension and what files are needed
|
||||
PHP_NEW_EXTENSION(libinjection, libinjection_sqli.c libinjection_wrap.c, $ext_shared)
|
||||
PHP_SUBST(LIBINJECTION_SHARED_LIBADD)
|
||||
fi
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
// add to your ini file:
|
||||
// extension=YOUR DIRECTORY//libinjection.so
|
||||
|
||||
echo "Using libinjection " . LIBINJECTION_VERSION . "\n";
|
||||
|
||||
// make a state object .. can be reused
|
||||
$x = new_libinjection_sqli_state();
|
||||
|
||||
// pass it in to init
|
||||
// arg 1 -- state objection above
|
||||
// arg 2 -- php string of input -- MUST BE URL-DECODED
|
||||
// arg 3 -- flags -- just pass in '0' for now
|
||||
$input = "1 union select 1,2,3,4--";
|
||||
libinjection_sqli_init($x, $input, 0);
|
||||
|
||||
// do a test
|
||||
$sqli = libinjection_is_sqli($x);
|
||||
if ($sqli == 1) {
|
||||
echo "sqli with fingerprint " . libinjection_sqli_state_fingerprint_get($x) . "\n";
|
||||
} else {
|
||||
echo "not sqli";
|
||||
}
|
||||
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Takes testing files and turns them PHP module tests
|
||||
"""
|
||||
|
||||
import glob
|
||||
import os
|
||||
|
||||
def phpescape(s):
|
||||
"""
|
||||
escapes plain text into php-code
|
||||
"""
|
||||
return s.replace("\\", "\\\\").replace("$", "\\$")
|
||||
|
||||
def readtestdata(filename):
|
||||
"""
|
||||
Read a test file and split into components
|
||||
"""
|
||||
|
||||
state = None
|
||||
info = {
|
||||
'--TEST--': '',
|
||||
'--INPUT--': '',
|
||||
'--EXPECTED--': ''
|
||||
}
|
||||
|
||||
for line in open(filename, 'r'):
|
||||
line = line.rstrip()
|
||||
if line in ('--TEST--', '--INPUT--', '--EXPECTED--'):
|
||||
state = line
|
||||
elif state:
|
||||
info[state] += line + '\n'
|
||||
|
||||
# remove last newline from input
|
||||
info['--INPUT--'] = info['--INPUT--'][0:-1]
|
||||
|
||||
return (info['--TEST--'], info['--INPUT--'].strip(), info['--EXPECTED--'].strip())
|
||||
|
||||
def gentest_tokens():
|
||||
"""
|
||||
generate token phpt test
|
||||
"""
|
||||
for testname in sorted(glob.glob('../tests/test-tokens-*.txt')):
|
||||
data = readtestdata(os.path.join('../tests', testname))
|
||||
testname = os.path.basename(testname)
|
||||
phpt = """
|
||||
--TEST--
|
||||
{1}
|
||||
--FILE--
|
||||
<?php
|
||||
require(sprintf("%s/../testsupport.php", dirname(__FILE__)));
|
||||
$sqlistate = new_libinjection_sqli_state();
|
||||
$s = <<<EOT
|
||||
{2}
|
||||
EOT;
|
||||
$s = trim($s);
|
||||
libinjection_sqli_init($sqlistate, $s, FLAG_QUOTE_NONE | FLAG_SQL_ANSI);
|
||||
while (libinjection_sqli_tokenize($sqlistate)) {{
|
||||
echo(print_token(libinjection_sqli_state_current_get($sqlistate)) . "\\n");
|
||||
}}
|
||||
--EXPECT--
|
||||
{3}
|
||||
"""
|
||||
phpt = phpt.format(testname, data[0], phpescape(data[1]), data[2])
|
||||
|
||||
with open('build/tests/' + testname.replace('.txt', '.phpt'), 'w') as fd:
|
||||
fd.write(phpt.strip())
|
||||
|
||||
|
||||
def gentest_folding():
|
||||
for testname in sorted(glob.glob('../tests/test-folding-*.txt')):
|
||||
data = readtestdata(os.path.join('../tests', testname))
|
||||
testname = os.path.basename(testname)
|
||||
phpt = """
|
||||
--TEST--
|
||||
{1}
|
||||
--FILE--
|
||||
<?php
|
||||
require(sprintf("%s/../testsupport.php", dirname(__FILE__)));
|
||||
$sqlistate = new_libinjection_sqli_state();
|
||||
$s = <<<EOT
|
||||
{2}
|
||||
EOT;
|
||||
$s = trim($s);
|
||||
libinjection_sqli_init($sqlistate, $s, FLAG_QUOTE_NONE | FLAG_SQL_ANSI);
|
||||
$fingerprint = libinjection_sqli_fingerprint($sqlistate, FLAG_QUOTE_NONE | FLAG_SQL_ANSI);
|
||||
for ($i = 0; $i < strlen($fingerprint); $i++) {{
|
||||
echo(print_token(libinjection_sqli_get_token($sqlistate, $i)) . "\\n");
|
||||
}}
|
||||
--EXPECT--
|
||||
{3}
|
||||
"""
|
||||
phpt = phpt.format(testname, data[0], phpescape(data[1]), data[2])
|
||||
|
||||
with open('build/tests/' + testname.replace('.txt', '.phpt'), 'w') as fd:
|
||||
fd.write(phpt.strip())
|
||||
|
||||
def gentest_fingerprints():
|
||||
"""
|
||||
generate phpt for testing sqli testing
|
||||
"""
|
||||
for testname in sorted(glob.glob('../tests/test-sqli-*.txt')):
|
||||
data = readtestdata(os.path.join('../tests', testname))
|
||||
testname = os.path.basename(testname)
|
||||
phpt = """
|
||||
--TEST--
|
||||
{0}
|
||||
--DESCRIPTION--
|
||||
{1}
|
||||
--FILE--
|
||||
<?php
|
||||
require(sprintf("%s/../testsupport.php", dirname(__FILE__)));
|
||||
$sqlistate = new_libinjection_sqli_state();
|
||||
$s = <<<EOT
|
||||
{2}
|
||||
EOT;
|
||||
$s = trim($s);
|
||||
libinjection_sqli_init($sqlistate, $s, FLAG_QUOTE_NONE | FLAG_SQL_ANSI);
|
||||
$ok = libinjection_is_sqli($sqlistate);
|
||||
if ($ok == 1) {{
|
||||
echo(libinjection_sqli_state_fingerprint_get($sqlistate) . "\n");
|
||||
}}
|
||||
--EXPECT--
|
||||
{3}
|
||||
"""
|
||||
phpt = phpt.format(testname, data[0], phpescape(data[1]), data[2])
|
||||
|
||||
with open('build/tests/' + testname.replace('.txt', '.phpt'), 'w') as fd:
|
||||
fd.write(phpt.strip())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
gentest_tokens()
|
||||
gentest_folding()
|
||||
gentest_fingerprints()
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright 2012, 2013 Nick Galbreath
|
||||
# nickg@client9.com
|
||||
# BSD License -- see COPYING.txt for details
|
||||
#
|
||||
|
||||
"""
|
||||
Converts a libinjection JSON data file to PHP array
|
||||
"""
|
||||
|
||||
def toc(obj):
|
||||
""" main routine """
|
||||
|
||||
print("""<?php
|
||||
function lookup($state, $stype, $keyword) {
|
||||
$keyword = struper(keyword);
|
||||
if ($stype == libinjection.LOOKUP_FINGERPRINT) {
|
||||
if ($keyword == $fingerprints && libinjection.sqli_not_whitelist($state)) {
|
||||
return 'F';
|
||||
} else {
|
||||
return chr(0);
|
||||
}
|
||||
}
|
||||
return $words.get(keyword, chr(0));
|
||||
}
|
||||
""")
|
||||
|
||||
words = {}
|
||||
keywords = obj['keywords']
|
||||
for k,v in keywords.items():
|
||||
words[str(k)] = str(v)
|
||||
|
||||
print('$words = array(')
|
||||
for k in sorted(words.keys()):
|
||||
print("'{0}' => '{1}',".format(k, words[k]))
|
||||
print(');\n')
|
||||
|
||||
|
||||
keywords = obj['fingerprints']
|
||||
print('$fingerprints = array(')
|
||||
for k in sorted(keywords):
|
||||
print("'{0}',".format(k.upper()))
|
||||
print(');')
|
||||
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
import json
|
||||
sys.exit(toc(json.load(sys.stdin)))
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/* libinjection.i SWIG interface file for PHP */
|
||||
%module libinjection
|
||||
%{
|
||||
#include "libinjection.h"
|
||||
#include "libinjection_sqli.h"
|
||||
|
||||
struct libinjection_sqli_token * libinjection_sqli_state_tokenvec_geti(sfilter* sf, int i) {
|
||||
return &(sf->tokenvec[i]);
|
||||
}
|
||||
%}
|
||||
|
||||
%include "typemaps.i"
|
||||
|
||||
// automatically append string length into arg array
|
||||
%apply (char *STRING, size_t LENGTH) { (const char *s, size_t slen) };
|
||||
|
||||
%include "libinjection.h"
|
||||
%include "libinjection_sqli.h"
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
function print_token($tok) {
|
||||
$tt = libinjection_sqli_token_type_get($tok);
|
||||
$out = '';
|
||||
$out .= $tt;
|
||||
$out .= ' ';
|
||||
if ($tt == 's') {
|
||||
$out .= print_token_string($tok);
|
||||
} else if ($tt == 'v') {
|
||||
$vc = libinjection_sqli_token_count_get($tok);
|
||||
if ($vc == 1) {
|
||||
$out .= '@';
|
||||
} else if ($vc == 2) {
|
||||
$out .= '@@';
|
||||
}
|
||||
$out .= print_token_string($tok);
|
||||
} else {
|
||||
$out .= libinjection_sqli_token_val_get($tok);
|
||||
}
|
||||
return trim($out);
|
||||
}
|
||||
|
||||
function print_token_string($tok) {
|
||||
$out = '';
|
||||
$quote = libinjection_sqli_token_str_open_get($tok);
|
||||
if ($quote != "\0") {
|
||||
$out .= $quote;
|
||||
}
|
||||
$out .= libinjection_sqli_token_val_get($tok);
|
||||
$quote = libinjection_sqli_token_str_close_get($tok);
|
||||
if ($quote != "\0") {
|
||||
$out .= $quote;
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
Reference in New Issue
Block a user