Vehicle-to-Board Query on sinesp via PHP - no captcha

11

Has anyone managed to consult Sinesp, via php? I'm trying to put this code to work 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 get it to work, and I'm now investing in the code below that, like the other one, is not working either, but it seems to be less complex. Can you help me identify your bugs?

<?

$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!";

}
    
asked by anonymous 16.04.2015 / 21:11

4 answers

1

Running according to GitHub: link
Any credit to the creator of this code, I'm just reviewing.

Installation :

composer require chapeupreto/sinesp

<?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 buscar() method must be the first method to invoke. This method is used to locate vehicle information with the board informed.

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

Also, instead of using the entire array returned by the dados() method, you can also retrieve an information in isolation by accessing it as an attribute of the object:

echo 'O municipio do veiculo é ', $veiculo->municipio;
    
13.03.2018 / 15:55
7

I decided, the guy on the site passed the tips right, just missed the stencils ... follow the example code I tested that 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...';
  }
  

link

note: bgastaldi thanks for the clarifications

    
02.07.2015 / 14:39
4

"After the apcom decompiled I understood the new method they used to obfuscate the new soap available the link

a> the key is the same! Just change the link to it 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...';
  }
    
20.11.2015 / 12:09
2

Resolved and working again. Home Explained step by step:

link

SINESP Client

SINESP Client makes it possible to consult the SINESP Citizen database without the need to fill captchas or any other type of authentication.

What is SINESP

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

Available information

If a vehicle with the specified card is found, the server will return the following information that 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 customer?

We do not know why, but the government does not 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 request.

What we did

Fortunately Android and iOS apps allow the search to be done without having to respond to any captcha tests. We then reverse-engineered the application so that we could have access to this public information without having to respond to those boring captchas.

Using

Installing

Through PyPI

'pip install sinesp-client'

Or from the source code

'python setup.py install'

Normal Usage

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

With proxy

SINESP can block connections from outside the country. If you happen to be experiencing connection problems you may try to use 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

In response to several requests that have arrived by email, in this article in the Project Wiki I teach to call a simple script made in Python, which returns the data obtained in JSON format, and 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's Python library in PHP.

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

Installing the library

Remember to install the library with

pip install sinesp-client

Writing the script in Python

Let's create a script called card.py, which will run on command line and will receive the vehicle's card as the 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 very simple too:

Watch out for the shell_exec command, it leaves your code susceptible to injections of malicious code.

  $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 has been omitted.

Accessing individual results

This allows you to access the data as well:

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

What would return:

GUARAMIRIM
SC
    
08.09.2016 / 20:24