HyperDbg Debugger
Loading...
Searching...
No Matches
connect.cpp File Reference

.connect command More...

#include "pch.h"

Functions

VOID CommandConnectHelp ()
 help of the .connect command
VOID ConnectLocalDebugger ()
 Connect to local debugger.
BOOLEAN ConnectRemoteDebugger (const CHAR *Ip, const CHAR *Port)
 Connect to remote debugger.
VOID CommandConnect (vector< CommandToken > CommandTokens, string Command)
 .connect command handler

Variables

BOOLEAN g_IsConnectedToHyperDbgLocally
 Shows whether the user is allowed to use 'load' command to load modules locally in VMI (virtual machine introspection) mode.
BOOLEAN g_IsConnectedToRemoteDebuggee
 Shows whether the current debugger is the host and connected to a remote debuggee (guest).
BOOLEAN g_IsConnectedToRemoteDebugger
 Shows whether the current system is a guest (debuggee) and a remote debugger is connected to this system.
BOOLEAN g_IsSerialConnectedToRemoteDebuggee
 Shows if the debugger was connected to remote debuggee over (A remote guest).
BOOLEAN g_IsSerialConnectedToRemoteDebugger
 Shows if the debugger was connected to remote debugger (A remote host).
string g_ServerPort
 In debugger (not debuggee), we save the port of server debuggee in this variable to use it later e.g, in signature.
string g_ServerIp
 In debugger (not debuggee), we save the port of server debuggee in this variable to use it later e.g, in signature.

Detailed Description

.connect command

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.1
Date
2020-05-27

Function Documentation

◆ CommandConnect()

VOID CommandConnect ( vector< CommandToken > CommandTokens,
string Command )

.connect command handler

Parameters
CommandTokens
Command
Returns
VOID
108{
109 string Ip;
110 string Port;
111
114 {
115 ShowMessages("you're connected to a debugger, please use '.disconnect' "
116 "command\n");
117 return;
118 }
119
122 {
123 ShowMessages("you're connected to a an instance of HyperDbg, please use "
124 "'.debug close' command\n");
125 return;
126 }
127
128 if (CommandTokens.size() == 1)
129 {
130 //
131 // Means that user entered just a connect so we have to
132 // ask to connect to what ?
133 //
134 ShowMessages("incorrect use of the '%s'\n\n",
135 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
137 return;
138 }
139 else if (CompareLowerCaseStrings(CommandTokens.at(1), "local") && CommandTokens.size() == 2)
140 {
141 //
142 // connect to local debugger
143 //
144 ShowMessages("local debugging (vmi-mode)\n");
145
147
148 return;
149 }
150 else if (CommandTokens.size() == 3 || CommandTokens.size() == 2)
151 {
152 Ip = GetCaseSensitiveStringFromCommandToken(CommandTokens.at(1));
153
154 if (CommandTokens.size() == 3)
155 {
156 Port = GetCaseSensitiveStringFromCommandToken(CommandTokens.at(2));
157 }
158
159 //
160 // means that probably wants to connect to a remote
161 // system, let's first check the if the parameters are
162 // valid
163 //
164 if (!ValidateIP(Ip))
165 {
166 ShowMessages("incorrect ip address\n");
167 return;
168 }
169
170 if (CommandTokens.size() == 3)
171 {
172 if (!IsNumber(Port) || stoi(Port) > 65535 || stoi(Port) < 0)
173 {
174 ShowMessages("incorrect port\n");
175 return;
176 }
177
178 //
179 // connect to remote debugger
180 //
181 ConnectRemoteDebugger(Ip.c_str(), Port.c_str());
182 }
183 else
184 {
185 //
186 // connect to remote debugger (default port)
187 //
188 ConnectRemoteDebugger(Ip.c_str(), NULL);
189 }
190 }
191 else
192 {
193 ShowMessages("incorrect use of the '%s'\n\n",
194 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
196 return;
197 }
198}
BOOLEAN g_IsSerialConnectedToRemoteDebuggee
Shows if the debugger was connected to remote debuggee over (A remote guest).
Definition globals.h:253
std::string GetCaseSensitiveStringFromCommandToken(CommandToken TargetToken)
Get case sensitive string from command token.
Definition common.cpp:467
BOOLEAN ValidateIP(const string &ip)
Function to validate an IP address.
Definition common.cpp:590
BOOLEAN CompareLowerCaseStrings(CommandToken TargetToken, const CHAR *StringToCompare)
Compare lower case strings.
Definition common.cpp:503
VOID ConnectLocalDebugger()
Connect to local debugger.
Definition connect.cpp:50
VOID CommandConnectHelp()
help of the .connect command
Definition connect.cpp:31
BOOLEAN ConnectRemoteDebugger(const CHAR *Ip, const CHAR *Port)
Connect to remote debugger.
Definition connect.cpp:61
BOOLEAN g_IsConnectedToRemoteDebuggee
Shows whether the current debugger is the host and connected to a remote debuggee (guest).
Definition globals.h:96
BOOLEAN g_IsConnectedToHyperDbgLocally
Shows whether the user is allowed to use 'load' command to load modules locally in VMI (virtual machi...
Definition globals.h:89
BOOLEAN IsNumber(const string &str)
BOOLEAN g_IsSerialConnectedToRemoteDebugger
Shows if the debugger was connected to remote debugger (A remote host).
Definition rev.cpp:18
BOOLEAN g_IsConnectedToRemoteDebugger
Shows whether the current system is a guest (debuggee) and a remote debugger is connected to this sys...
Definition globals.h:103

◆ CommandConnectHelp()

VOID CommandConnectHelp ( )

help of the .connect command

Returns
VOID
32{
33 ShowMessages(".connect : connects to a remote or local machine to start "
34 "debugging.\n\n");
35
36 ShowMessages("syntax : \t.connect [local]\n");
37 ShowMessages("syntax : \t.connect [Ip (string)] [Port (decimal)]\n");
38
39 ShowMessages("\n");
40 ShowMessages("\t\te.g : .connect local\n");
41 ShowMessages("\t\te.g : .connect 192.168.1.5 50000\n");
42}

◆ ConnectLocalDebugger()

VOID ConnectLocalDebugger ( )

Connect to local debugger.

Returns
VOID
51{
53}
#define TRUE
Definition BasicTypes.h:114

◆ ConnectRemoteDebugger()

BOOLEAN ConnectRemoteDebugger ( const CHAR * Ip,
const CHAR * Port )

Connect to remote debugger.

Returns
BOOLEAN
62{
63 //
64 // Validate IP and Port
65
66 if (!ValidateIP(Ip))
67 {
68 return FALSE;
69 }
70
71 if (Port != NULL)
72 {
73 if (!IsNumber(Port) || stoi(Port) > 65535 || stoi(Port) < 0)
74 {
75 return FALSE;
76 }
77
78 //
79 // connect to remote debugger
80 //
81 g_ServerIp = Ip;
82 g_ServerPort = Port;
84 }
85 else
86 {
87 //
88 // connect to remote debugger (default port)
89 //
90 g_ServerIp = Ip;
93 }
94
95 return TRUE;
96}
#define FALSE
Definition BasicTypes.h:113
#define DEFAULT_PORT
default port of HyperDbg for listening by debuggee (server, guest)
Definition Constants.h:331
string g_ServerPort
In debugger (not debuggee), we save the port of server debuggee in this variable to use it later e....
Definition globals.h:132
string g_ServerIp
In debugger (not debuggee), we save the port of server debuggee in this variable to use it later e....
Definition globals.h:139
VOID RemoteConnectionConnect(PCSTR Ip, PCSTR Port)
Connect to a remote debuggee (guest) as a client (host).
Definition remote-connection.cpp:315

Variable Documentation

◆ g_IsConnectedToHyperDbgLocally

BOOLEAN g_IsConnectedToHyperDbgLocally
extern

Shows whether the user is allowed to use 'load' command to load modules locally in VMI (virtual machine introspection) mode.

◆ g_IsConnectedToRemoteDebuggee

BOOLEAN g_IsConnectedToRemoteDebuggee
extern

Shows whether the current debugger is the host and connected to a remote debuggee (guest).

◆ g_IsConnectedToRemoteDebugger

BOOLEAN g_IsConnectedToRemoteDebugger
extern

Shows whether the current system is a guest (debuggee) and a remote debugger is connected to this system.

◆ g_IsSerialConnectedToRemoteDebuggee

BOOLEAN g_IsSerialConnectedToRemoteDebuggee
extern

Shows if the debugger was connected to remote debuggee over (A remote guest).

◆ g_IsSerialConnectedToRemoteDebugger

BOOLEAN g_IsSerialConnectedToRemoteDebugger
extern

Shows if the debugger was connected to remote debugger (A remote host).

◆ g_ServerIp

string g_ServerIp
extern

In debugger (not debuggee), we save the port of server debuggee in this variable to use it later e.g, in signature.

◆ g_ServerPort

string g_ServerPort
extern

In debugger (not debuggee), we save the port of server debuggee in this variable to use it later e.g, in signature.