3 ini_set('display_errors', 1);
4 ini_set('display_startup_errors', 1);
5 error_reporting(E_ALL);
7 include_once('/var/www/secure.php'); //outside webserver
10 function cut_part_out($start,$end,$whole){
11 $parts = explode($start,$whole);
12 $subparts = explode($end,$parts[1]);
17 function MVgetPage($url,$cookie,$post){
18 // spoof https://topic.alibabacloud.com/a/php-curl-fake-ip-address-and-header-information-code-instance_1_34_10139121.html
19 $randIP = "".mt_rand(0,255).".".mt_rand(0,255).".".mt_rand(0,255).".".mt_rand(0,255);
20 $headers['CLIENT-IP'] = $randIP;
21 $headers['X-FORWARDED-FOR'] = $randIP;
23 foreach( $headers as $n => $v ) {
24 $headerArr[] = $n .':' . $v;
27 $url = str_replace('[month]',date('F'),$url); // replace month January through December
28 $url = str_replace('[day]',date('j'),$url); // replace day 1 to 31
29 $url = str_replace('[yesterday]',date('j',strtotime('yesterday')),$url); // replace day 1 to 31
30 $url = str_replace('[year]',date('Y'),$url); // replace year Examples: 1999 or 2003
32 curl_setopt ($curl, CURLOPT_URL
, $url);
33 curl_setopt ($curl, CURLOPT_USERAGENT
, sprintf("McGuire MEPS https://www.md-petition.com/ /%d.0",rand(4,50)));
34 curl_setopt ($curl, CURLOPT_RETURNTRANSFER
, 1);
35 curl_setopt ($curl, CURLOPT_HEADER
, 1);
37 curl_setopt ($curl, CURLOPT_HTTPHEADER
, $headerArr ); //Structure IP
38 curl_setopt ($curl, CURLOPT_REFERER
, $url); //Structure
40 curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER
, 0);
41 curl_setopt ($curl, CURLOPT_FOLLOWLOCATION
, true);
43 curl_setopt ($curl, CURLOPT_HTTPHEADER
, array("Cookie: ASP.NET_SessionId=$cookie")); // use cookies
47 'upload_file' => '@file_to_upload.png',
48 'upload_text' => '@text_to_upload'
52 curl_setopt ($curl, CURLOPT_POSTFIELDS
, $post);
54 $html = curl_exec ($curl);
59 function md_voter_lookup($SearchFirstName,$SearchLastName,$DOBMonth,$DOBDay,$DOBYear,$SearchZipCode,$SearchHouseNumber,$SearchMiddleInitial){
61 $post['ctl00$MainContent$btnSearch'] = "Search";
62 $post['btnSearch'] = "Search";
63 $post['ctl00$MainContent$listLanguages'] = "en";
64 $post['listLanguages'] = "en";
65 if ($SearchFirstName == ''){
66 return 'MISSING NAME';
68 $post['ctl00$MainContent$txtSearchFirstName'] = $SearchFirstName;
69 $post['txtSearchFirstName'] = $SearchFirstName;
70 $post['ctl00$MainContent$txtSearchLastName'] = $SearchLastName;
71 $post['txtSearchLastName'] = $SearchLastName;
72 $post['ctl00$MainContent$txtDOBMonth'] = $DOBMonth;
73 $post['txtDOBMonth'] = $DOBMonth;
74 $post['ctl00$MainContent$txtDOBDay'] = $DOBDay;
75 $post['txtDOBDay'] = $DOBDay;
76 $post['ctl00$MainContent$txtDOBYear'] = $DOBYear;
77 $post['txtDOBYear'] = $DOBYear;
78 $post['ctl00$MainContent$txtSearchZipCode'] = $SearchZipCode;
79 $post['txtSearchZipCode'] = $SearchZipCode;
80 $post['ctl00$MainContent$txtSearchHouseNumber'] = $SearchHouseNumber;
81 $post['txtSearchHouseNumber'] = $SearchHouseNumber;
82 $post['ctl00$MainContent$txtSearchMiddleInitial'] = $SearchMiddleInitial;
83 $post['txtSearchMiddleInitial'] = $SearchMiddleInitial;
84 // start a session to get a cookie
85 $form['url'] = 'https://voterservices.elections.maryland.gov/VoterSearch';
86 $form['html'] = MVgetPage($form['url'],'','');
87 // extract the cookie from the header (see CURLOPT_HEADER)
88 $cookie = cut_part_out('ASP.NET_SessionId=',';',$form['html']);
89 // extract the form elements we will need to post with our data
90 $post['__VIEWSTATE'] = cut_part_out('id="__VIEWSTATE" value="','"',$form['html']);
91 $post['__VIEWSTATEGENERATOR'] = cut_part_out('id="__VIEWSTATEGENERATOR" value="','"',$form['html']);
92 $post['__VIEWSTATEENCRYPTED'] = cut_part_out('id="__VIEWSTATEENCRYPTED" value="','"',$form['html']);
93 $post['__EVENTVALIDATION'] = cut_part_out('id="__EVENTVALIDATION" value="','"',$form['html']);
94 $result['html'] = MVgetPage($form['url'],$cookie,$post);
95 //echo "<h1>STEP 2: SBE RESULTS</h1>";
96 $return['debug'] = htmlspecialchars($result['html']);
97 $return['html'] = $result['html'];
98 $html = $petition->real_escape_string($result['html']);
99 $petition->query("INSERT INTO `RemoteVoterList` (`date_validated`, `txtSearchFirstName`, `txtSearchLastName`, `txtDOBMonth`, `txtDOBDay`, `txtDOBYear`, `txtSearchZipCode`, `txtSearchHouseNumber`, `txtSearchMiddleInitial`, `sbe_response`)
100 VALUES (now(), '$SearchFirstName', '$SearchLastName', '$DOBMonth', '$DOBDay', '$DOBYear', '$SearchZipCode', '$SearchHouseNumber', '$SearchMiddleInitial', '$html')");
101 return $result['html'];
104 if (isset($_POST['SearchFirstName'])){
105 $voter = md_voter_lookup($_POST['SearchFirstName'],$_POST['SearchLastName'],$_POST['DOBMonth'],$_POST['DOBDay'],$_POST['DOBYear'],$_POST['SearchZipCode'],$_POST['SearchHouseNumber'],$_POST['SearchMiddleInitial']);
112 <td>SearchFirstName</td><td><input name='SearchFirstName'></td>
115 <td>SearchLastName</td><td><input name='SearchLastName'></td>
118 <td>DOBMonth</td><td><input name='DOBMonth'></td>
121 <td>DOBDay</td><td><input name='DOBDay'></td>
124 <td>DOBYear</td><td><input name='DOBYear'></td>
127 <td>SearchZipCode</td><td><input name='SearchZipCode'></td>
130 <td>SearchHouseNumber*</td><td><input name='SearchHouseNumber'></td>
133 <td>SearchMiddleInitial*</td><td><input name='SearchMiddleInitial'></td>
136 <td>*Optional</td><td><input type='submit'></td>