ByetHost server passes "Check your browser" html values โ€‹โ€‹using JSON String

When trying to parse a json string for android, HTML values โ€‹โ€‹are passed. Until the day everything worked fine, and suddenly my application crashed when trying to get the database using php files.

When I checked, I noticed that the html values โ€‹โ€‹.. see logcat

08-10 01:09:55.814: E/result(6744): <html><body><h2>Checking your browser..<h2><script type="text/javascript" src="/aes.js" ></script><script>function toNumbers(d){var e=[];d.replace(/(..)/g,function(d){e.push(parseInt(d,16))});return e}function toHex(){for(var d=[],d=1==arguments.length&&arguments[0].constructor==Array?arguments[0]:arguments,e="",f=0;f<d.length;f++)e+=(16>d[f]?"0":"")+d[f].toString(16);return e.toLowerCase()}var a=toNumbers("f655ba9d09a112d4968c63579db590b4"),b=toNumbers("98344c2eee86c3994890592585b49f80"),c=toNumbers("7965e114a1dccaf35af3756261f75ad8");document.cookie="__test="+toHex(slowAES.decrypt(c,2,a,b))+"; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/";location.href="http://realroom.byethost24.com/medical/stokist.php?ckattempt=1";</script></body></html> 08-10 01:09:55.814: E/JSON Parser(6744): Error parsing data org.json.JSONException: Value <html><body><h2>Checking of type java.lang.String cannot be converted to JSONObject 08-10 01:09:55.816: E/AndroidRuntime(6744): FATAL EXCEPTION: AsyncTask #1 08-10 01:09:55.816: E/AndroidRuntime(6744): Process: com.example.medionline, PID: 6744 08-10 01:09:55.816: E/AndroidRuntime(6744): java.lang.RuntimeException: An error occured while executing doInBackground() 08-10 01:09:55.816: E/AndroidRuntime(6744): at android.os.AsyncTask$3.done(AsyncTask.java:304) 08-10 01:09:55.816: E/AndroidRuntime(6744): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355) 08-10 01:09:55.816: E/AndroidRuntime(6744): at java.util.concurrent.FutureTask.setException(FutureTask.java:222) 08-10 01:09:55.816: E/AndroidRuntime(6744): at java.util.concurrent.FutureTask.run(FutureTask.java:242) 08-10 01:09:55.816: E/AndroidRuntime(6744): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 08-10 01:09:55.816: E/AndroidRuntime(6744): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 08-10 01:09:55.816: E/AndroidRuntime(6744): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 08-10 01:09:55.816: E/AndroidRuntime(6744): at java.lang.Thread.run(Thread.java:818) 08-10 01:09:55.816: E/AndroidRuntime(6744): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.json.JSONObject.toString()' on a null object reference 08-10 01:09:55.816: E/AndroidRuntime(6744): at com.example.medionline.All_supplier_list$FetchMFG.doInBackground(All_supplier_list.java:182) 08-10 01:09:55.816: E/AndroidRuntime(6744): at com.example.medionline.All_supplier_list$FetchMFG.doInBackground(All_supplier_list.java:1) 08-10 01:09:55.816: E/AndroidRuntime(6744): at android.os.AsyncTask$2.call(AsyncTask.java:292) 08-10 01:09:55.816: E/AndroidRuntime(6744): at java.util.concurrent.FutureTask.run(FutureTask.java:237) 08-10 01:09:55.816: E/AndroidRuntime(6744): ... 4 more 

This happens with all the pages that I hosted on the byethost server, and the pages hosted on another server work well and well. I tried moving one of my files to another server and that it returns the correct json string.

Also, when I check the URL in the browser, it returns the correct json string without any exceptions or errors with byethost .., but in android with html values.

Here is my JSON function class

 package com.example.medionline; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.util.List; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.impl.client.DefaultHttpClient; import org.json.JSONException; import org.json.JSONObject; import android.util.Log; public class JSONfunctions { static InputStream is = null; static String result = ""; static JSONObject jArray = null; public static JSONObject getJSONfromURL(String url) { // Download JSON data from URL try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); httppost.setHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240 "); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = entity.getContent(); } catch (Exception e) { Log.e("log_tag", "Error in http connection " + e.toString()); } try { BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { Log.e("jsonnnnnnn", line); sb.append(line + "\n"); } is.close(); result = sb.toString(); Log.e("result", result); } catch (Exception e) { Log.e("log_tag", "Error converting result " + e.toString()); } try { jArray = new JSONObject(result); } catch (JSONException e) { Log.e("log_tag", "Error parsing data " + e.toString()); } return jArray; } public static JSONObject makeHttpRequest(String loginUrl, String post, List<NameValuePair> para) { try { if(post == "POST") { HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(loginUrl); httpPost.setEntity(new UrlEncodedFormEntity(para)); httpPost.setHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240 "); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } else if(post == "GET") { HttpClient httpClient = new DefaultHttpClient(); String paramString = URLEncodedUtils.format(para, "utf-8"); loginUrl += "?" + paramString; HttpGet httpGet = new HttpGet(loginUrl); HttpResponse httpResponse = httpClient.execute(httpGet); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { BufferedReader reader = new BufferedReader(new InputStreamReader(is, "utf-8"), 8); StringBuilder sb = new StringBuilder(); String line = null; if (is != null) { while ((line = reader.readLine()) != null) { //Log.e("jsonnnnnnn", line); sb.append(line + "\n"); } is.close(); result = sb.toString(); Log.e("result", result); } } catch (Exception e) { Log.e("Buffer Error", "Error converting result " + e.toString()); } try { jArray = new JSONObject(result); } catch (JSONException e) { Log.e("JSON Parser", "Error parsing data " + e.toString()); } return jArray; } } 

And this is my php file

 <?php include('config.php'); date_default_timezone_set("Asia/Calcutta"); $result1 = mysqli_query($con,"SELECT * FROM `pj_medionline_mst_stockist` ORDER BY `pj_medionline_mst_stockist`.`ID` ASC "); $response = array(); $posts = array(); while($row=mysqli_fetch_array($result1)) { $id =$row["ID"]; $stkcode =$row["stkcode"]; $comName =$row["ComName"]; $operatorid =$row["operatorid"]; $password =$row["Password"]; $posts[] = array('id'=>$id, 'stkcode'=>$stkcode, 'stkname'=>$comName, 'operatorid'=>$operatorid, 'password'=>$password); } $response['stokist'] = $posts; print(json_encode($response)); ?> 
+7
json android php
source share
4 answers

I should add the following as an answer, since a workaround is getting around this problem. Posting as this may help someone:

This problem can be solved by simply writing exit (); in the php file in the last executable statement. This will exit the php file and not add text. eg.

 <?php include('config.php'); date_default_timezone_set("Asia/Calcutta"); $result1 = mysqli_query($con,"SELECT * FROM `pj_medionline_mst_stockist` ORDER BY `pj_medionline_mst_stockist`.`ID` ASC "); $response = array(); $posts = array(); while($row=mysqli_fetch_array($result1)) { $id =$row["ID"]; $stkcode =$row["stkcode"]; $comName =$row["ComName"]; $operatorid =$row["operatorid"]; $password =$row["Password"]; $posts[] = array('id'=>$id, 'stkcode'=>$stkcode, 'stkname'=>$comName, 'operatorid'=>$operatorid, 'password'=>$password); } $response['stokist'] = $posts; print(json_encode($response)); exit(); ?> 
0
source share

Solved!

I had the same problem using Byethost to retrieve JSON data from my PHP server. We just need to add the cookie to the HTTP request in order to pass the testcookie-nginx module

Richard's answer says:

The main problem is that Byet Host implements a simple anti-virus protection module> named testcookie-nginx-module

https://kyprizel.imtqy.com/testcookie-nginx-module/

From the link that he provided, we see that the testcookie-nginx module does a 2-step check:

  • The first time the HTTP request is completed, the module returns javascript instead of the expected JSON. This script runs on the client (typically a web browser) and generates a validation cookie containing the AES key.

Here's the script I got my server form:

 <html> <body> <script type="text/javascript" src="/aes.js" ></script> <script> function toNumbers(d){ var e=[]; d.replace(/(..)/g,function(d){ e.push(parseInt(d,16))}); return e } function toHex(){ for(var d=[],d=1==arguments.length&&arguments[0].constructor==Array?arguments[0]:arguments,e="",f=0;f<d.length;f++) e+=(16>d[f]?"0":"")+d[f].toString(16); return e.toLowerCase() } var a=toNumbers("f655ba9d09a112ffff8c63579db590b4"), b=toNumbers("98344c2eee86c3ffff90592585b49f80"), c=toNumbers("1286963467aa92ffff8323bdca0d7be9"); document.cookie="__test="+toHex(slowAES.decrypt(c,2,a,b))+"; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/"; location.href="http://myserver.byethost8.com/myPhpPage.php?i=1"; </script> <noscript>This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support</noscript> </body> 

  1. The script adds the validation cookie to the document and redirects it to the URL that we really want to access. The testcookie-nginx module checks the AES key of the cookie and allows the request to get a URL that will respond to the JSON data that we want to access.

In the following HTTP requests, the client will save the cookie and add it to the request, skipping step 1.

Solution for our Android app

We are going to skip the creation of the cookie by receiving it from a web browser and add it directly to our HTTP request for Android (unless, of course, you want to participate in creating it).

Before you receive a cookie from a web browser, make sure that you have accessed the URL at least once so that the browser creates it.

  • Retrieving a cookie key from a web browser. I used Google Chrome for this:

    • From the Chrome menu in the upper right corner of your browser, select "Settings."
    • At the bottom of the page, click "Show advanced options."
    • In the "Privacy" section, select "Content Settings."
    • select all cookies and site data ....
    • Find the name of your site. Looking through "byethost" you will find it.
    • Open a cookie called __test and copy the content values, path and expiration date
  • Setting a cookie in our Android app. Your code should have something like:

     try { if(post == "POST") { HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(loginUrl); httpPost.setEntity(new UrlEncodedFormEntity(para)); httpPost.setHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240 "); httpPost.addHeader("Cookie", "__test=THE_CONTENT_OF_YOUR_COOKIE_HERE; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/"); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } else if(post == "GET") { HttpClient httpClient = new DefaultHttpClient(); String paramString = URLEncodedUtils.format(para, "utf-8"); loginUrl += "?" + paramString; HttpGet httpGet = new HttpGet(loginUrl); httpGet.addHeader("Cookie", "__test=THE_CONTENT_OF_YOUR_COOKIE_HERE; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/"); HttpResponse httpResponse = httpClient.execute(httpGet); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } } 

What is it. Now, every time the application makes an HTTP request, it will contain a cookie to transfer the testcookie-nginx module and will retrieve your JSON data.

I hope this helps and not too late.

Hi

+14
source share

The main problem is that Byet Host implements a simple security protection module called testcookie-nginx-module

https://kyprizel.imtqy.com/testcookie-nginx-module/

This will cause the application to crash.

+3
source share

This is a new bot detection feature on free hosting to prevent unwanted bots. This appears only on the first visit to the page.

For example, / upper_respiratory_infection.htm? Ckattempt = 1 has registered 37 times with my web analytics from August 8 to August 11. This creates chaos with my web analytics, since now I collect two sets of data for each page (one with one and without CKattempt = 1, and some even with the addition of CKattempt = 2)

Sorry, this cannot be removed.

for more details

0
source share

All Articles