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: 23/04/16 |
|||||||||||
6 | * Time: 01:43. |
|||||||||||
7 | */ |
|||||||||||
8 | ||||||||||||
9 | namespace Aszone\SearchHacking\Engines; |
|||||||||||
10 | ||||||||||||
11 | use Aszone\SearchHacking\Utils; |
|||||||||||
12 | ||||||||||||
13 | class DuckDuckGo extends Engine |
|||||||||||
14 | { |
|||||||||||
15 | public function run() |
|||||||||||
16 | { |
|||||||||||
17 | $exit = false; |
|||||||||||
18 | $count = 0; |
|||||||||||
19 | $numPaginator = 0; |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
20 | $countProxyVirgin = rand(0, count($this->listOfVirginProxies) - 1); |
|||||||||||
21 | $resultFinal = array(); |
|||||||||||
22 | $countError = 0; |
|||||||||||
23 | ||||||||||||
24 | $numberForUrl = $this->getNumberForUrl(); |
|||||||||||
25 | ||||||||||||
26 | while ($exit == false) { |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
27 | switch ($count) { |
|||||||||||
28 | case 0: |
|||||||||||
29 | $numPaginator = 0; |
|||||||||||
30 | break; |
|||||||||||
31 | case 1: |
|||||||||||
32 | $numPaginator = 30; |
|||||||||||
33 | break; |
|||||||||||
34 | case 2: |
|||||||||||
35 | $numPaginator = 80; |
|||||||||||
36 | break; |
|||||||||||
37 | case 3: |
|||||||||||
38 | $numPaginator = 130; |
|||||||||||
39 | break; |
|||||||||||
40 | case 4: |
|||||||||||
41 | $numPaginator = 180; |
|||||||||||
42 | break; |
|||||||||||
43 | default: |
|||||||||||
44 | $numPaginator = 230; |
|||||||||||
45 | break; |
|||||||||||
46 | ||||||||||||
47 | } |
|||||||||||
48 | ||||||||||||
49 | $urlOfSearch = 'https://duckduckgo.com/d.js?q='.urlencode($this->commandData['dork']).'&ct=BR&ss_mkt=us&sp=1&l=wt-wt&vqd='.$numberForUrl.'&p=1&s='.$numPaginator; |
|||||||||||
50 | ||||||||||||
51 | $this->output('Page '.$count."\n"); |
|||||||||||
52 | ||||||||||||
53 | if ($this->commandData['virginProxies']) { |
|||||||||||
54 | $body = Utils::getBodyByVirginProxies($urlOfSearch, $this->listOfVirginProxies[$countProxyVirgin], $this->proxy); |
|||||||||||
55 | ||||||||||||
56 | $arrLinks = $this->getLinks($body); |
|||||||||||
57 | ||||||||||||
58 | if ($this->checkReturnError($body)) { |
|||||||||||
59 | $this->output("You has a problem with proxy, probaly you stress the engenier ...\n"); |
|||||||||||
60 | --$count; |
|||||||||||
61 | ++$countError; |
|||||||||||
62 | if ($countError == 4) { |
|||||||||||
63 | $exit = true; |
|||||||||||
64 | } |
|||||||||||
65 | } else { |
|||||||||||
66 | $countError = 0; |
|||||||||||
67 | } |
|||||||||||
68 | ||||||||||||
69 | //Check if next virgin proxy or repeat of 0 |
|||||||||||
70 | if ($countProxyVirgin == count($this->listOfVirginProxies) - 1) { |
|||||||||||
71 | $countProxyVirgin = 0; |
|||||||||||
72 | } else { |
|||||||||||
73 | ++$countProxyVirgin; |
|||||||||||
74 | } |
|||||||||||
75 | } else { |
|||||||||||
76 | $body = Utils::getBody($urlOfSearch, $this->proxy); |
|||||||||||
77 | ||||||||||||
78 | $arrLinks = $this->getLinks($body); |
|||||||||||
79 | } |
|||||||||||
80 | ||||||||||||
81 | $this->output("\n".$urlOfSearch."\n"); |
|||||||||||
82 | ||||||||||||
83 | $results = $this->sanitazeLinks($arrLinks); |
|||||||||||
84 | ||||||||||||
85 | if ((count($results) == 0 and $body != 'repeat')) { |
|||||||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Using logical operators such as
and instead of && is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. ![]() |
||||||||||||
86 | $exit = true; |
|||||||||||
87 | } |
|||||||||||
88 | ||||||||||||
89 | $resultFinal = array_merge($resultFinal, $results); |
|||||||||||
90 | ||||||||||||
91 | ++$count; |
|||||||||||
92 | } |
|||||||||||
93 | ||||||||||||
94 | return $resultFinal; |
|||||||||||
95 | } |
|||||||||||
96 | ||||||||||||
97 | private function getNumberForUrl() |
|||||||||||
98 | { |
|||||||||||
99 | $firstUrlOfSearch = 'https://duckduckgo.com/?q='.urlencode($this->commandData['dork']).'&search_plus_one=form&ia=web'; |
|||||||||||
100 | $body = Utils::getBody($firstUrlOfSearch, $this->proxy); |
|||||||||||
101 | ||||||||||||
102 | $validXmlrpc = preg_match("/','.*&vqd=(.*?)&/", $body, $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 ![]() |
||||||||||||
103 | ||||||||||||
104 | if (isset($matches[1][0])) { |
|||||||||||
105 | return $matches[1][0]; |
|||||||||||
106 | } |
|||||||||||
107 | ||||||||||||
108 | return false; |
|||||||||||
109 | } |
|||||||||||
110 | ||||||||||||
111 | View Code Duplication | public function sanitazeLinks($links = array()) |
||||||||||
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. ![]() |
||||||||||||
112 | { |
|||||||||||
113 | $hrefs = array(); |
|||||||||||
114 | ||||||||||||
115 | if (!empty($links)) { |
|||||||||||
116 | foreach ($links as $keyLink => $valueLink) { |
|||||||||||
117 | $validResultOfBlackList = Utils::checkBlacklist($valueLink); |
|||||||||||
118 | if (!$validResultOfBlackList and $valueLink) { |
|||||||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Using logical operators such as
and instead of && is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. ![]() |
||||||||||||
119 | $hrefs[] = $valueLink; |
|||||||||||
120 | } |
|||||||||||
121 | } |
|||||||||||
122 | ||||||||||||
123 | $hrefs = array_unique($hrefs); |
|||||||||||
124 | } |
|||||||||||
125 | ||||||||||||
126 | return $hrefs; |
|||||||||||
127 | } |
|||||||||||
128 | ||||||||||||
129 | public function getLinks($body) |
|||||||||||
130 | { |
|||||||||||
131 | $result = []; |
|||||||||||
132 | $validXmlrpc = preg_match("/DDG\.Data\.languages\.resultLanguages', (.*?)\);if/", $body, $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 ![]() |
||||||||||||
133 | ||||||||||||
134 | if (isset($matches[1][0])) { |
|||||||||||
135 | $resultJson = json_decode($matches[1][0]); |
|||||||||||
136 | foreach ($resultJson as $resultsByLanguage) { |
|||||||||||
137 | foreach ($resultsByLanguage as $resultByLanguage) { |
|||||||||||
138 | $result[] = $resultByLanguage; |
|||||||||||
139 | } |
|||||||||||
140 | } |
|||||||||||
141 | } |
|||||||||||
142 | ||||||||||||
143 | return $result; |
|||||||||||
144 | } |
|||||||||||
145 | ||||||||||||
146 | public function checkReturnError($body) |
|||||||||||
147 | { |
|||||||||||
148 | $valid = preg_match("/Dvar q=window\.location\.href\.indexOf/", $body, $matches, PREG_OFFSET_CAPTURE); |
|||||||||||
149 | ||||||||||||
150 | if ($valid) { |
|||||||||||
151 | return true; |
|||||||||||
152 | } |
|||||||||||
153 | ||||||||||||
154 | return false; |
|||||||||||
155 | } |
|||||||||||
156 | } |
|||||||||||
157 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.