This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Aszone\Vulnerabilities; |
||
4 | |||
5 | use GuzzleHttp\ClientInterface; |
||
6 | use Psr\Log\LoggerInterface; |
||
7 | use Aszone\Vulnerabilities\Log\Logger; |
||
8 | |||
9 | class CrossSiteScripting implements VulnerabilityScanner |
||
10 | { |
||
11 | const EXPLOIT1 = '<script>alert(aaabbbccc);</script>'; |
||
12 | const EXPLOIT2 = '<h1>aaabbbccc</h1>'; |
||
13 | const EXPLOIT1REGEX = "<script>alert\(aaabbbccc\);<\/script>"; |
||
14 | const EXPLOIT2REGEX = "<h1>aaabbbccc<\/h1>"; |
||
15 | |||
16 | private $compare; |
||
17 | |||
18 | private $client; |
||
19 | |||
20 | private $logger; |
||
21 | |||
22 | View Code Duplication | public function __construct(ClientInterface $client, array $compare, LoggerInterface $logger = null) |
|
0 ignored issues
–
show
|
|||
23 | { |
||
24 | $this->client = $client; |
||
25 | $this->compare = $compare; |
||
26 | |||
27 | if (empty($logger)) { |
||
28 | $logger = new Logger; |
||
29 | } |
||
30 | |||
31 | $this->logger = $logger; |
||
32 | |||
33 | |||
34 | } |
||
35 | |||
36 | public function isVulnerable($target) |
||
37 | { |
||
38 | if ($this->isXssPossible($target)) { |
||
39 | return $this->verify($target); |
||
40 | } |
||
41 | |||
42 | return false; |
||
43 | } |
||
44 | |||
45 | public function isXssPossible($target) |
||
46 | { |
||
47 | return (bool) preg_match("/\?|(.+?)\=/", (string) $target); |
||
48 | } |
||
49 | |||
50 | View Code Duplication | public function verify($target) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
51 | { |
||
52 | |||
53 | $urls = $this->generateUrls($target); |
||
54 | |||
55 | $this->logger->info("\n"); |
||
56 | |||
57 | foreach ($urls as $url) { |
||
58 | if ($this->attack($url)) { |
||
59 | $this->logger->info('Is Vull'); |
||
60 | |||
61 | return true; |
||
62 | } |
||
63 | } |
||
64 | |||
65 | return false; |
||
66 | } |
||
67 | |||
68 | View Code Duplication | public function attack($url) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
69 | { |
||
70 | $this->logger->info('.'); |
||
71 | |||
72 | try { |
||
73 | $body = $this->client->get($url)->getBody()->getContents(); |
||
74 | if ($body && $this->checkSuccess($body) && $this->checkCompare($body)) { |
||
75 | return true; |
||
76 | } |
||
77 | } catch (\Exception $e) { |
||
78 | $this->logger->error('#'); |
||
79 | } |
||
80 | |||
81 | return false; |
||
82 | } |
||
83 | |||
84 | public function checkSuccess($body) |
||
85 | { |
||
86 | return (bool) preg_match('/'.static::EXPLOIT1REGEX.'|'.static::EXPLOIT2REGEX.'/', $body); |
||
87 | } |
||
88 | |||
89 | View Code Duplication | public function generateUrls($target) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
90 | { |
||
91 | $this->logger->info("\n".$target); |
||
92 | $urls1 = $this->generateUrlsByExploit($target, static::EXPLOIT1); |
||
93 | $urls2 = $this->generateUrlsByExploit($target, static::EXPLOIT2); |
||
94 | return array_merge($urls1, $urls2); |
||
95 | } |
||
96 | |||
97 | public function generateUrlsByExploit($target, $exploit) |
||
98 | { |
||
99 | $explodeUrl = parse_url($target); |
||
100 | $explodeQuery = explode('&', $explodeUrl['query']); |
||
101 | |||
102 | if (!isset($explodeUrl['query'])) { |
||
103 | return []; |
||
104 | } |
||
105 | |||
106 | $wordsValue = []; |
||
107 | |||
108 | View Code Duplication | foreach ($explodeQuery as $query) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
109 | $explodeQueryEqual = explode('=', $query); |
||
110 | $wordsValue[$explodeQueryEqual[0]] = ''; |
||
111 | |||
112 | if (isset($explodeQueryEqual[1])) { |
||
113 | $wordsValue[$explodeQueryEqual[0]] = $explodeQueryEqual[1]; |
||
114 | } |
||
115 | } |
||
116 | |||
117 | View Code Duplication | foreach ($wordsValue as $keyValue => $value) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
118 | $urls[] = str_replace($keyValue.'='.$value, $keyValue.'='.$exploit, $target); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$urls was never initialized. Although not strictly required by PHP, it is generally a good practice to add $urls = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.
Loading history...
|
|||
119 | } |
||
120 | |||
121 | return $urls; |
||
0 ignored issues
–
show
The variable
$urls does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
Loading history...
|
|||
122 | } |
||
123 | |||
124 | public function checkCompare($body) |
||
125 | { |
||
126 | foreach ($this->compare as $compare) { |
||
127 | |||
128 | $isValid = strpos($body, $compare); |
||
129 | if ($isValid !== false) { |
||
130 | return true; |
||
131 | } |
||
132 | } |
||
133 | |||
134 | return false; |
||
135 | } |
||
136 | |||
137 | } |
||
138 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.