Send message to telegram with no access to DNS - telegram

Is there any option to send message to telegram while there is no access to DNS server (no option to resolve api.telegram.org url) ?
Tried with 149.154.167.220 instead of api.telegram.org - no luck

Yes, it is possible. If IP didn't blocked then you can send request to IP instead of domain.
For example in PHP with curl:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL," IP here ");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$headers = [
'Content-Type: application/html; charset=utf-8',
'Method: GET',
'Host: domain.com',
'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$server_output = curl_exec ($ch);
curl_close ($ch);
print $server_output ;

Related

Is there a way to retrieve data from a website/app that doesn't offer open APIs

Let's say, for example, I'm building an application where a user searches for a shirt based on it's UPC code. The application's job is to find that shirt at other various retailers. Retailer A has a API that can be easily used to locate product. However, retailer B doesn't have an API open to developers.
How would a developer handle retailer B?
The ideas that I've come up with were:
Use a headless browser to load retailer B's website, perform a search, and crawl the webpage. (Which sounds terrible)
Use a headless browser to load retailer B's website, perform a search, intercept the network traffic. (Better but still not great)
Has anyone encountered this before, or does anyone know of an existing technology or method to approach this issue? I've never understood how you would handle data retrieval without using APIs.
Here is something I did in php using curl. It should help get you started.
$url = 'https://newjersey.xxxxxx.net/login';
$cookie="cookie.txt";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_REFERER, $url);
curl_setopt ($ch, CURLOPT_VERBOSE, true);
$result = curl_exec ($ch);
preg_match('/meta content="([^"]+)" name="csrf-token"/', $result, $matches);
$token = $matches[1];
$creds['authenticity_token'] = $token;
print "login page with token $token\n";
curl_setopt ($ch, CURLOPT_URL, 'https://newjersey.xxxxx.net/auth/identity/callback');
curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($creds));
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);
Once logged in, you can get use a regex to get the data you are looking for.

Why am I getting CLIENT_ERROR when uploading a photo to LinkedIn API?

I'm working on making an Image Share with the LinkedIn v2 api. There are three steps, according to the LinkedIn docs.
Register your image to be uploaded.
Upload your image to LinkedIn.
Create the image share.
After I complete step 2, I check the status of the upload with /v2/assets/{asset-id} and get a "CLIENT_ERROR". I have no idea what this means and haven't found much about it in the LinkedIn docs or online. It may have something to do with uploading a binary image file as LinkedIn asks, but as far as I know I am uploading one.
Edit: The php-curl I'm using to upload the image is below. The $uploadUrl is obtained from the image register (step 1.)
$data = [
'file' => curl_file_create($file, $mimeType)//;
];
ob_start();
$out = fopen('php://output', 'w');
$ch = curl_init($uploadUrl);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_STDERR, $out);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch,CURLOPT_USERAGENT,'curl/7.35.0');
$authorizationHeader = trim("Authorization: Bearer $accessToken");
curl_setopt($ch, CURLOPT_HTTPHEADER, array($authorizationHeader,"Content-Type: {$mimeType}","X-Restli-Protocol-Version: 2.0.0"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
curl_setopt($ch, CURLOPT_UPLOAD, '1L');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
fclose($out);
$debug = ob_get_clean();
print_r($debug);
$resp_obj = json_decode($response);
print_r($response);
curl_close($ch);
The assets API is returning:
> GET /v2/assets/{redacted} HTTP/1.1
User-Agent: curl/7.35.0
Host: api.linkedin.com
Accept: */*
Authorization: Bearer {redacted}
< HTTP/1.1 200 OK
< X-LI-ResponseOrigin: RGW
< Content-Type: application/json
< X-RestLi-Protocol-Version: 1.0.0
< Content-Length: 319
< Date: Wed, 20 Mar 2019 14:09:18 GMT
< X-Li-Fabric: prod-ltx1
< Connection: keep-alive
< X-Li-Pop: prod-edc2-nkernB
< X-LI-Proto: http/1.1
< X-LI-UUID: {redacted}
< Set-Cookie: {redacted}
< X-LI-Route-Key: {redacted}
Response object is:
(
[serviceRelationships] => Array
(
[0] => stdClass Object
(
[identifier] => urn:li:userGeneratedContent
[relationshipType] => OWNER
)
)
[recipes] => Array
(
[0] => stdClass Object
(
[recipe] => urn:li:digitalmediaRecipe:feedshare-image
[status] => CLIENT_ERROR
)
)
[mediaTypeFamily] => STILLIMAGE
[created] => 1553090957146
[lastModified] => 1553090958505
[id] => {redacted}
[status] => ALLOWED
)
Update: it works fine when I upload the image using command line curl:
curl -i --upload-file {file} --header "Authorization: Bearer {auth}" {url}
Update: Solution:
use file_get_contents: curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents({path-to-your-image));**
$ch = curl_init($uploadUrl);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch,CURLOPT_USERAGENT,'curl/7.35.0');
$authorizationHeader = trim("Authorization: Bearer $accessToken");
curl_setopt($ch, CURLOPT_HTTPHEADER, array($authorizationHeader,"Content-Type: {$mimeType}","X-Restli-Protocol-Version: 2.0.0"));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents({path-to-your-image));
$response = curl_exec($ch);
This: curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents({path-to-your-image));
$ch = curl_init($uploadUrl);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch,CURLOPT_USERAGENT,'curl/7.35.0');
$authorizationHeader = trim("Authorization: Bearer $accessToken");
curl_setopt($ch, CURLOPT_HTTPHEADER, array($authorizationHeader,"Content-Type: {$mimeType}","X-Restli-Protocol-Version: 2.0.0"));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents({path-to-your-image));
$response = curl_exec($ch);
add headers to your code as Content-Type:application/octet-stream
Authorization': Bearer ${ access_token },
'X-Restli-Protocol-Version': '2.0.0',
'Content-Type': 'image/jpg'
body is simply the image file contents or a BLOB
method: POST or PUT... i guess one of it works with some and the second for others

How to send data to Visual Form Builder form

Wordpress Module : Visual Form Builder
I need to send post values to one of my
website with visual form builder.
Basically I have this website where people fill up and when
the user submits the form , my website will also send that
data to one of my website with visual form builder .
I've been banging my head for 2 days now .
still no lead to make it work.
*I am using php CURL. I've check cookies , csrf hidden field. etc.... still no luck ...
P.S .. No I have no intention to spam websites..
Here is my code
<?php
set_time_limit(9999999999999999);
require_once './simple_html_dom.php';
$GLOBALS['BASE_URL'] = "http://data.mysite.com";
$GLOBALS['cookieJar'] = "cookieTemp.txt";
function runCommand()
{
$csrf_token = getCSRFVal();
$payload = array(
"form_id" => "1",
"vfb-6[0]" => "Other",
"vfb-9" => "yes",
"vfb-10" => "yes",
"vfb-11" => "yes",
"vfb-12" => "options",
"vfb-14" => "test",
"vfb-15" => "test",
"vfb-16" => "447796272707",
"_wp_http_referer" => "/",
"_vfb-csrf-token" => $csrf_token,
);
$contentLength = strlen(http_build_query($payload));
$request_header = array(
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Encoding: gzip,deflate,sdch',
'Accept-Language: en-US,en;q=0.8,fil;q=0.6,th;q=0.4,it;q=0.2,es;q=0.2',
'Cache-Control: max-age=0',
'Connection: keep-alive',
'Host:data.mysite.com',
'Origin:http://data.mysite.com',
'Referer:http://data.mysite.com/',
'User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36',
'Content-Length:'.$contentLength,
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$GLOBALS['BASE_URL']);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER , $request_header);
curl_setopt($ch, CURLOPT_COOKIEJAR, $GLOBALS['cookieJar']);
curl_setopt($ch, CURLOPT_COOKIEFILE, $GLOBALS['cookieJar']);
$cur_res = curl_exec($ch);
echo $cur_res;
print_r(curl_getinfo($ch));
curl_close($ch);
}
function getCSRFVal()
{
$request_header = array(
'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Language:en-US,en;q=0.8,fil;q=0.6,th;q=0.4,it;q=0.2,es;q=0.2',
'User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36',
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$GLOBALS['BASE_URL']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER , $request_header);
curl_setopt($ch, CURLOPT_COOKIEJAR, $GLOBALS['cookieJar']);
curl_setopt($ch, CURLOPT_COOKIEFILE, $GLOBALS['cookieJar']);
$page = curl_exec($ch);
$html_object = str_get_html($page);
curl_close($ch);
$tempCsrfToken = "";
if (#$html_object->find("input[name='_vfb-csrf-token']",0)->value) {
$tempCsrfToken = $html_object->find("input[name='_vfb-csrf-token']",0)->value;
}else{
echo "Cant get new csrf token";
die();
}
return $tempCsrfToken;
}
runCommand();
?>

How come "Connection" is misspelled in HTTP response header?

We're running the following php code:
function downloadwebsite($url, $nobody=false) {
$ch = curl_init();
// FLAGS
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_NOBODY, $nobody);
curl_setopt($ch, CURLOPT_HEADER, $nobody);
$content = curl_exec($ch);
curl_close($ch);
return $content;
}
$website = downloadwebsite("www.imdb.com", true);
echo nl2br($website);
At one line in the response it says: "Cneonction: close".
Why is it misspelled? Is it on purpose?
According to this StackOverflow thread, it's done on purpose for load balancers. It's done to help with keepalives, it seems.

HTTP response header code ignored when using cURL

I have the below code but for some reason I cannot get the correct HTTP response code as it always comes back as 0. I have tried testing a page that only has "header("HTTP/1.1 404 Not Found");" and run cURL on this page bit still I get 0. When I go direct to the page in the browser, the header code is correct. Any ideas?
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPHEADER, Array (
"Content-Type: " . $content_type
));
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPGET, TRUE);
curl_setopt($curl, CURLOPT_USERAGENT, RESTClient :: USER_AGENT);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_HTTPHEADER, TRUE);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
curl_setopt($curl, CURLOPT_USERPWD, $auth);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
echo $httpcode;
$result = curl_exec($curl);
curl_close($curl);
Naturally, the return code can't be retrieved until after the request has been performed, which happens with the curl_exec() call. Move your curl_getinfo after that line and it should work.

Resources