From 30450594db0f727fc95a4150439e9950d32ca8fe Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Wed, 19 Jan 2022 13:35:20 -0300 Subject: [PATCH] php:chore - Add example2 of the php project (#12) Adding another php example to get vulnerabilities using tool PHP_CodeSniffer Signed-off-by: wilian --- java/example2/src/main/resources/log4j2.xml | 16 +++ php/example2/basic-collection.php | 30 +++++ php/example2/cross-site-scripting-xss.php | 24 ++++ php/example2/sql-injection.php | 31 +++++ php/example2/sql-injection_2.php | 30 +++++ .../tool-examples/php-security-scanner.php | 23 ++++ .../tool-examples/phpcs-security-audit.php | 127 ++++++++++++++++++ php/example2/tool-examples/progpilot.php | 19 +++ 8 files changed, 300 insertions(+) create mode 100644 php/example2/basic-collection.php create mode 100644 php/example2/cross-site-scripting-xss.php create mode 100644 php/example2/sql-injection.php create mode 100644 php/example2/sql-injection_2.php create mode 100644 php/example2/tool-examples/php-security-scanner.php create mode 100644 php/example2/tool-examples/phpcs-security-audit.php create mode 100644 php/example2/tool-examples/progpilot.php diff --git a/java/example2/src/main/resources/log4j2.xml b/java/example2/src/main/resources/log4j2.xml index 200e939..f333729 100644 --- a/java/example2/src/main/resources/log4j2.xml +++ b/java/example2/src/main/resources/log4j2.xml @@ -15,6 +15,22 @@ --> + + diff --git a/php/example2/basic-collection.php b/php/example2/basic-collection.php new file mode 100644 index 0000000..48aa635 --- /dev/null +++ b/php/example2/basic-collection.php @@ -0,0 +1,30 @@ +query($sql) as $row) { + $employee = $row['LastName'] . " - " . $row['Email'] . "\n"; + + echo $employee; +} diff --git a/php/example2/sql-injection_2.php b/php/example2/sql-injection_2.php new file mode 100644 index 0000000..0076378 --- /dev/null +++ b/php/example2/sql-injection_2.php @@ -0,0 +1,30 @@ +query('SELECT * FROM customers WHERE customerId = ' . $id) as $row) { + $customer = $row['LastName'] . " - " . $row['Email'] . "\n"; + + echo $customer; +} + diff --git a/php/example2/tool-examples/php-security-scanner.php b/php/example2/tool-examples/php-security-scanner.php new file mode 100644 index 0000000..1c5edf6 --- /dev/null +++ b/php/example2/tool-examples/php-security-scanner.php @@ -0,0 +1,23 @@ +", 1000), $a); +quoted_printable_encode(str_repeat("\xf4", 1000)); + +// Misc +$a->withHeader('Access-Control-Allow-Origin', '*'); +include('abc.xyz'); + +// Easy user input +$_GET['a'] = 'xss'; +print("aaa" . $_GET['a']); +echo($_GET['a']); +echo $_GET['a']; +echo "{$_GET['a']}"; +print "${_GET['a']}"; +echo a($_GET['b']); +echo(allo(a($_GET['c']))); +echo arg(1); +die("" . $_GET['a']); +exit("exit" . $_GET['a']); +?> + +join('node', 'n', $a); +$query->innerJoin('node', 'n', $a); +$query->leftJoin('node', 'n', $a); +$query->rightJoin('node', 'n', $a); +$query->addExpression($a, 'w'); +$query->groupBy($a); + +$query->orderBy($a, $a); +$query->range('safe', 'safe'); + +$count = $query + ->fields("wn") + ->condition('email', '1', $_GET) + ->condition('email', '1') + ->where($a, array(":aaa" => '2')) + ->havingCondition('email', '', $a) + ->having($a, $args = array(":aaa" => '2')) + ->execute() + ->rowCount(); +echo $count; + +$query = db_update('tname') + ->expression($a, $a) + ->execute(); + +$nid = db_insert('tname') + ->fields(array( + $a => 'safe', + $b => 'safe', + 'c' => 'safe', + + )) + ->values(array( + 'safe' => 'safe', + )) + ->execute(); + +$query = db_select('node', 'n'); +$myselect = db_select('mytable') + ->fields($_GET) + ->condition('myfield', 'myvalue'); +$alias = $query->join($myselect, 'myalias', 'n.nid = myalias.nid'); + + +?> \ No newline at end of file diff --git a/php/example2/tool-examples/progpilot.php b/php/example2/tool-examples/progpilot.php new file mode 100644 index 0000000..8fe1d6c --- /dev/null +++ b/php/example2/tool-examples/progpilot.php @@ -0,0 +1,19 @@ +