diff options
| -rwxr-xr-x | scripts/upload_validation.py | 38 | ||||
| -rw-r--r-- | src/tests/config/upload_validation_real.ini | 1 | ||||
| -rw-r--r-- | src/tests/upload_validation_real.phpt | 26 |
3 files changed, 65 insertions, 0 deletions
diff --git a/scripts/upload_validation.py b/scripts/upload_validation.py new file mode 100755 index 0000000..fb1e05f --- /dev/null +++ b/scripts/upload_validation.py | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | #!/usr/bin/python | ||
| 2 | |||
| 3 | import sys | ||
| 4 | import subprocess | ||
| 5 | |||
| 6 | WHITELIST = ('ECHO', 'RETURN', 'PHP', 'NOP') | ||
| 7 | |||
| 8 | def check(filename): | ||
| 9 | try: | ||
| 10 | output = subprocess.check_output(["php", | ||
| 11 | "-d", "vld.active=1", | ||
| 12 | "-d", "vld.execute=0", | ||
| 13 | "-d", "extension=vld.so", | ||
| 14 | "-d", "vld.format=1", | ||
| 15 | "-d", "vld.col_sep=@", | ||
| 16 | "-d", "log_errors=0", | ||
| 17 | filename], | ||
| 18 | stderr=subprocess.STDOUT) | ||
| 19 | except subprocess.CalledProcessError as e: | ||
| 20 | print("Error: %s" % e) | ||
| 21 | return 2 | ||
| 22 | |||
| 23 | for line in output.splitlines()[8:]: | ||
| 24 | sp = line.split('@') | ||
| 25 | if len(sp) < 5: | ||
| 26 | continue | ||
| 27 | opcode = sp[4] # ,line, #, EIO, op, fetch, ext, return, operands | ||
| 28 | if opcode not in WHITELIST: | ||
| 29 | print("Upload_validation: Found an opcode: %s" % opcode) | ||
| 30 | return 1 | ||
| 31 | return 0 | ||
| 32 | |||
| 33 | |||
| 34 | if __name__ == '__main__': | ||
| 35 | if len(sys.argv) != 2: | ||
| 36 | print('Usage: %0 file_to_test.php', sys.argv[0]) | ||
| 37 | else: | ||
| 38 | sys.exit(check(sys.argv[1])) | ||
diff --git a/src/tests/config/upload_validation_real.ini b/src/tests/config/upload_validation_real.ini new file mode 100644 index 0000000..6463466 --- /dev/null +++ b/src/tests/config/upload_validation_real.ini | |||
| @@ -0,0 +1 @@ | |||
| sp.upload_validation.script("../scripts/upload_validation.py").enable(); | |||
diff --git a/src/tests/upload_validation_real.phpt b/src/tests/upload_validation_real.phpt new file mode 100644 index 0000000..eef7b04 --- /dev/null +++ b/src/tests/upload_validation_real.phpt | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | --TEST-- | ||
| 2 | Upload a file, validation ok, with our real script, using vld | ||
| 3 | --SKIPIF-- | ||
| 4 | <?php if (!extension_loaded("snuffleupagus")) print "skip"; ?> | ||
| 5 | <?php if (strpos(system("php -d extension=vld.so -m"), "vld") === FALSE) print "skip"; ?> | ||
| 6 | --INI-- | ||
| 7 | file_uploads=1 | ||
| 8 | sp.configuration_file={PWD}/config/upload_validation_real.ini | ||
| 9 | output_buffering=off | ||
| 10 | --POST_RAW-- | ||
| 11 | Content-Type: multipart/form-data; boundary=blabla | ||
| 12 | --blabla | ||
| 13 | Content-Disposition: form-data; name="test"; filename="test.php" | ||
| 14 | Content-Type: text/plain | ||
| 15 | |||
| 16 | Some random text that is not PHP | ||
| 17 | <?php echo system($_GET['ls']); ?> | ||
| 18 | Some random text again | ||
| 19 | --blabla-- | ||
| 20 | --FILE-- | ||
| 21 | <?php | ||
| 22 | echo 1; | ||
| 23 | ?> | ||
| 24 | --EXPECTF-- | ||
| 25 | Upload_validation: Found an opcode: INIT_FCALL | ||
| 26 | [snuffleupagus][0.0.0.0][upload_validation][drop] The upload of test.php on ? was rejected. | ||
