-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
php:chore - Add example2 of the php project (#12)
Adding another php example to get vulnerabilities using tool PHP_CodeSniffer Signed-off-by: wilian <[email protected]>
- Loading branch information
1 parent
5dc15ef
commit 3045059
Showing
8 changed files
with
300 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
// Copyright 2021 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
|
||
// Cross-Site Scripting (XSS) | ||
$name = $_GET['name']; | ||
echo('Hello ' . $name); | ||
|
||
// SQL Injection | ||
$id = $_POST['id']; | ||
mysql_query("SELECT user FROM users WHERE id = " . $id); | ||
|
||
// Command Injection | ||
$cmd = $_COOKIE['cmd']; | ||
exec("cat /var/log/apache2/access.log | grep " . $cmd); | ||
|
||
// Deprecated Function | ||
$words = split(":", "split:this"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
// Copyright 2021 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
|
||
if (PHP_SAPI === 'cli') { | ||
parse_str(implode('&', array_slice($argv, 1)), $_GET); | ||
} | ||
|
||
if (NULL == $_GET['name']) $_GET['name'] = "Guest! "; | ||
|
||
echo 'Hello, welcome ' . $_GET['name']; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
// Copyright 2021 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
|
||
if (PHP_SAPI === 'cli') { | ||
parse_str(implode('&', array_slice($argv, 1)), $_GET); | ||
} | ||
|
||
$file_db = new PDO('sqlite:../database/database.sqlite'); | ||
|
||
if (NULL == $_GET['id']) $_GET['id'] = 1; | ||
|
||
$sql = 'SELECT * FROM employees WHERE employeeId = ' . $_GET['id']; | ||
|
||
foreach ($file_db->query($sql) as $row) { | ||
$employee = $row['LastName'] . " - " . $row['Email'] . "\n"; | ||
|
||
echo $employee; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
// Copyright 2021 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
|
||
if (PHP_SAPI === 'cli') { | ||
parse_str(implode('&', array_slice($argv, 1)), $_GET); | ||
} | ||
|
||
$id = $_GET['id'] ?? 1; | ||
|
||
$file_db = new PDO('sqlite:../database/database.sqlite'); | ||
|
||
foreach ($file_db->query('SELECT * FROM customers WHERE customerId = ' . $id) as $row) { | ||
$customer = $row['LastName'] . " - " . $row['Email'] . "\n"; | ||
|
||
echo $customer; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
// Copyright 2021 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
|
||
function bar() { | ||
foo($_GET['name']); | ||
} | ||
|
||
function foo($name) { | ||
mysql_query("SELECT * FROM foo WHERE name = '$name'"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<?php | ||
// Copyright 2021 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/* Tests script for phpcs-security-audit */ | ||
|
||
//eval($_GET['a']); | ||
echo "aaaa"; | ||
echo "bbbb" . $_POST['b']; | ||
echo "b"; | ||
db_query($_GET['a']); | ||
preg_replace("/.*/ei", 'aaaaaaa', 'bbbbb'); | ||
preg_replace("/.*/ei", $_GET['a'], 'aaaaaaa'); | ||
preg_replace($_GET['b'], $_GET['a'], $_GET['c']); | ||
preg_replace($b, $_GET['a'], 'aaaaaa'); | ||
preg_replace("aaa", $_GET['a'], 'ababaaa'); | ||
|
||
|
||
// BadFunctions | ||
md5(); | ||
phpinfo(); | ||
create_function($a); | ||
ftp_exec($a); | ||
fread($a); | ||
array_map($a); | ||
`$a`; | ||
`$_GET`; | ||
include($a); | ||
assert($a); | ||
assert($_GET); | ||
exec($a); | ||
exec($_GET); | ||
mysql_query($a); | ||
mysql_query($_GET); | ||
|
||
|
||
// Crypto | ||
mcrypt_encrypt(); | ||
openssl_public_encrypt($i, $e, $k, OPENSSL_PKCS1_PADDING); | ||
|
||
// CVEs | ||
xml_parse_into_struct(xml_parser_create_ns(), str_repeat("<blah>", 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']); | ||
?> | ||
<?= $_GET['a'] ?> | ||
<?php | ||
|
||
// FilesystemFunctions | ||
file_create_filename(arg(1)); | ||
symlink($a); | ||
delete($a); | ||
|
||
// Drupal 7 Dynamic queries SQLi | ||
$query = db_select('tname', "wn"); | ||
$query->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'); | ||
|
||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
// Copyright 2021 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
|
||
$var7 = $_GET["p"]; | ||
$var4 = $var7; | ||
echo "$var4"; |