📜 ⬆️ ⬇️

Anonymous browser do it yourself or Hide your ass yourself

Introduction

This small topic will tell you how to quickly and easily create your browser, with a few extras that will help us stay anonymous in the network. Qt will do all the hard work for us, namely its QtWebKit module. We will only add lines to the right places that replace the http-headers of our http-requests. This will allow you to remain anonymous when passively analyzing http requests. We will also redefine the navigator, which allows us to remain anonymous for javascript-s with active identification. For definiteness, we will designate the basic parameters with which we can be identified in the network - that’s what we’ll replace them for. The first is of course the IP address, everything is simple - we use a proxy. The second is any http-request headers (the user-agent will be most interesting: its value should be replaced both in http-request headers and in javascript checking). We also implement the ability to edit and substitute your cookies for certain sites, since there is such an opportunity. And we will supplement all this with the built-in editor for the substituted parameters with the possibility of saving them for later use.

We take the QWebView class as the basis for our browser, which will take over the work of loading and displaying any web pages.

QWebView* pView = new QWebView;
pView->load(url);


In order to have access to all requests that pView forms, define our QBotNetworkAccessManager class inherited from QNetworkAccessManager, create an object of this class and set it as a NetworkManager for pView.

m_NetManage = new QBotNetworkAccessManager;
pView->page()->setNetworkAccessManager(m_NetManage);


Install a proxy through which NetworkManager will work and, accordingly, our browser:
')
//pProxiEdit – IP:Port
QRegExp rx("^\\d{1,3}.\\d{1,3}.\\d{1,3}.\\d{1,3}:\\d{2,}$")
QString sProxiIP, sPRoxiPort, sTmp;
sTmp = pProxiEdit->text();
if(rx.indexIn(sTmp, 0) != -1) {
int pos = sTmp.indexOf(":");
sProxiIP = sTmp.mid(0, pos);
sPRoxiPort = sTmp.mid(pos + 1, sTmp.size() - pos - 1);
QNetworkProxy* proxy = new QNetworkProxy(QNetworkProxy::HttpProxy, sProxiIP, sPRoxiPort.toUInt());
m_NetManage->setProxy(*proxy);
}


Changing HTTP request headers

Access to http requests generated by our browser is in the function

QNetworkReply * QNetworkAccessManager::createRequest ( Operation op, const QNetworkRequest & req, QIODevice * outgoingData = 0 ) [virtual protected]

which we need to redefine in our QBotNetworkAccessManager class.
Override it like this:

QNetworkReply * QBotNetworkAccessManager::createRequest ( Operation op, const QNetworkRequest & req, QIODevice * outgoingData) {
QNetworkRequest myReq(req);// QNetworkRequest & req
// http-
myReq.setRawHeader("User-Agent", sUA.toUtf8());
// ...
return QNetworkAccessManager::createRequest( op, myReq, outgoingData);
}


This way you can implement the substitution of any http-request headers sent by our browser to the headers we need.
Now, it is necessary that the javascript-s, our browser is also determined as necessary. To do this, before downloading the next page, edit the javascript by changing it so that it sends the information we need to the server. To do this, when changing the appearance of the page, we will override the navigator as shown below by running javascript:

QString sUA = "MY_USER_AGENT";
...
connect(pView, SIGNAL(urlChanged(const QUrl&)), this, SLOT(OnUrlChanged(const QUrl&)));
...
void MainWindow::OnUrlChanged(const QUrl& url) {
QString jScript = QString("var navigator = new Object; navigator.appName = '%1';").arg(sUA);
pUrlEdit->setText(url.toString());
pView->page()->mainFrame()->evaluateJavaScript(jScript);
}


We perform the same function before loading the page:

...
OnUrlChanged(url);
pView->load(url);
...


Now javascript is seen as in the analysis of http headers.
image

Working with cookies

Save cookies and other information (in this case, only the cookie and user-agent will be) will be in the form of a vector of structures defined below:

struct SDataArhive {
QByteArray BaseItemText;
QMap<QByteArray, QByteArray> ChItemText;
};
QVector vDataArhive;

cookie user-agent- :

QList ListCookies;
// cookie
ListCookies = pView->page()->networkAccessManager()->cookieJar()->cookiesForUrl(pView->url());
QByteArray sByteAr = "";
SDataArhive strTmp
// cookie QByteArray,
//
for(int i = 0; i < ListCookies.size(); i++) {
sByteAr += ListCookies[i].name();
sByteAr += "=";
sByteAr += ListCookies[i].value();
if(i < (ListCookies.size() - 1)){
sByteAr += "\n";
}
}
strTmp.ChItemText.insert("cookie", sByteAr);
//----------------------------------------
// User-Aget
sByteAr = sUA.toUtf8();
strTmp.ChItemText.insert("user-agent", sByteAr);
//--------------------------------------
vDataArhive.append(strTmp);

cookie . , .
image

, cookie, :

// QByteArray cookie
QByteArray tmp = vDataArhive[IdxTop].ChItemText[dataIdx];
// QByteArray cookie
QList ListData = tmp.split('\n');
QList ListCookies;
if(!ListData.isEmpty()) {
for(int i = 0; i < ListData.size(); i++) {
QList cooka = ListData[i].split('=');
if(cooka.size() == 2) {
ListCookies.push_back(QNetworkCookie(cooka[0], cooka[1]));
}
}
if(!ListCookies.isEmpty()){
// cookie
pView->page()->networkAccessManager()->cookieJar()->setCookiesFromUrl(ListCookies ,pView->url());
}
}
// user-agent
sUA = vDataArhive[IdxTop].ChItemText["user-agent"];

: .

PS www.free-lance.ru
, Qt www.prog.org.ru .

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


All Articles