Vehicle consultation by the Board on the site sinesp via PHP - without captcha

Asked

Viewed 23,448 times

12

Someone managed to query Sinesp, via php ? I’m trying to get this code to work but without success.

  $placa   = 'KCK2486';
  $request = '<?xml version="1.0" encoding="utf-8" standalone="yes" ?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ><soap:Header><dispositivo>GT-S1312L</dispositivo><nomeSO>Android</nomeSO><versaoAplicativo>1.1.1</versaoAplicativo><versaoSO>4.1.4</versaoSO><aplicativo>aplicativo</aplicativo><ip>177.206.169.90</ip><token>5021719229f7ddad0c786542da534ad0375f021f</token><latitude>-3.6770324</latitude><longitude>-38.6791411</longitude></soap:Header><soap:Body><webs:getStatus xmlns:webs="http://soap.ws.placa.service.sinesp.serpro.gov.br/"><placa>'.$placa.'</placa></webs:getStatus></soap:Body></soap:Envelope>';


  $header = array(
    "Content-type: application/x-www-form-urlencoded; charset=UTF-8",
    "Accept: text/plain, */*; q=0.01",
    "Cache-Control: no-cache",
    "Pragma: no-cache",
    "x-wap-profile: http://wap.samsungmobile.com/uaprof/GT-S7562.xml",
    "Content-length: ".strlen($request),
    "User-Agent: Mozilla/5.0 (Linux; U; Android 4.1.4; pt-br; GT-S1162L Build/IMM76I) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30",
  );

  $soap_do = curl_init();
  curl_setopt($soap_do, CURLOPT_URL, "http://sinespcidadao.sinesp.gov.br/sinesp-cidadao/ConsultaPlacaNovo27032014" );
  curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
  curl_setopt($soap_do, CURLOPT_TIMEOUT,        10);
  curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
  curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
  curl_setopt($soap_do, CURLOPT_POST,           true );
  curl_setopt($soap_do, CURLOPT_POSTFIELDS,     $soap_request);
  curl_setopt($soap_do, CURLOPT_HTTPHEADER,     $header);
  $res = curl_exec($soap_do);
  if($res === false)
  {
    $err = 'Curl erro: ' . curl_error($soap_do);
    curl_close($soap_do);
    print $err;
  }
  else
  {
    echo $res;
    curl_close($soap_do);
    print 'Ocorreu um erro...';
  }

The above code did not work, or I could not make it work and I am now investing in the code below, which, like the other one, is not working, but seems to be less complex. Can help me identify the mistakes of this ?

<?

$placa = 'ABC1234';

//chave do service
$chave = 'shienshenlhq';
//token para funcionamento
$token = hash_hmac('sha1', $placa, $chave, false);
//ramdom de ip para dificultar rastreamento
$random_ip = (string)mt_rand(1,255).".".mt_rand(0,255).".".mt_rand(0,255).".".mt_rand(0,255);

//criação estática de um xml com as informacoes para resgate
$data = 'GT-S1312L';
$data .= 'Android';
$data .= '1.1.1';
$data .= '4.1.4';
$data .= 'aplicativo';
$data .= '' . $random_ip . '';
$data .= '' . $token . '';
$data .= '' . (( 20000/111000.0 * sqrt(rand(1,1000)) ) * sin(2 * 3.141592654 * rand(1,1000)) + -38.5290245) . '';
$data .= '' . (( 20000/111000.0 * sqrt(rand(1,1000)) ) * cos(2 * 3.141592654 * rand(1,1000)) + -3.7506985) . '';
$data .= '' . $placa . '';

//inicia curl
$ch = curl_init();
//define para onde serao enviados
curl_setopt($ch, CURLOPT_URL, 'http://sinespcidadao.sinesp.gov.br/sinesp-cidadao/ConsultaPlacaNovo27032014');
//define que o conteúdo obtido deve ser retornado em vez de exibido
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//define que recebera posts
curl_setopt($ch, CURLOPT_POST, true);
//define os campos a serem postados
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
//envia
$retorno_curl = curl_exec($ch);
//encerra
curl_close($ch);

//retira o a tag return e seu conteudo, será enviado para retorno[0]
if(preg_match('/\(.*?)\/', utf8_encode($retorno_curl), $retorno)){

    $dom = new DOMDocument();
    //coloca o conteudo da tag return para ser tratado como xml
    $dom->loadXML($retorno[0]);
    //converte seu conteudo como objeto
    $elemento = simplexml_import_dom($dom);
    echo $elemento;

}else{

    echo "ERRO!";

}
  • No progress until the moment.

  • They put captcha in the site query. If there is no specific API you will not be able to query from PHP.

  • But this way I’m simulating the app

  • And how will fill the captcha?

  • I found it interesting I will follow, and try to help you, I will try some codes if I have any progress inform you

4 answers

7

solved, the guy on the site gave the tips straight, just missed to give the cut... follow the code example I tested this way and it worked

    <?php
  // Desenvolvido Para fins EDUCATIVOS.
  // Criado em 12/11/2014
  // Contato: [email protected]
  $placa   = 'KCK2486';
  $token = hash_hmac('sha1', $placa, 'shienshenlhq', false);
  $request = '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>'
          . '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" '
          . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
          . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" >'
          . '<soap:Header>'
          . '<dispositivo>GT-S1312L</dispositivo>'
          . '<nomeSO>Android</nomeSO>'
          . '<versaoAplicativo>1.1.1</versaoAplicativo><versaoSO>4.1.4</versaoSO>'
          . '<aplicativo>aplicativo</aplicativo><ip>177.206.169.90</ip>'
          . '<token>'.$token.'</token>'
          . '<latitude>-3.6770324</latitude><longitude>-38.6791411</longitude></soap:Header><soap:Body><webs:getStatus xmlns:webs="http://soap.ws.placa.service.sinesp.serpro.gov.br/"><placa>'.$placa.'</placa></webs:getStatus></soap:Body></soap:Envelope>';


  $header = array(
    "Content-type: application/x-www-form-urlencoded; charset=UTF-8",
    "Accept: text/plain, */*; q=0.01",
    "Cache-Control: no-cache",
    "Pragma: no-cache",
    "x-wap-profile: http://wap.samsungmobile.com/uaprof/GT-S7562.xml",
    "Content-length: ".strlen($request),
    "User-Agent: Mozilla/5.0 (Linux; U; Android 4.1.4; pt-br; GT-S1162L Build/IMM76I) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30",
  );

  $soap_do = curl_init();
  curl_setopt($soap_do, CURLOPT_URL, "http://sinespcidadao.sinesp.gov.br/sinesp-cidadao/ConsultaPlacaNovo27032014" );
  curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
  curl_setopt($soap_do, CURLOPT_TIMEOUT,        10);
  curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
  curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
  curl_setopt($soap_do, CURLOPT_POST,           true );
  curl_setopt($soap_do, CURLOPT_POSTFIELDS, $request);
  curl_setopt($soap_do, CURLOPT_HTTPHEADER,     $header);
  $res = curl_exec($soap_do);
  if($res === false)
  {
    $err = 'Curl erro: ' . curl_error($soap_do);
    curl_close($soap_do);
    print $err;
  }
  else
  {
    echo $res;
    curl_close($soap_do);
    print 'Ocorreu um erro...';
  }

https://paoloo.wordpress.com/2014/03/05/minha-primeira-tentativa-de-decodificar-um-apk-android-e-usar-seu-servico/

note: bgastaldi thanks for the clarifications

  • 2

    WORKING PERFECTLY. Broke me a bloody branch this.

  • Excellent! worked properly.

  • And they’ve changed the endpoint again, as expected :)

  • Have really changed. I’m trying to get the new way. Qd has put result

  • Stopped working due to update in sinesp to v3.. Does anyone know what to do?

4

"People after the decompiled apk understood the new method they used to obfuscate the new available the https://sinespcidadao.sinesp.gov.br/sinesp-cidadao/ConsultaPlacaNovo the key is the same ! Just Change the link to this and you’re done !"

Credits: Junior Kaibro

New Code:

<?php
  $placa   = 'KCK2486';
  $token = hash_hmac('sha1', $placa, 'shienshenlhq', false);
  $request = '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>'
          . '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" '
          . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
          . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" >'
          . '<soap:Header>'
          . '<dispositivo>GT-S1312L</dispositivo>'
          . '<nomeSO>Android</nomeSO>'
          . '<versaoAplicativo>1.1.1</versaoAplicativo><versaoSO>4.1.4</versaoSO>'
          . '<aplicativo>aplicativo</aplicativo><ip>177.206.169.90</ip>'
          . '<token>'.$token.'</token>'
          . '<latitude>-3.6770324</latitude><longitude>-38.6791411</longitude></soap:Header><soap:Body><webs:getStatus xmlns:webs="http://soap.ws.placa.service.sinesp.serpro.gov.br/"><placa>'.$placa.'</placa></webs:getStatus></soap:Body></soap:Envelope>';


  $header = array(
    "Content-type: application/x-www-form-urlencoded; charset=UTF-8",
    "Accept: text/plain, */*; q=0.01",
    "Cache-Control: no-cache",
    "Pragma: no-cache",
    "x-wap-profile: http://wap.samsungmobile.com/uaprof/GT-S7562.xml",
    "Content-length: ".strlen($request),
    "User-Agent: Mozilla/5.0 (Linux; U; Android 4.1.4; pt-br; GT-S1162L Build/IMM76I) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30",
  );

  $soap_do = curl_init();
  curl_setopt($soap_do, CURLOPT_URL, "http://sinespcidadao.sinesp.gov.br/sinesp-cidadao/ConsultaPlacaNovo");
  curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
  curl_setopt($soap_do, CURLOPT_TIMEOUT,        10);
  curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
  curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
  curl_setopt($soap_do, CURLOPT_POST,           true );
  curl_setopt($soap_do, CURLOPT_POSTFIELDS, $request);
  curl_setopt($soap_do, CURLOPT_HTTPHEADER,     $header);
  $res = curl_exec($soap_do);
  if($res === false)
  {
    $err = 'Curl erro: ' . curl_error($soap_do);
    curl_close($soap_do);
    print $err;
  }
  else
  {
    echo $res;
    curl_close($soap_do);
    print 'Ocorreu um erro...';
  }
  • 1

    Stopped again. Waiting for new solution !

2


Working according to Github: https://github.com/chapeupreto/sinesp
All credit to the creator of this code, I’m just passing along.

Installation:

composer require chapeupreto/sinesp

Utilizing:

<?php

require 'vendor/autoload.php';

use Sinesp\Sinesp;

$veiculo = new Sinesp;

try {
    $veiculo->buscar('GWW-6471');
    if ($veiculo->existe()) {
        print_r($veiculo->dados());
        echo 'O ano do veiculo eh ' , $veiculo->anoModelo, PHP_EOL;
    }
} catch (\Exception $e) {
    echo $e->getMessage();
}


The method buscar() must be the first method to be invoked. This method is used to locate vehicle information with the informed plate.

After the method call buscar(), the method dados() will return an associative array containing all vehicle information.

Still, instead of using the entire array returned by the method dados(), can also recover an information alone accessing it as object attribute:

echo 'O municipio do veiculo é ', $veiculo->municipio;

2

Solved and running again.
Explained step by step:

https://github.com/victor-torres/sinesp-client

SINESP Client

SINESP Client makes it possible to consult the SINESP Citizen database without the need to fill in Maps or some other type of authentication.

What is the SINESP

SINESP Citizen is a public database of Brazilian vehicles. It is very useful to identify stolen or suspect cars or motorcycles.

Available information

If a vehicle with the specified card is found, the server will return the following information which will be passed through a dictionary:

return_code (código de retorno)
return_message (mensagem de retorno)
status_code (código do status)
status_message (mensagem do status)
chassis (chassi do veículo)
model (modelo/versão)
brand (marca/fabricante)
color (cor/pintura)<br>
year (ano de fabricação)
model_year (ano do modelo)
plate (placa)
date (data e horada consulta)
city (cidade)
state (estado ou unidade federativa)

Why make a SINESP client?

We don’t know why, but the government doesn’t maintain a public API for this service. The only way to access the data is by accessing the SINESP website and answering verification questions (Captchas) for each of the requests.

What we did

Fortunately, the apps for Android and iOS allow the search to be done without having to answer any captcha tests. We then reverse-engineered the app so that we could have access to this public information without having to respond to these boring cookies.

Using

Installing

Through the Pypi

`pip install sinesp-client`

Or from the source code

`python setup.py install`

Normal use

from sinesp_client import SinespClient
sc = SinespClient()
result = sc.search('ABC1234')

Proxy

SINESP can block connections from outside the country. If you happen to be experiencing connection problems you can try using a web proxy (SOCKS5), which can be found for free on the Internet.

from sinesp_client import SinespClient
sc = SinespClient(proxy_address='127.0.0.1', proxy_port=8080)
result = sc.search('ABC1234')

Note: Use valid address and port values.

Calling a Python script through PHP

Attending several requests that have been coming by email, in this article on the Wiki of the teaching project to call a simple script made in Python, which returns the data obtained in JSON format, and to access the data obtained through PHP.

How to run Python code in PHP

Many people asked me how to get the results generated by the SINESP Client Python library in PHP.

Here I describe how to call a simple Python script (based on the example you have in our library’s README) to send the data obtained in JSON format to our PHP application, where we will receive and use in the best way possible.

Installing the library

Remember to install the library with

pip install sinesp-client

Writing the script in Python

Let’s create a script called.py board, which will run in command line and will receive the vehicle board as first argument:

import json
import sys

from sinesp_client import SinespClient

sc = SinespClient()
plate = sys.argv[1]
result = sc.search(plate)
json_result = json.dumps(result)
print(json_result)

Writing the PHP script

To call/run our Python script from PHP and resume the results is quite simple too:

Beware of the shell_exec command, it leaves your code susceptible to malicious code injections.

  $placa = 'M**4***';
  $informacoesDaPlacaEmJSON = shell_exec('python placa.py ' . $placa);
  $informacoesDaPlaca = json_decode($informacoesDaPlacaEmJSON);

The generated object

If we print the generated object with the PHP print_r function:

print_r($informacoesDaPlaca);

We get:

stdClass Object
(
    [city] => GUARAMIRIM
    [model_year] => 201*
    [plate] => M**4***
    [color] => VERMELHA
    [status_code] => 0
    [brand] => FIAT/SIENA EL FLEX
    [return_code] => 0
    [date] => 23/02/2016 19:59:59
    [state] => SC
    [chassis] => ************57158
    [year] => 201*
    [return_message] => Sem erros.
    [model] => FIAT/SIENA EL FLEX
    [status_message] => Sem restrição
)

Some data were omitted.

Accessing the individual results

This allows you to also access the data like this:

print($informacoesDaPlaca->city);
print($informacoesDaPlaca->state);

What would return:

GUARAMIRIM
SC
  • 5

    Hello Peter, could you, in addition to the link, add the information in the reply? A Paste/cole would do it. That’s what will change a letter in the repository name... If the link is disabled, your answer would be invalid. If you can’t do that now, if you allow me, I can edit and add the information for you. But that’s up to you.

  • Done, I’ll remember to do it next time. Thanks

  • 1

    I just edited the formatting, but with the information there is much better your answer, congratulations.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.