esp8266 byethost Error get request

2019-09-17 16:17发布

Good morning, I want to send data by get through esp8266, I have a qualifying account in byethost and I also have a hosting account paid with another hosting provider, but with byethost I get the following error:

AT+CIPSTART="TCP","ahorrodeenergy.byethost17.com",80
AT+CIPSEND=67
GET /inserta.php HTTP/1.1 
Host:ahorrodeenergy.byethost17.com/inserta.php"



+IPD,1080:HTTP/1.1 200 OK
Server: nginx
Date: Fri, 10 Mar 2017 01:30:09 GMT
Content-Type: text/html
Content-Length: 851
Connection: keep-alive
Vary: Accept-Encoding
Expires: THu, 01 Jan 1970 00:00:01 GMT
Cache-Control: no-cache

And returns: This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support

标签: nginx esp8266
2条回答
别忘想泡老子
2楼-- · 2019-09-17 16:59

Spoof the User-Agent string. It probably tries to identify your browser by that, and then tries to figure out if you have JavaScript enabled. It could then try to use more active tests, like inserting a piece of JavaScript and expect a page to be called with the result of the computation of that javascript, in a challenge-and-response manner. But I think a User-Agent spoof should just work fine. Do the following:

AT+CIPSTART="TCP","ahorrodeenergy.byethost17.com",80
AT+CIPSEND=154
GET /inserta.php HTTP/1.1 
Host: ahorrodeenergy.byethost17.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0


+IPD,1080: ..

(number in CIPSEND assumes \r\nbeing used as newline)

查看更多
劳资没心,怎么记你
3楼-- · 2019-09-17 17:22

Based on the this awnser, the problem is testcookie-nginx-module which is used by byethost, and here the solution:

/*
  Author: Moien007
  Source: https://gist.github.com/moien007/06656aa4032c45b629a507dd4dcb6fd6
  Description:
  Bypass testcookie-nginx-module bot protection
  Web host providers like Byethost uses that module so...
*/

using System;
using System.Linq;
using System.Threading.Tasks;
using System.Security.Cryptography;
using System.Net;
using System.Net.Http;

namespace Gist
{
    class CustomWebClient
    {
        const string TestCookieSign = "aes.js";

        public static byte[] Get(string url)
        {
            var address = new Uri(url);
            var cookieContainer = new CookieContainer();
            using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer })
            using (var client = new HttpClient(handler))
            {
                var content = client.GetAsync(address).WaitResult().Content;
                var script = content.ReadAsStringAsync().WaitResult();

                if (!script.Contains(TestCookieSign))
                {
                    return content.ReadAsByteArrayAsync().WaitResult();
                }

                var test = Decrypt(script);
                cookieContainer.Add(new Cookie("__test", test) { Domain = address.Host });

                content = client.GetAsync(address).WaitResult().Content;
                if (content.ReadAsStringAsync().WaitResult().Contains(TestCookieSign))
                {
                    throw new Exception();
                }

                return content.ReadAsByteArrayAsync().WaitResult();
            }
        }

        public static byte[] Post(string url, byte[] data)
        {
            var address = new Uri(url);
            var cookieContainer = new CookieContainer();
            using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer })
            using (var client = new HttpClient(handler))
            using (var post = new ByteArrayContent(data))
            {
                var content = client.PostAsync(address, post).WaitResult().Content;
                var script = content.ReadAsStringAsync().WaitResult();

                if (!script.Contains(TestCookieSign))
                {
                    return content.ReadAsByteArrayAsync().WaitResult();
                }

                var test = Decrypt(script);
                cookieContainer.Add(new Cookie("__test", test) { Domain = address.Host });

                content = client.PostAsync(address, post).WaitResult().Content;
                if (content.ReadAsStringAsync().WaitResult().Contains(TestCookieSign))
                {
                    throw new Exception();
                }

                return content.ReadAsByteArrayAsync().WaitResult();
            }
        }

        static string Decrypt(string script)
        {
            var split = script.Split(new[] { "toNumbers(\"", "\")" }, StringSplitOptions.RemoveEmptyEntries)
                        .Where(s => s.Length == 32)
                        .ToArray();

            if (split.Length != 3)
                throw new Exception();

            var key = StringToByteArray(split[0]);
            var iv = StringToByteArray(split[1]);
            var bytesIn = StringToByteArray(split[2]);

            var aes = Aes.Create();
            aes.Padding = PaddingMode.None;
            aes.Mode = CipherMode.CBC;
            aes.BlockSize = 128;
            aes.KeySize = 128;
            aes.Key = key;
            aes.IV = iv;

            var decrypter = aes.CreateDecryptor();
            var decrypted = decrypter.TransformFinalBlock(bytesIn, 0, bytesIn.Length);

            decrypter.Dispose();
            aes.Dispose();

            return BitConverter.ToString(decrypted).Replace("-", "").ToLower();
        }

        static byte[] StringToByteArray(string hex) // Taken from https://stackoverflow.com/a/321404/9248173
        {
            return Enumerable.Range(0, hex.Length)
                             .Where(x => x % 2 == 0)
                             .Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
                             .ToArray();
        }
    }

    static class ExtensionMethods
    {
        public static T WaitResult<T>(this Task<T> task)
        {
            task.Wait();
            return task.Result;
        }
    }
}
查看更多
登录 后发表回答