📜 ⬆️ ⬇️

We send “anonymous” SMS from the Console to the desired number using the bytehand service and C ++

Sometimes it becomes necessary to send an anonymous message to the right addressee without using your phone or when you have only a computer, a working Internet and an open console.

In many films there is a moment when a hacker who is breaking into a person needs to send a message to his number in order to distract him or scare him and in such situations the most important thing is that when a person calls the number from which the SMS came, the screen of the smartphone did not light up and not music played. Oops ... awkward situation. In this topic, we will write a program in C ++, which will allow you to send SMS without using your number, SIM card and soul.

Mr. Robot TV Show

The word “Anonymity” implies that someone who sent the message is not really recognized, but not so well. During the trial, this fact will become clear, so that with particularly serious gags I will not come to visit you at the test.
')
A warning. The task could be solved in easier ways. This topic provides one of the solutions in the c ++ language.

Let's get down to business.

The bytehand service is a business solution that allows you to do both mass mailings and single messages. The main feature of the service and why I chose it is accessible from all API platforms, which is an HTTP Request-Response with a very simple authorization system.

Here is what we need:


First of all we are registering on the bytehand service. Registration is the entered e-mail and password. This is already enough. After that, your account is created and when replenishing the account (at least 100 rubles) you can already send messages with the heading SMS-INFO. For most operators, this entry is replaced by the item number. You can come up with your own text alias if you like.

Further we climb in resource API. And we see that in order to send SMS you just need to form the following data packet:

POST /v2/sms/messages HTTP/1.1 Host: api.bytehand.com Connection: close Content-Length: * Content-Type: application/json;charset=UTF-8 X-Service-Key: ab4db0b982dcd0ba63e44191e5d71ef8 { "sender": "MyShop", "receiver": "+79167654321", "text": "Today only! 20% off for all goods!!" } 

I draw your attention to the fact that the X-Service-Key in the http header is all authorization. This key can be viewed in the settings on the website in the “Security” section.

I think everything is clear here and you can start writing a console program in c ++

First of all, I present to your attention the code snippet that, using Boost.Asio, establishes a connection to the site using the https protocol

 //   Boost #include <boost/asio.hpp> #include <boost/asio/ssl.hpp> #include <boost/bind.hpp> // --------------------------- // ---------- Include OpenSSL Lib ---------- #pragma comment (lib, "libeay32.lib") #pragma comment (lib, "ssleay32.lib") // ----------------------------------------- using namespace boost::asio; //    bool verify_certificate(bool preverified, boost::asio::ssl::verify_context& ctx) { X509* cert = X509_STORE_CTX_get_current_cert(ctx.native_handle()); return preverified; } int main() { io_service service; // ,    /*------------------------------------------------------------ -     - ------------------------------------------------------------*/ ip::tcp::resolver resolver(service); ip::tcp::resolver::query query("api.bytehand.com", "https"); ip::tcp::resolver::iterator iterator = resolver.resolve(query); ssl::context context(boost::asio::ssl::context::sslv23); context.load_verify_file("dh2048.pem"); ssl::stream<ip::tcp::socket> socket_(service, context); socket_.set_verify_mode(ssl::context::verify_none); socket_.set_verify_callback(boost::bind(verify_certificate, _1, _2)); connect(socket_.lowest_layer(), iterator); socket_.handshake(boost::asio::ssl::stream_base::client); //        socket_.write_some() } 

The code uses a link to the dh2048.pem certificate file. You replace it with your own.
You can also see that the domain name api.bytehand.com is used as the server here.

Further, an example of how the header and the body of the http request for the server is formed.

 int main() { /*  ,       https */ //            //       string number = "+79180000000"; string signature = "SMS-INFO"; string text = "Today only! 20% off for all goods!!"; std::stringstream request_; //     char sockBuffer[8192]; //      //     ,       Content-Length string reqTmp = "{\"sender\": \"" + signature + "\",\"receiver\": \"" + number + "\",\"text\": \"" + text + "\"}\r\n"; request_ << "POST /v2/sms/messages HTTP/1.1\r\n"; request_ << "Host: api.bytehand.com\r\n"; request_ << "Connection: close\r\n"; request_ << "Content-Length: " << reqTmp.length() << "\r\n"; request_ << "Content-Type: application/json;charset=UTF-8\r\n"; request_ << "X-Service-Key: ab4db0b982dcd0ba63e44191e5d71ef8\r\n"; request_ << "\r\n"; request_ << reqTmp; //     socket_.write_some(buffer(request_.str())); memset(sockBuffer, NULL, 8192); //       socket_.read_some(buffer(boost::asio::buffer(sockBuffer))); //     cout << endl << endl << sockBuffer << endl; } 

I remind you that you replace the X-Service-Key field with your key.

After executing this code and if everything went as it should, the server returns the answer:

 Status Code: 200 Content-Type: application/json;charset=UTF-8 Content-Language: en Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache { "result": "created", "count": 1 } 

At this point, money is deducted from your account for sending a message. And the message goes to the addressee. When he receives it, it will be a company number or a text identifier and it is unlikely that a person will understand from whom this message was.

This is what happened with me when writing this program:

Myprogram

It turned out clumsy, but that is. Good luck to everyone, maybe this topic has helped you.

This was my second article here. Thanks for reading. Good luck in developing your applications.

Source: https://habr.com/ru/post/419165/


All Articles