Skip to content

Commit

Permalink
Update GruntBridge profiles for updated IMessenger interface
Browse files Browse the repository at this point in the history
  • Loading branch information
cobbr committed Aug 21, 2020
1 parent 6afc976 commit f5014ba
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 30 deletions.
21 changes: 0 additions & 21 deletions Covenant/Data/Grunt/GruntBridge/GruntBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,27 +339,6 @@ private static IntPtr TaskExecute(TaskingMessenger messenger, GruntTaskingMessag
}
}

public enum MessageType
{
Read,
Write
}

public class ProfileMessage
{
public MessageType Type { get; set; }
public string Message { get; set; }
}

public interface IMessenger
{
string Hostname { get; }
string Identifier { get; set; }
string Authenticator { get; set; }
ProfileMessage Read();
void Write(string Message);
void Close();
}

public class Profile
{
Expand Down
6 changes: 3 additions & 3 deletions Covenant/Data/Grunt/GruntBridge/GruntBridgeStager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void ExecuteStager()
BridgeMessenger messenger = new BridgeMessenger(CovenantURI, GUID, ProfileWriteFormat);
messenger.Connect();
messenger.Write(String.Format(ProfileWriteFormat, transformedResponse, GUID));
string Stage0Response = messenger.Read();
string Stage0Response = messenger.Read().Message;
string extracted = Parse(Stage0Response, ProfileReadFormat)[0];
extracted = Encoding.UTF8.GetString(MessageTransform.Invert(extracted));
List<string> parsed = Parse(extracted, MessageFormat);
Expand Down Expand Up @@ -88,7 +88,7 @@ public void ExecuteStager()
transformedResponse = MessageTransform.Transform(Encoding.UTF8.GetBytes(Stage1Body));
string formatted = String.Format(ProfileWriteFormat, transformedResponse, GUID);
messenger.Write(formatted);
string Stage1Response = messenger.Read();
string Stage1Response = messenger.Read().Message;
extracted = Parse(Stage1Response, ProfileReadFormat)[0];
extracted = Encoding.UTF8.GetString(MessageTransform.Invert(extracted));
parsed = Parse(extracted, MessageFormat);
Expand All @@ -113,7 +113,7 @@ public void ExecuteStager()
string Stage2Body = String.Format(MessageFormat, GUID, "2", "", Convert.ToBase64String(SessionKey.IV), Convert.ToBase64String(EncryptedChallenge2), Convert.ToBase64String(hash));
transformedResponse = MessageTransform.Transform(Encoding.UTF8.GetBytes(Stage2Body));
messenger.Write(String.Format(ProfileWriteFormat, transformedResponse, GUID));
string Stage2Response = messenger.Read();
string Stage2Response = messenger.Read().Message;
extracted = Parse(Stage2Response, ProfileReadFormat)[0];
extracted = Encoding.UTF8.GetString(MessageTransform.Invert(extracted));
parsed = Parse(extracted, MessageFormat);
Expand Down
16 changes: 14 additions & 2 deletions Covenant/Data/Profiles/DefaultBridgeProfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,24 @@ ReadFormat: |-
WriteFormat: |-
{DATA},{GUID}
BridgeMessengerCode: |-
public enum MessageType
{
Read,
Write
}
public class ProfileMessage
{
public MessageType Type { get; set; }
public string Message { get; set; }
}
public interface IMessenger
{
string Hostname { get; }
string Identifier { get; set; }
string Authenticator { get; set; }
string Read();
ProfileMessage Read();
void Write(string Message);
void Close();
}
Expand All @@ -44,7 +56,7 @@ BridgeMessengerCode: |-
// TODO
}
public string Read()
public ProfileMessage Read()
{
// TODO
return null;
Expand Down
20 changes: 16 additions & 4 deletions Covenant/Data/Profiles/TCPBridgeProfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,24 @@ ReadFormat: |-
WriteFormat: |-
{DATA},{GUID}
BridgeMessengerCode: |-
public enum MessageType
{
Read,
Write
}
public class ProfileMessage
{
public MessageType Type { get; set; }
public string Message { get; set; }
}
public interface IMessenger
{
string Hostname { get; }
string Identifier { get; set; }
string Authenticator { get; set; }
string Read();
ProfileMessage Read();
void Write(string Message);
void Close();
}
Expand All @@ -53,17 +65,17 @@ BridgeMessengerCode: |-
this.WriteFormat = WriteFormat;
}
public string Read()
public ProfileMessage Read()
{
byte[] read = this.ReadBytes();
if (read == null)
{
Thread.Sleep(5000);
this.Close();
this.Connect();
return "";
return new ProfileMessage { Type = MessageType.Read, Message = "" };
}
return Encoding.UTF8.GetString(read);
return new ProfileMessage { Type = MessageType.Read, Message = Encoding.UTF8.GetString(read) };
}
public void Write(string Message)
Expand Down

0 comments on commit f5014ba

Please sign in to comment.