마루마루 사이트의 PHP 파싱 파일입니다. fmaru 관련 포팅 자료도 있습니다. (마루마루 사이트가 닫혀서 더 이상 작동하지 않습니다.) https://marumaru.hakase.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

_function.php 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <?php
  2. class Marumaru {
  3. private $httph = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.89 Safari/537.36';
  4. private $fname = 'cookie_hidden.txt';
  5. public function linkencode ($url) {
  6. $ta = parse_url($url);
  7. if (!empty($ta['scheme']))
  8. $ta['scheme'] .= '://';
  9. if (!empty($ta['pass']) and !empty($ta['user']))
  10. {
  11. $ta['user'] = ':';
  12. $ta['pass'] = rawurlencode($ta['pass']).'@';
  13. }
  14. elseif (!empty($ta['user']))
  15. $ta['user'] .= '@';
  16. if (!empty($ta['port']) and !empty($ta['host']))
  17. $ta['host'] = ''.$ta['host'].':';
  18. elseif (!empty($ta['host']))
  19. $ta['host'] = $ta['host'];
  20. if (!empty($ta['path']))
  21. {
  22. $tu = '';
  23. $tok = strtok($ta['path'], "\\/");
  24. while (strlen($tok))
  25. {
  26. $tu .= rawurlencode($tok).'/';
  27. $tok = strtok("\\/");
  28. }
  29. $ta['path'] = '/'.trim($tu, '/');
  30. }
  31. if (!empty($ta['query']))
  32. $ta['query'] = '?'.$ta['query'];
  33. if (!empty($ta['fragment']))
  34. $ta['fragment'] = '#'.$ta['fragment'];
  35. return implode('', array($ta['scheme'], $ta['user'], $ta['pass'], $ta['host'], $ta['port'], $ta['path'], $ta['query'], $ta['fragment']));
  36. }
  37. public function splits($data, $first, $end, $num = 1)
  38. {
  39. $temp = @explode($first, $data);
  40. $temp = @explode($end, $temp[$num]);
  41. $temp = $temp[0];
  42. return $temp;
  43. }
  44. public function WEBParsing($url, $cookie=NULL, $headershow=TRUE, $postparam=NULL, $otherheader=NULL)
  45. {
  46. if (!preg_match('/^(?:https?):\/\//', $url)) return false;
  47. $ch = curl_init();
  48. $url = $this->linkencode($url);
  49. $opts = array(CURLOPT_RETURNTRANSFER => true,
  50. CURLOPT_URL => $url,
  51. CURLOPT_TIMEOUT => 60,
  52. CURLOPT_CONNECTTIMEOUT => 10,
  53. CURLOPT_SSL_VERIFYPEER => FALSE,
  54. CURLOPT_HEADER => $headershow,
  55. CURLOPT_USERAGENT => $this->httph
  56. );
  57. curl_setopt_array($ch, $opts);
  58. if ($otherheader) curl_setopt($ch, CURLOPT_HTTPHEADER, $otherheader);
  59. if ($cookie) curl_setopt($ch, CURLOPT_COOKIE, $cookie);
  60. if ($postparam)
  61. {
  62. curl_setopt($ch, CURLOPT_POST, 1);
  63. curl_setopt($ch, CURLOPT_POSTFIELDS, $postparam);
  64. }
  65. $data = curl_exec($ch);
  66. if (curl_errno($ch))
  67. $this->ErrorEcho(14, 'Connect Error!!!');
  68. curl_close($ch);
  69. return ($data) ? $data : false;
  70. }
  71. /**
  72. * sucuri - sucuri 프록시 관련 쿠키 우회
  73. * 소스 : https://github.com/organization/cloudflare-bypass
  74. * 소스 : http://cafe.naver.com/gogoomas/337647
  75. * @param string $result 쿠키 string 입력
  76. * @return strring 쿠키 데이터 출력
  77. * 사용하지 않음.
  78. */
  79. /*public function sucuri($result)
  80. {
  81. if(strpos($result, 'sucuri_cloudproxy_js') !== false)
  82. {
  83. $cp_temp1 = explode('S=\'', $result);
  84. $cp_temp2 = explode(';', $cp_temp1[1]);
  85. $cp_script = $cp_temp2[0];
  86. $cp_temp1 = explode('A=\'', $result);
  87. $cp_temp2 = explode('\';', $cp_temp1[1]);
  88. $cp_chlist = $cp_temp2[0];
  89. $cp_charr = array();
  90. for($i = 0; $i < 64; $i++)
  91. $cp_charr[$cp_chlist[$i]] = $i;
  92. $cp_len = strlen($cp_script);
  93. $cp_c = 0;
  94. $cp_u = 0;
  95. $cp_i = 0;
  96. $cp_l = 0;
  97. $cp_a = NULL;
  98. $cp_r = NULL;
  99. for($i = 0; $i < $cp_len; $i++)
  100. {
  101. $cp_c = $cp_charr[$cp_script[$i]];
  102. $cp_u = ($cp_u << 6) + $cp_c;
  103. $cp_l += 6;
  104. while($cp_l >= 8)
  105. (($cp_a = ($cp_u >> ($cp_l -= 8)) & 0xff) || ($cp_i < ($cp_len - 2))) && ($cp_r .= chr($cp_a));
  106. }
  107. $cp_temp1 = explode('document.cookie=', $cp_r);
  108. $cp_temp2 = explode('=', $cp_temp1[1]);
  109. $cp_cnam = str_replace('"', '\'', $cp_temp2[0]);
  110. $cp_cnam_split = explode('+', $cp_cnam);
  111. $cp_cnam_split_cnt = count($cp_cnam_split);
  112. $cp_cnam_string = NULL;
  113. for($i = 0 ; $i < $cp_cnam_split_cnt; $i++)
  114. {
  115. $cp_cnam = trim($cp_cnam_split[$i]);
  116. if(strpos($cp_cnam, 'slice') !== false)
  117. {
  118. $cp_temp1 = explode('\'', $cp_cnam);
  119. $cp_temp2 = explode('(', $cp_cnam);
  120. $cp_temp3 = explode(')', $cp_temp2[1]);
  121. $cp_temp4 = explode(',', $cp_temp3[0]);
  122. $cp_cnam_string .= substr($cp_temp1[1], trim($cp_temp4[0]), (intval(trim($cp_temp4[1])-trim($cp_temp4[0]))));
  123. }
  124. elseif(strpos($cp_cnam, 'charAt') !== false)
  125. {
  126. $cp_temp1 = explode('\'', $cp_cnam);
  127. $cp_temp2 = explode('(', $cp_cnam);
  128. $cp_temp3 = explode(')', $cp_temp2[1]);
  129. $cp_cnam_string .= substr($cp_temp1[1], trim($cp_temp3[0]), 1);
  130. }
  131. elseif(strpos($cp_cnam, 'String.fromCharCode') !== false)
  132. {
  133. $cp_temp1 = explode('(', $cp_cnam);
  134. $cp_temp2 = explode(')', $cp_temp1[1]);
  135. if(strpos($cp_temp2[0], '0x') !== false)
  136. $cp_cnam_string .= chr(hexdec($cp_temp2[0]));
  137. else
  138. $cp_cnam_string .= chr($cp_temp2[0]);
  139. }
  140. elseif(strpos($cp_cnam, 'substr') !== false)
  141. {
  142. $cp_temp1 = explode('\'', $cp_cnam);
  143. $cp_temp2 = explode('(', $cp_cnam);
  144. $cp_temp3 = explode(')', $cp_temp2[1]);
  145. $cp_temp4 = explode(',', $cp_temp3[0]);
  146. $cp_cnam_string .= substr($cp_temp1[1], trim($cp_temp4[0]), trim($cp_temp4[1]));
  147. }
  148. else
  149. $cp_cnam_string .= trim(trim($cp_cnam, '\''));
  150. $cp_cnam_string .= NULL;
  151. }
  152. //$cp_temp1 = explode('=', $cp_r);
  153. $cp_temp1 = strpos($cp_r, '=');
  154. $cp_temp2 = explode(';document.cookie', substr($cp_r, $cp_temp1+1)); //$cp_temp[1]
  155. $cp_cval = str_replace('"', '\'', $cp_temp2[0]);
  156. $cp_cval_split = explode('+', $cp_cval);
  157. $cp_cval_split_cnt = count($cp_cval_split);
  158. $cp_cval_string = null;
  159. for($i = 0 ; $i < $cp_cval_split_cnt; $i++)
  160. {
  161. $cp_nval = trim($cp_cval_split[$i]);
  162. if(strpos($cp_nval, 'slice') !== false)
  163. {
  164. $cp_temp1 = explode('\'', $cp_nval);
  165. $cp_temp2 = explode('(', $cp_nval);
  166. $cp_temp3 = explode(')', $cp_temp2[1]);
  167. $cp_temp4 = explode(',', $cp_temp3[0]);
  168. $cp_cval_string .= substr($cp_temp1[1], trim($cp_temp4[0]), (intval(trim($cp_temp4[1])-trim($cp_temp4[0]))));
  169. }
  170. elseif(strpos($cp_nval, 'charAt') !== false)
  171. {
  172. $cp_temp1 = explode("'", $cp_nval);
  173. $cp_temp2 = explode("(", $cp_nval);
  174. $cp_temp3 = explode(")", $cp_temp2[1]);
  175. $cp_cval_string .= substr($cp_temp1[1], trim($cp_temp3[0]), 1);
  176. }
  177. elseif(strpos($cp_nval, 'String.fromCharCode') !== false)
  178. {
  179. $cp_temp1 = explode('(', $cp_nval);
  180. $cp_temp2 = explode(')', $cp_temp1[1]);
  181. if(strpos($cp_temp2[0], '0x') !== false)
  182. {
  183. $cp_cval_string .= chr(hexdec($cp_temp2[0]));
  184. }
  185. else
  186. {
  187. $cp_cval_string .= chr($cp_temp2[0]);
  188. }
  189. }
  190. elseif(strpos($cp_nval, 'substr') !== false)
  191. {
  192. $cp_temp1 = explode('\'', $cp_nval);
  193. $cp_temp2 = explode('(', $cp_nval);
  194. $cp_temp3 = explode(')', $cp_temp2[1]);
  195. $cp_temp4 = explode(',', $cp_temp3[0]);
  196. $cp_cval_string .= substr($cp_temp1[1], trim($cp_temp4[0]), trim($cp_temp4[1]));
  197. }
  198. else
  199. {
  200. $cp_cval_string .= trim(trim($cp_nval, '\''));
  201. }
  202. $cp_cval_string .= NULL;
  203. }
  204. // String Output
  205. return $cp_cnam_string."=".$cp_cval_string;
  206. }
  207. }*/
  208. public function FileRead($filename=NULL)
  209. {
  210. $filename = ($filename) ? $filename : $this->fname;
  211. if(!is_file($filename)) return false;
  212. if(!filesize($filename)) return false;
  213. $fp = fopen($filename, 'r');
  214. $data = fread($fp, filesize($filename));
  215. fclose($fp);
  216. return $data;
  217. }
  218. public function FileWrite($str,$filename=NULL,$time=(60*30))
  219. {
  220. $filename = ($filename) ? $filename : $this->fname;
  221. $fp = fopen($filename, 'w');
  222. // 30분
  223. fwrite($fp, time()+$time.PHP_EOL.$str);
  224. fclose($fp);
  225. }
  226. public function GetCookie()
  227. {
  228. /*$data = $this->WEBParsing('http://wasabisyrup.com/archives/');
  229. $cookie = $this->splits($data, '<script>', '</script>');
  230. $cookie = $this->sucuri($cookie);*/
  231. $data = $this->WEBParsing('http://wasabisyrup.com/archives/455742', $cookie, true, 'pass=qndxkr',
  232. array(
  233. 'Referer: http://wasabisyrup.com/'
  234. )
  235. );
  236. $cookie = $this->splits($data, 'Set-Cookie: PHPSESSID=', ';');
  237. $cookie = 'PHPSESSID=' . $cookie . ';';
  238. if(!$cookie) return false; else return $cookie;
  239. }
  240. public function ErrorEcho($num,$err=NULL)
  241. {
  242. if($err)
  243. die(json_encode(array('error'=>$num, 'message'=>$err)));
  244. else
  245. {
  246. switch($num)
  247. {
  248. case 0:
  249. $err='Connect Error (wasabisyrup 403 or other error)';
  250. break;
  251. case 1:
  252. $err='Cookie Send Error (Not applied sucuri cookie data)';
  253. break;
  254. case 2:
  255. $err='Cookie Get Error';
  256. break;
  257. case 3:
  258. $err='Password Error (Protected archive) - Retry 10 minutes after view or retry about 3 times';
  259. break;
  260. case 4:
  261. $err='Not found comics data';
  262. break;
  263. default:
  264. $err='Unknown Error. Please send me an e-mail (hakase@hakase.io)';
  265. }
  266. die(json_encode(array('error'=>$num, 'message'=>$err)));
  267. }
  268. }
  269. }