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< string > SplitCommand, 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< string > SplitCommand,
string Command )

.connect command handler

Parameters
SplitCommand
Command
Returns
VOID
107{
108 string ip;
109 string port;
110
113 {
114 ShowMessages("you're connected to a debugger, please use '.disconnect' "
115 "command\n");
116 return;
117 }
118
121 {
122 ShowMessages("you're connected to a an instance of HyperDbg, please use "
123 "'.debug close' command\n");
124 return;
125 }
126
127 if (SplitCommand.size() == 1)
128 {
129 //
130 // Means that user entered just a connect so we have to
131 // ask to connect to what ?
132 //
133 ShowMessages("incorrect use of the '.connect'\n\n");
135 return;
136 }
137 else if (SplitCommand.at(1) == "local" && SplitCommand.size() == 2)
138 {
139 //
140 // connect to local debugger
141 //
142 ShowMessages("local debugging (vmi-mode)\n");
144 return;
145 }
146 else if (SplitCommand.size() == 3 || SplitCommand.size() == 2)
147 {
148 ip = SplitCommand.at(1);
149
150 if (SplitCommand.size() == 3)
151 {
152 port = SplitCommand.at(2);
153 }
154
155 //
156 // means that probably wants to connect to a remote
157 // system, let's first check the if the parameters are
158 // valid
159 //
160 if (!ValidateIP(ip))
161 {
162 ShowMessages("incorrect ip address\n");
163 return;
164 }
165
166 if (SplitCommand.size() == 3)
167 {
168 if (!IsNumber(port) || stoi(port) > 65535 || stoi(port) < 0)
169 {
170 ShowMessages("incorrect port\n");
171 return;
172 }
173
174 //
175 // connect to remote debugger
176 //
177 ConnectRemoteDebugger(ip.c_str(), port.c_str());
178 }
179 else
180 {
181 //
182 // connect to remote debugger (default port)
183 //
184 ConnectRemoteDebugger(ip.c_str(), NULL);
185 }
186 }
187 else
188 {
189 ShowMessages("incorrect use of the '.connect'\n\n");
191 return;
192 }
193}
BOOLEAN IsNumber(const string &str)
check if given string is a numeric string or not
Definition common.cpp:145
BOOLEAN ValidateIP(const string &ip)
Function to validate an IP address.
Definition common.cpp:469
BOOLEAN g_IsSerialConnectedToRemoteDebugger
Shows if the debugger was connected to remote debugger (A remote host)
Definition globals.h:238
BOOLEAN g_IsConnectedToRemoteDebuggee
Shows whether the current debugger is the host and connected to a remote debuggee (guest)
Definition globals.h:74
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_IsConnectedToRemoteDebugger
Shows whether the current system is a guest (debuggee) and a remote debugger is connected to this sys...
Definition globals.h:81
BOOLEAN g_IsSerialConnectedToRemoteDebuggee
Shows if the debugger was connected to remote debuggee over (A remote guest)
Definition globals.h:231
BOOLEAN g_IsConnectedToHyperDbgLocally
Shows whether the user is allowed to use 'load' command to load modules locally in VMI (virtual machi...
Definition globals.h:67
VOID ShowMessages(const char *Fmt,...)
Show messages.
Definition libhyperdbg.cpp:96

◆ 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:55

◆ 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:54
#define DEFAULT_PORT
default port of HyperDbg for listening by debuggee (server, guest)
Definition Constants.h:323
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:110
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:117
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.