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 | * Created by PhpStorm. |
||
4 | * User: lenon |
||
5 | * Date: 03/04/16 |
||
6 | * Time: 19:24. |
||
7 | */ |
||
8 | |||
9 | namespace Aszone\SearchHacking; |
||
10 | |||
11 | use Symfony\Component\DomCrawler\Crawler; |
||
12 | use Aszone\FakeHeaders\FakeHeaders; |
||
13 | use GuzzleHttp\Client; |
||
14 | |||
15 | class Utils |
||
16 | { |
||
17 | View Code Duplication | public static function sanitazeLinks($links = array()) |
|
18 | { |
||
19 | $hrefs = array(); |
||
20 | |||
21 | if (!empty($links)) { |
||
22 | foreach ($links as $keyLink => $valueLink) { |
||
23 | $url = static::clearLink($valueLink->getAttribute('href')); |
||
24 | $validResultOfBlackList = static::checkBlacklist($url); |
||
25 | |||
26 | if (!$validResultOfBlackList and $url) { |
||
0 ignored issues
–
show
|
|||
27 | $hrefs[] = $url; |
||
28 | } |
||
29 | } |
||
30 | |||
31 | $hrefs = array_unique($hrefs); |
||
32 | } |
||
33 | |||
34 | return $hrefs; |
||
35 | } |
||
36 | |||
37 | public static function checkBlacklist($url = '') |
||
38 | { |
||
39 | if (!empty($url)) { |
||
40 | $validXmlrpc = preg_match("/(https?\:\/\/|^)(.+?)\//", $url, $matches, PREG_OFFSET_CAPTURE); |
||
0 ignored issues
–
show
$validXmlrpc is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
41 | $url = ''; |
||
42 | |||
43 | if (isset($matches[2][0])) { |
||
44 | $url = $matches[2][0]; |
||
45 | } |
||
46 | |||
47 | $ini_blakclist = parse_ini_file(__DIR__.'/../resources/Blacklist.ini'); |
||
48 | |||
49 | $key = array_search($url, $ini_blakclist); |
||
50 | |||
51 | if ($key != false) { |
||
52 | return true; |
||
53 | } |
||
54 | } |
||
55 | |||
56 | return false; |
||
57 | } |
||
58 | |||
59 | public static function clearLink($url = '') |
||
60 | { |
||
61 | if (!empty($url)) { |
||
62 | $validXmlrpc = preg_match('/search%3Fq%3Dcache:.+?:(.+?)%252B/', $url, $matches, PREG_OFFSET_CAPTURE); |
||
0 ignored issues
–
show
$validXmlrpc is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
63 | |||
64 | if (isset($matches[1][0])) { |
||
65 | return $matches[1][0]; |
||
66 | } |
||
67 | |||
68 | $validXmlrpc = preg_match("/search\?q=cache:.+?:(.+?)\+/", $url, $matches, PREG_OFFSET_CAPTURE); |
||
0 ignored issues
–
show
$validXmlrpc is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
69 | |||
70 | if (isset($matches[1][0])) { |
||
71 | return $matches[1][0]; |
||
72 | } |
||
73 | |||
74 | $validXmlrpc = preg_match('/url=(.*?)&tld/', $url, $matches, PREG_OFFSET_CAPTURE); |
||
0 ignored issues
–
show
$validXmlrpc is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
75 | |||
76 | if (isset($matches[1][0])) { |
||
77 | return urldecode($matches[1][0]); |
||
78 | } |
||
79 | |||
80 | //Msn Bing |
||
81 | $validXmlrpc = preg_match("/^((http|https):\/\/|www).+?\/?ld=.+?\&u=(.+?)\n/", $url, $matches, PREG_OFFSET_CAPTURE); |
||
0 ignored issues
–
show
$validXmlrpc is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
82 | |||
83 | if (isset($matches[1][0])) { |
||
84 | return urldecode($matches[1][0]); |
||
85 | } |
||
86 | |||
87 | $validXmlrpc = preg_match("/^((http|https):\/\/|www)(.+?)\//", $url, $matches, PREG_OFFSET_CAPTURE); |
||
0 ignored issues
–
show
$validXmlrpc is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
88 | |||
89 | if (isset($matches[0][0])) { |
||
90 | $check[] = strpos($url, 'www.blogger.com'); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$check was never initialized. Although not strictly required by PHP, it is generally a good practice to add $check = 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. ![]() |
|||
91 | $check[] = strpos($url, 'youtube.com'); |
||
92 | $check[] = strpos($url, '.google.'); |
||
93 | $check[] = strpos($url, 'yandex.ru'); |
||
94 | $check[] = strpos($url, 'microsoft.com'); |
||
95 | $check[] = strpos($url, 'microsofttranslator.com'); |
||
96 | $check[] = strpos($url, '.yahoo.com'); |
||
97 | $check[] = strpos($url, 'yahoo.uservoice.com'); |
||
98 | $check[] = strpos($url, 'www.mozilla.org'); |
||
99 | $check[] = strpos($url, 'www.facebook.com'); |
||
100 | $check[] = strpos($url, 'go.mail.ru'); |
||
101 | $check[] = strpos($url, '/search/srpcache?p='); |
||
102 | $check[] = strpos($url, 'flickr.com'); |
||
103 | |||
104 | $tmp = array_filter($check); |
||
105 | |||
106 | if (empty($tmp)) { |
||
107 | return trim($url); |
||
108 | } |
||
109 | } |
||
110 | } |
||
111 | |||
112 | return false; |
||
113 | } |
||
114 | |||
115 | public static function getLinks($body) |
||
116 | { |
||
117 | $crawler = new Crawler($body); |
||
118 | |||
119 | return $crawler->filter('a'); |
||
120 | } |
||
121 | |||
122 | public static function getBody($urlOfSearch, $proxy) |
||
123 | { |
||
124 | $header = new FakeHeaders(); |
||
125 | $valid = true; |
||
0 ignored issues
–
show
$valid is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
126 | |||
127 | try { |
||
128 | $client = new Client([ |
||
129 | 'defaults' => [ |
||
130 | 'headers' => ['User-Agent' => $header->getUserAgent()], |
||
131 | 'proxy' => $proxy, |
||
132 | 'timeout' => 60, |
||
133 | ], |
||
134 | ]); |
||
135 | |||
136 | return $client->get($urlOfSearch)->getBody()->getContents(); |
||
137 | } catch (\Exception $e) { |
||
138 | $message = 'ERROR : '.$e->getMessage()."\n"; |
||
139 | |||
140 | if ($proxy == false) { |
||
141 | $message .= "Your ip is blocked, we are using proxy at now...\n"; |
||
142 | } |
||
143 | |||
144 | return $message; |
||
145 | } |
||
146 | |||
147 | return false; |
||
0 ignored issues
–
show
return false; does not seem to be reachable.
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed. Unreachable code is most often the result of function fx() {
try {
doSomething();
return true;
}
catch (\Exception $e) {
return false;
}
return false;
}
In the above example, the last ![]() |
|||
148 | } |
||
149 | |||
150 | public static function getBodyByVirginProxies($urlOfSearch, $urlProxie, $proxy) |
||
151 | { |
||
152 | $header = new FakeHeaders(); |
||
153 | |||
154 | echo 'Proxy : '.$urlProxie."\n"; |
||
155 | |||
156 | $dataToPost = ['body' => ['url' => $urlOfSearch]]; |
||
157 | |||
158 | $valid = true; |
||
159 | while ($valid == true) { |
||
0 ignored issues
–
show
|
|||
160 | try { |
||
161 | $client = new Client([ |
||
162 | 'defaults' => [ |
||
163 | 'headers' => ['User-Agent' => $header->getUserAgent()], |
||
164 | 'proxy' => $proxy, |
||
165 | 'timeout' => 60, |
||
166 | ], |
||
167 | ]); |
||
168 | |||
169 | $res = $client->post($urlProxie, $dataToPost); |
||
170 | $body = $res->getBody()->getContents(); |
||
171 | |||
172 | //check if change new tor ip |
||
173 | $valid = false; |
||
174 | } catch (\Exception $e) { |
||
175 | echo 'ERROR : '.$e->getMessage()."\n"; |
||
176 | if ($proxy == false) { |
||
177 | echo "This ip of virgin proxy is blocked, we are using proxy at now...\n"; |
||
178 | } |
||
179 | |||
180 | return 'repeat'; |
||
181 | } |
||
182 | } |
||
183 | |||
184 | return $body; |
||
0 ignored issues
–
show
The variable
$body 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
![]() |
|||
185 | } |
||
186 | } |
||
187 |
PHP has two types of connecting operators (logical operators, and boolean operators):
and
&&
or
||
The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&
, or||
.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
die
introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrow
at this point:These limitations lead to logical operators rarely being of use in current PHP code.