[Slack] Use GET request where possible

Fixes https://github.com/FSecureLABS/C3/issues/15
dependabot/npm_and_yarn/Src/WebController/UI/websocket-extensions-0.1.4
Grzegorz Rychlik 2020-05-15 17:01:19 +02:00
parent 85937815a5
commit 0c4785c946
2 changed files with 11 additions and 3 deletions

View File

@ -61,7 +61,7 @@ std::map<std::string, std::string> FSecure::Slack::ListChannels()
std::map<std::string, std::string> channelMap;
std::string url = OBF("https://slack.com/api/conversations.list?exclude_archived=true");
json response = SendJsonRequest(url, NULL);
json response = GetJsonResponse(url);
for (auto &channel : response[OBF("channels")])
{
@ -107,7 +107,7 @@ std::string FSecure::Slack::CreateChannel(std::string const& channelName)
std::vector<std::pair<std::string, std::string>> FSecure::Slack::ReadReplies(std::string const& timestamp)
{
std::string url = OBF("https://slack.com/api/conversations.replies?channel=") + this->m_Channel + OBF("&ts=") + timestamp;
json output = SendJsonRequest(url, NULL);
json output = GetJsonResponse(url);
//This logic is really messy, in reality the checks are over cautious, however there is an edgecase
//whereby a message could be created with no replies of the implant that wrote triggers an exception or gets killed.
@ -159,7 +159,7 @@ std::vector<std::string> FSecure::Slack::GetMessagesByDirection(std::string con
url.append(OBF("&cursor=") + cursor);
//Actually send the http request and grab the messages
auto resp = SendJsonRequest(url, NULL);
auto resp = GetJsonResponse(url);
auto& messages = resp[OBF("messages")];
@ -247,6 +247,11 @@ json FSecure::Slack::SendJsonRequest(std::string const& url, json const& data)
return json::parse(SendHttpRequest(url, ContentType::ApplicationJson, data.dump()));
}
json FSecure::Slack::GetJsonResponse(std::string const& url)
{
return json::parse(SendHttpRequest(url));
}
void FSecure::Slack::UploadFile(ByteView data, std::string const& ts)
{
std::string url = OBF_STR("https://slack.com/api/files.upload?") + OBF("&channels=") + this->m_Channel + OBF("&thread_ts=") + ts;

View File

@ -89,6 +89,9 @@ namespace FSecure
/// Send http request with json data, uses preset token for authentication
json SendJsonRequest(std::string const& url, json const& data);
/// Send http GET request, uses preset token for authentication, expect response of application/json type
json GetJsonResponse(std::string const& url);
/// Use Slack's File API to retrieve files.
/// @param url - the url where the file can be retrieved.
/// @return - the data within the file.