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); |
||
119 | } |
||
120 | |||
121 | return $urls; |
||
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.