Lists Windows sessions (user logon sessions) in the guest. Demonstrates attaching to a domain, guest detection, and walking session structures.
#include <boost/program_options.hpp>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
namespace po = boost::program_options;
po::variables_map& vm);
int main(
int argc,
char** argv) {
po::options_description desc("Options");
std::string domain_name;
desc.add_options()
("domain,D", po::value<std::string>(&domain_name)->required(), "The domain name or ID attach to")
("help", "Display program help");
po::variables_map vm;
auto hypervisor = Hypervisor::instance();
auto domain = hypervisor->attach_domain(domain_name);
if (!
domain->detect_guest()) {
std::cerr << "Failed to detect guest\n";
return 1;
}
auto* guest =
domain->guest();
if (guest->os() != OS::Windows) {
std::cerr << "Only Windows guests are supported\n";
return 1;
}
const NtKernel& kernel = windows_guest->kernel();
std::vector<std::shared_ptr<PROCESS>> processes;
map<uint32_t, const MM_SESSION_SPACE*> sessionMap;
for (auto& entry : CidTable->open_handles()) {
std::unique_ptr<OBJECT_HEADER> header(entry->ObjectHeader());
if (header->type() == ObjectType::Process) {
auto process = kernel.
process(header->Body());
if (session) {
processes.emplace_back(std::move(process));
}
}
}
for (const auto& entry : sessionMap) {
cout << "*************************************************************\n";
cout <<
"Session " << session->
ptr() <<
": ";
cout << std::right << std::setw(5);
cout <<
"ID: " << session->
SessionID() <<
'\n';
cout << sessionProcList.size() << " processes\n";
cout << std::left << std::setw(5) << "PID";
cout << std::left << std::setw(5) << "Name";
cout << '\n';
for (auto& proc : sessionProcList) {
cout << std::left << std::setw(5) << proc->UniqueProcessId();
cout << std::left << std::setw(17) << proc->ImageFileName();
cout << '\n';
}
}
return 0;
}
po::variables_map& vm) {
try {
po::store(po::parse_command_line(argc, argv, desc), vm);
if (vm.count("help")) {
std::cout << "ivprocinfo - Display process information" << '\n';
std::cout << desc << '\n';
exit(0);
}
po::notify(vm);
} catch (po::error& e) {
std::cerr << "ERROR: " << e.what() << std::endl << std::endl;
std::cerr << desc << std::endl;
exit(1);
}
}
A representation of a Windows Guest OS.
Definition WindowsGuest.hh:33
Definition MM_SESSION_SPACE.hh:29
virtual std::vector< std::shared_ptr< const PROCESS > > process_list() const =0
virtual guest_ptr< void > ptr() const =0
virtual uint32_t SessionID() const =0
Abstraction for the Windows NT kernel.
Definition NtKernel.hh:37
virtual std::unique_ptr< HANDLE_TABLE > CidTable()=0
Get the PspCidTable from the kernel.
virtual std::shared_ptr< PROCESS > process(const guest_ptr< void > &ptr) const =0
Get the PROCESS at the given address.
int main(int argc, char **argv)
Definition main.c:35
Classes related to the Windows NT kernel.
Definition APPHELPCACHESERVICECLASS.hh:23
Classes related to Microsoft Windows guests.
Definition LanguageId.hh:21
Core IntroVirt classes.
Definition Cr0.hh:20
void parse_program_options(int argc, char **argv, po::options_description &desc, po::variables_map &vm)
Definition vmcall_interface.cc:581
unique_ptr< Domain > domain
Definition vmcall_interface.cc:48