Get User/Channel by name via Slack API - slack

Is it possible to get User/Channel object if you know user/channel name with Slack API?
If you try to search user/channel in the web version you can see this (trying to find #tmp-blo gives 2 results: #tmp-block-check and #tmp-improving-review-block):
this search use /search resource:
payload:
I can use this request from the Terminal if I save it as cURL:
curl 'https://edgeapi.slack.com/cache/????/channels/search?fp=2b' \
-H 'content-type: text/plain;charset=UTF-8' \
-H 'cookie: d=????; b=??????; lc=????; shown_ssb_redirect_page=1; shown_download_ssb_modal=1; show_download_ssb_banner=1; no_download_ssb_banner=1; _gcl_au=??????; _cs_c=1; _rdt_uuid=????; __qca=????; OptanonConsent=isGpcEnabled=0&datestamp=Tue+Aug+09+2022+17%????&version=6.22.0&isIABGlobal=false&hosts=&consentId=????????&interactionCount=1&landingPath=NotLandingPage&groups=????&AwaitingReconsent=false; _gid=????; _ga=????; _cs_id=????; _lc2_fpi=????; __adroll_fpc=????; __ar_v4=????; _fbp=????; _ga_????=????; d-s=????; x=????' \
-H 'origin: https://app.slack.com' \
-H 'pragma: no-cache' \
-H 'sec-ch-ua: "Chromium";v="104", " Not A;Brand";v="99", "Google Chrome";v="104"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "macOS"' \
-H 'sec-fetch-dest: empty' \
-H 'sec-fetch-mode: cors' \
-H 'sec-fetch-site: same-site' \
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36' \
--data-raw '{"token":"????","query":"tmp-blo","count":30,"fuzz":1,"uax29_tokenizer":false,"check_membership":true}' \
--compressed
but this request requires some authentication cookies. And I don't know how my application should specify appropriate cookies for this request. So my questions are:
can I specify appropriate authorization cookies for /search ? Or is there any other api that can return user/channel id by name?
For a Context:
We have application that periodically sends data to user/channel. User can create its own mailing by specifying the data to send and recipients. We often face a problem that user incorrectly entered user or channel and we want to develop a feature that will suggest options for autocomplete just like Slack Application.

Related

GraphiQL is not sending cookies?

I've got a Spring Boot App that gains GraphQL by way of org.springframework.experimental/graphql-spring-boot-starter. That starter, somehow, gives me the GraphiQL UI to run ad-hoc queries through. As I tried to integrate Spring Security into my Application all of my POST /graphql calls began to see 403 at the browser.
Looking at the Chrome console, I can see the root cause. Our auth rides on a cookie bound to the domain. The GraphiQL client is failing to send the cookie, so Spring Security can't find anything to authenticate. When I copy the request as curl, I can see it is missing the Cookie header...
$ curl 'http://localhost.example.com:8080/graphql' \
> -H 'Connection: keep-alive' \
> -H 'Accept: application/json' \
> -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36' \
> -H 'Content-Type: application/json' \
> -H 'Origin: http://localhost.blueorigin.com:8080' \
> -H 'Referer: http://localhost.blueorigin.com:8080/?path=/graphql' \
> -H 'Accept-Language: en-US,en;q=0.9' \
> --data-raw '{"query":"query now {\n now\n}","variables":null,"operationName":"now"}' \
> --compressed \
> --insecure
{"timestamp":"2021-10-13T19:18:37.223+00:00","status":403,"error":"Forbidden","message":"Access Denied","path":"/graphql"}
If I give curl the Cookie the server needs...all is well.
How do I get GraphiQL to send cookies for a Spring Boot Application?

wget to retrieve search results from virustotal

I am trying to retrieve the search results from virustotal for ransomware keyword, where I am trying to use the following code:
wget "https://www.virustotal.com/#/search/ransomware" -O output.txt
However, I do not get the result output. I am expecting to get at least the hash value of each resulted sample, where I am planning to use them later on.
Any advice?
You can use either curl or wget to do this.
Using Curl
curl 'https://www.virustotal.com/ui/search?query=ransomware&relationships\[url\]=network_location%2Clast_serving_ip_address&relationships\[comment\]=author%2Citem' -H 'pragma: no-cache' -H 'cookie: _ga=GA1.2.1407677727.1526818525; _gid=GA1.2.163855722.1526818525; _gat=1' -H 'accept-encoding: gzip, deflate, br' -H 'accept-language: en-US,en;q=0.9' -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36' -H 'accept: application/json' -H 'cache-control: no-cache' -H 'authority: www.virustotal.com' -H 'referer: https://www.virustotal.com/' --compressed
Using wget
wget 'https://www.virustotal.com/ui/search?query=ransomware&relationships\[url\]=network_location%2Clast_serving_ip_address&relationships\[comment\]=author%2Citem' -O output.txt

bash curl with session cookies?

I managed to get the curl output of a web-page that using site minder authentication by manually extracting the cookie from firefox and using it in the curl command:
curl "example.com/firstexample" -H "Host: example.com" -H "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" -H "Accept-Language: en-US,en;q=0.5" --compressed -H "Content-Type: application/x-www-form-urlencoded" -H "X-Requested-With: XMLHttpRequest" -H "Referer: http://example.com" -H --cookie-jar cookies.txt --cookie cookies.txt -H "Connection: keep-alive"
However, the curl works only as long as the session lasts. Once a new session starts i.e. the cookie session id and other stuff changes - the curl no longer works obviously.
Is there a way to get the subsequent cookies/session ids via curl to continue seemlessly.
Check out the --cookie and --cookie-jar options on curl in the man page. They should do what you need.

Unix cUrl cookie login to a .jsp servlet page, request and save file requested

I have tried to export a text file resulted by an request to a .jsp page with Java script enabled from Oracle BI Publisher framework with below command in Unix:
curl 'http://server/xmlpserver/report.xdo&_xt=New+Template+1&_xf=text'
-H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8'
-H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36'
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
-H 'Referer: http://server/xmlpserver/report.xdo'
-H 'Cookie:
JSESSIONID=qq!11!22; ORA_XDO_UI=en_US;
JSESSIONID=qq!11; oracle.uix=0^^GMT+3:00^p'
-H 'Connection: keep-alive'
--compressed -o test.txt
This command is 'copy as bash curl command' from Google Chrome debugger and work it but syntax command use id JSESSION in cookie who will expire.
I need to login on this .jsp page to generate cookie with JSESSION=qq!11!22 and JSESSION=qq!11 (see above cUrl syntax from Google Chrome).
For this I have used command:
curl -c cookies.txt -d "user=user&pass=pass" http://server/xmlpserver/login.jsp, and was generated only one "JSESSIONID=qq!11;".
I need to generate one more JSESSIONID=qq!11!22.
Thanks!

How to use Chrome's "Copy as cURL" for multipart/form-data post requests on Windows?

I am developing a module for a web application. To trigger this module, I need to submit some data to the server. For simple forms, Copy as cURL in the Chrome Developer Tools works fine (using curl from msys[git]), but for post requests with multipart/form-data, the copied string is neither usable in the windows shell (cmd) nor with bash (form msys); the copied text is similar to:
curl "http://myserver.local" -H "Origin: http://wiki.selfhtml.org" -H "Accept-Encoding: gzip, deflate" -H "Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4" -H "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36" -H "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryntXdlWbYXAVwCIMU" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" -H "Cache-Control: max-age=0" -H "Referer: http://wiki.selfhtml.org/extensions/Selfhtml/frickl.php/Beispiel:HTML_form-Element1.html" -H "Connection: keep-alive" --data-binary "------WebKitFormBoundaryntXdlWbYXAVwCIMU"^
"Content-Disposition: form-data; name=""area"""^
"multi"^
"line"^
"------WebKitFormBoundaryntXdlWbYXAVwCIMU--"^
"" --compressed
Is there any way I could use this or convert it to something usable?
Chrome, as well as the other browsers actually, do a rather poor job of translating multi-part formposts into curl command lines.
A much more convenient curl command line would not use --data-binary for that, it would use --form. And then you want one --form per input field.
In your case, it probably would look something like (backslashes inserted here
for visibility):
curl "http://myserver.local" \
--compressed \
-H "Origin: http://wiki.selfhtml.org" \
-A "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36" \
-H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" \
-H "Cache-Control: max-age=0" \
-e "http://wiki.selfhtml.org/extensions/Selfhtml/frickl.php/Beispiel:HTML_form-Element1.html" \
-F area=[contents]
I left the [contents] in there, but it should be replaced with what you actually want in the area field. You could also pass it from a file if you prefer to.
I removed two unnecessary -H uses, and I replaced two to use the direct curl options.
h2c - headers to curl
Advice for the future: figure out the exact HTTP header trace you want to reproduce with a curl command line and paste it over at https://curl.se/h2c/ .

Resources