什么?ACGO的家被偷啦?
2026-02-09 15:24:13
发布于:湖南
那年,我一时兴起,来试试ACGO的服务器是什么系统的。
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstring>
#ifdef _WIN32
char x[]={"Windows"};
#elif __APPLE__
char x[]={"MacOS"};
#else
char x[]={"Linux"};
#endif
int main() {
std::cout<<x;
return 0;
}
输出:
Linux
居然可以!(有点小惊讶)
于是,我试了试system()函数:
#include <stdlib.h>
int main() {
system("ls");
return 0;
}
结果输出了运行错误
气死我了(后面用popen()/fork()/exec()都是这样)
但是,我如果不用呢?
获取当前文件路径的文件列表(ls):
#include <iostream>
#include <iomanip>
#include <string>
#include <ctime>
#include <cstring>
#include <dirent.h>
#include <sys/stat.h>
#include <pwd.h>
#include <grp.h>
#include <unistd.h>
#include <cerrno>
std::string get_file_permissions(mode_t mode) {
std::string perm(10, '-');
if (S_ISDIR(mode)) perm[0] = 'd'; // 目录
else if (S_ISLNK(mode)) perm[0] = 'l';
else if (S_ISCHR(mode)) perm[0] = 'c';
else if (S_ISBLK(mode)) perm[0] = 'b';
else if (S_ISFIFO(mode)) perm[0] = 'p';
else if (S_ISSOCK(mode)) perm[0] = 's';
if (mode & S_IRUSR) perm[1] = 'r';
if (mode & S_IWUSR) perm[2] = 'w';
if (mode & S_IXUSR) perm[3] = 'x';
if (mode & S_ISUID) perm[3] = (perm[3] == 'x') ? 's' : 'S';
if (mode & S_IRGRP) perm[4] = 'r';
if (mode & S_IWGRP) perm[5] = 'w';
if (mode & S_IXGRP) perm[6] = 'x';
if (mode & S_ISGID) perm[6] = (perm[6] == 'x') ? 's' : 'S';
if (mode & S_IROTH) perm[7] = 'r';
if (mode & S_IWOTH) perm[8] = 'w';
if (mode & S_IXOTH) perm[9] = 'x';
if (mode & S_ISVTX) perm[9] = (perm[9] == 'x') ? 't' : 'T';
return perm;
}
std::string format_file_size(off_t size) {
const char* units[] = {"", "K", "M", "G", "T"};
int unit_idx = 0;
double fsize = size;
while (fsize >= 1024 && unit_idx < 4) {
fsize /= 1024;
unit_idx++;
}
char buf[32];
if (unit_idx == 0) {
snprintf(buf, sizeof(buf), "%ld", size);
} else {
snprintf(buf, sizeof(buf), "%.0f%s", fsize, units[unit_idx]);
}
return std::string(buf);
}
void list_files_l(const std::string& dir_path = ".") {
DIR* dir = opendir(dir_path.c_str());
if (!dir) {
std::cerr << "无法打开目录 " << dir_path << ": " << strerror(errno) << std::endl;
return;
}
struct dirent* entry;
while ((entry = readdir(dir)) != nullptr) {
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
continue;
}
std::string file_path = dir_path + "/" + entry->d_name;
struct stat file_stat;
if (lstat(file_path.c_str(), &file_stat) == -1) {
std::cerr << "无法获取文件属性 " << file_path << ": " << strerror(errno) << std::endl;
continue;
}
std::string permissions = get_file_permissions(file_stat.st_mode);
int nlink = file_stat.st_nlink;
struct passwd* pw = getpwuid(file_stat.st_uid);
std::string owner = pw ? pw->pw_name : std::to_string(file_stat.st_uid);
struct group* gr = getgrgid(file_stat.st_gid);
std::string group = gr ? gr->gr_name : std::to_string(file_stat.st_gid);
std::string size = format_file_size(file_stat.st_size);
char time_buf[32];
struct tm* tm_info = localtime(&file_stat.st_mtime);
strftime(time_buf, sizeof(time_buf), "%b %d %H:%M", tm_info);
std::string mtime = time_buf;
std::string filename = entry->d_name;
std::cout << permissions << " "
<< std::setw(2) << nlink << " "
<< std::setw(8) << std::left << owner << " "
<< std::setw(8) << std::left << group << " "
<< std::setw(6) << std::right << size << " "
<< mtime << " "
<< filename << std::endl;
}
closedir(dir);
}
int main(int argc, char* argv[]) {
std::string dir = (argc > 1) ? argv[1] : ".";
list_files_l(dir);
return 0;
}
输出:
-rw-r--r-- 1 root root 3K Feb 09 15:08 main.cpp
-rw-r--r-- 1 root root 0 Feb 09 15:08 compiler_log.out
-rw-r--r-- 1 root root 0 Feb 09 15:08 compiler.out
-rw-r--r-- 1 root root 0 Feb 09 15:08 compiler_error.out
-rwxr-xr-x 1 compiler compiler 27K Feb 09 15:08 main
-rwx------ 1 code code 0 Feb 09 15:08 data.in
-rw-r--r-- 1 root root 0 Feb 09 15:08 data_judger.log
-rw-r--r-- 1 root root 451 Feb 09 15:08 test-result.out
-rw-r--r-- 1 root root 0 Feb 09 15:08 data_error.out
获取当前进程:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
#include <cstring>
#include <cerrno>
#include <algorithm>
#include <iomanip>
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>
bool is_all_digits(const std::string& s) {
return !s.empty() && std::all_of(s.begin(), s.end(), ::isdigit);
}
struct ProcessInfo {
int pid;
std::string name;
std::string state;
std::string uid;
std::string cmdline;
};
ProcessInfo get_process_info(int pid) {
ProcessInfo info;
info.pid = pid;
std::string status_path = "/proc/" + std::to_string(pid) + "/status";
std::ifstream status_file(status_path);
if (status_file.is_open()) {
std::string line;
while (std::getline(status_file, line)) {
if (line.substr(0, 5) == "Name:") {
info.name = line.substr(6);
info.name.erase(0, info.name.find_first_not_of(" \t"));
info.name.erase(info.name.find_last_not_of(" \t") + 1);
}
else if (line.substr(0, 6) == "State:") {
info.state = line.substr(7, 1);
}
else if (line.substr(0, 4) == "Uid:") {
std::istringstream iss(line.substr(5));
iss >> info.uid;
}
}
status_file.close();
}
std::string cmdline_path = "/proc/" + std::to_string(pid) + "/cmdline";
std::ifstream cmdline_file(cmdline_path);
if (cmdline_file.is_open()) {
std::string cmd;
char c;
while (cmdline_file.get(c)) {
if (c == '\0') {
if (!cmd.empty() && cmd.back() != ' ') {
cmd += ' ';
}
} else {
cmd += c;
}
}
if (!cmd.empty() && cmd.back() == ' ') {
cmd.pop_back();
}
info.cmdline = cmd.empty() ? info.name : cmd;
cmdline_file.close();
}
return info;
}
std::vector<ProcessInfo> get_all_running_processes() {
std::vector<ProcessInfo> processes;
DIR* proc_dir = opendir("/proc");
if (!proc_dir) {
std::cerr << "无法打开/proc目录: " << strerror(errno) << std::endl;
return processes;
}
struct dirent* entry;
while ((entry = readdir(proc_dir)) != nullptr) {
std::string dir_name = entry->d_name;
if (!is_all_digits(dir_name)) {
continue;
}
int pid = std::stoi(dir_name);
ProcessInfo proc_info = get_process_info(pid);
if (!proc_info.name.empty()) {
processes.push_back(proc_info);
}
}
closedir(proc_dir);
return processes;
}
void print_processes(const std::vector<ProcessInfo>& processes) {
std::cout << std::left
<< std::setw(8) << "UID"
<< std::setw(8) << "PID"
<< std::setw(4) << "STAT"
<< std::setw(0) << "COMMAND" << std::endl;
std::cout << std::string(80, '-') << std::endl;
for (const auto& proc : processes) {
std::cout << std::left
<< std::setw(8) << proc.uid
<< std::setw(8) << proc.pid
<< std::setw(4) << proc.state
<< std::setw(0) << proc.cmdline << std::endl;
}
}
int main() {
std::vector<ProcessInfo> processes = get_all_running_processes();
if (processes.empty()) {
std::cerr << "未获取到任何进程信息(可能需要root权限)" << std::endl;
return 1;
}
print_processes(processes);
std::cout << "\n总计: " << processes.size() << " 个进程" << std::endl;
return 0;
}
输出:
UID PID STATCOMMAND
--------------------------------------------------------------------------------
0 1 S /bin/bash /code/entrypoint.sh
0 19 S java -Denv=PRO -Dapollo.bootstrap.namespaces=application,dynamic-tp -Dspring.profiles.active=prod -Dapollo.bootstrap.enabled=true -Dapollo.bootstrap.eagerLoad.enabled=true -XX:+PrintFlagsFinal -XX:+PrintCommandLineFlags -XX:MinRAMPercentage=37.5 -XX:MaxRAMPercentage=37.5 -XX:InitialRAMPercentage=37.5 -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=1024m -XX:+UseContainerSupport -XX:+UnlockExperimentalVMOptions -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/data/www/logs/xm-oj/xm-oj-k8s-java-9598cbc86-6fp7d/xm-oj.hprof -XshowSettings:vm -jar xm-oj-1.0.0.jar
0 1759114 S /code/libjudger.so --env=LANG=en_US.UTF-8 --env=LANGUAGE=en_US:en --env=LC_ALL=en_US.UTF-8 --max_cpu_time=3000 --max_real_time=9000 --max_memory=1073741824 --max_stack=268435456 --max_output_size=10240 --uid=12002 --gid=12002 --memory_limit_check_only=0 --exe_path=/code/judger/test/2020757606477000704/main --input_path=/code/judger/test/2020757606477000704/data.in --output_path=/code/judger/test/2020757606477000704/test-result.out --error_path=/code/judger/test/2020757606477000704/data_error.out --log_path=/code/judger/test/2020757606477000704/data_judger.log --seccomp_rule=general
12002 1759115 R /code/judger/test/2020757606477000704/main
总计: 4 个进程
获取当前下载软件:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <unistd.h>
#include <algorithm>
#include <cctype>
struct PackageInfo {
std::string name;
std::string version;
std::string status;
std::string description;
std::string priority;
std::string section;
};
enum class DistroType {
DEBIAN_LIKE,
RPM_LIKE,
UNKNOWN
};
DistroType detect_distro() {
if (access("/var/lib/dpkg/status", F_OK) == 0) {
return DistroType::DEBIAN_LIKE;
}
else if (access("/var/lib/rpm/Packages", F_OK) == 0) {
return DistroType::RPM_LIKE;
}
return DistroType::UNKNOWN;
}
std::string trim(const std::string& str) {
size_t start = str.find_first_not_of(" \t");
size_t end = str.find_last_not_of(" \t");
return (start == std::string::npos || end == std::string::npos) ? "" : str.substr(start, end - start + 1);
}
bool starts_with(const std::string& str, const std::string& prefix) {
if (str.empty() || prefix.empty() || str.length() < prefix.length()) return false;
return std::equal(prefix.begin(), prefix.end(), str.begin(),
[](char a, char b) { return std::tolower(a) == std::tolower(b); });
}
bool is_system_package(const PackageInfo& pkg) {
if (pkg.name.empty()) return true;
const std::vector<std::string> system_prefixes = {
"lib", "linux", "dpkg", "systemd", "udev", "grub", "kernel",
"apt", "coreutils", "bash", "dash", "init", "networkd", "plymouth"
};
for (const auto& prefix : system_prefixes) {
if (starts_with(pkg.name, prefix)) {
return true;
}
}
if (pkg.priority == "required" || pkg.priority == "important") {
return true;
}
if (pkg.section == "main/base" || pkg.section == "main/admin") {
return true;
}
return false;
}
std::vector<PackageInfo> parse_non_system_packages() {
std::vector<PackageInfo> packages;
std::ifstream file("/var/lib/dpkg/status");
if (!file.is_open()) {
std::cerr << "[错误] 无法打开 /var/lib/dpkg/status,请确认:" << std::endl;
std::cerr << "1. 是否使用 sudo 运行程序" << std::endl;
std::cerr << "2. 文件是否存在(ls /var/lib/dpkg/status)" << std::endl;
return packages;
}
std::cout << "[成功] 已打开 /var/lib/dpkg/status 文件,开始解析..." << std::endl;
PackageInfo pkg;
std::string line;
bool in_package = false;
while (std::getline(file, line)) {
std::string trimmed_line = trim(line);
if (trimmed_line.empty()) {
if (in_package && trim(pkg.status) == "install ok installed" && !pkg.name.empty() && !is_system_package(pkg)) {
packages.push_back(pkg);
}
pkg = PackageInfo();
in_package = false;
continue;
}
in_package = true;
size_t pkg_pos = trimmed_line.find("Package:");
if (pkg_pos == 0) {
std::string name_part = trimmed_line.substr(pkg_pos + 8); // 跳过 "Package:"
pkg.name = trim(name_part);
continue;
}
size_t ver_pos = trimmed_line.find("Version:");
if (ver_pos == 0) {
std::string ver_part = trimmed_line.substr(ver_pos + 8);
pkg.version = trim(ver_part);
continue;
}
size_t status_pos = trimmed_line.find("Status:");
if (status_pos == 0) {
std::string status_part = trimmed_line.substr(status_pos + 7);
pkg.status = trim(status_part);
continue;
}
size_t prio_pos = trimmed_line.find("Priority:");
if (prio_pos == 0) {
std::string prio_part = trimmed_line.substr(prio_pos + 9);
pkg.priority = trim(prio_part);
continue;
}
size_t sect_pos = trimmed_line.find("Section:");
if (sect_pos == 0) {
std::string sect_part = trimmed_line.substr(sect_pos + 8);
pkg.section = trim(sect_part);
continue;
}
}
file.close();
std::cout << "[解析完成] 共找到 " << packages.size() << " 个非系统已安装软件" << std::endl;
return packages;
}
int main() {
DistroType distro = detect_distro();
std::vector<PackageInfo> packages;
switch (distro) {
case DistroType::DEBIAN_LIKE:
std::cout << "检测到 Debian/Ubuntu 系统" << std::endl;
packages = parse_non_system_packages();
break;
case DistroType::RPM_LIKE:
std::cerr << "暂不支持 RPM 系统(CentOS/RHEL)" << std::endl;
return 1;
case DistroType::UNKNOWN:
std::cerr << "无法识别的 Linux 发行版" << std::endl;
return 1;
}
if (packages.empty()) {
std::cout << "未找到非系统软件(或解析失败)" << std::endl;
return 0;
}
std::cout << "==================== 非系统软件列表 ====================" << std::endl;
for (const auto& pkg : packages) {
if (pkg.name.empty()) continue;
std::cout << "软件名: " << pkg.name << std::endl;
std::cout << "版本号: " << (pkg.version.empty() ? "未知" : pkg.version) << std::endl;
}
return 0;
}
(原本是加了一个“描述”的但是后面输出超限了TmT)
输出:
检测到 Debian/Ubuntu 系统
[成功] 已打开 /var/lib/dpkg/status 文件,开始解析...
[解析完成] 共找到 88 个非系统已安装软件
==================== 非系统软件列表 ====================
软件名: alsa-topology-conf
版本号: 1.2.2-1
软件名: alsa-ucm-conf
版本号: 1.2.2-1ubuntu0.13
软件名: at-spi2-core
版本号: 2.36.0-2
软件名: bc
版本号: 1.07.1-2build1
软件名: binutils
版本号: 2.34-6ubuntu1.9
软件名: binutils-common
版本号: 2.34-6ubuntu1.9
软件名: binutils-x86-64-linux-gnu
版本号: 2.34-6ubuntu1.9
软件名: build-essential
版本号: 12.8ubuntu1.1
软件名: bzip2
版本号: 1.0.8-2
软件名: ca-certificates
版本号: 20240203~20.04.1
软件名: ca-certificates-java
版本号: 20190405ubuntu1.1
软件名: cmake
版本号: 3.16.3-1ubuntu1.20.04.1
软件名: cmake-data
版本号: 3.16.3-1ubuntu1.20.04.1
软件名: cpp
版本号: 4:9.3.0-1ubuntu2
软件名: cpp-9
版本号: 9.4.0-1ubuntu1~20.04.2
软件名: curl
版本号: 7.68.0-1ubuntu2.24
软件名: dbus
版本号: 1.12.16-2ubuntu2.3
软件名: dirmngr
版本号: 2.2.19-3ubuntu2.2
软件名: fakeroot
版本号: 1.24-1
软件名: file
版本号: 1:5.38-4
软件名: fontconfig-config
版本号: 2.13.1-2ubuntu3
软件名: fonts-dejavu-core
版本号: 2.37-1
软件名: fonts-dejavu-extra
版本号: 2.37-1
软件名: g++
版本号: 4:9.3.0-1ubuntu2
软件名: g++-9
版本号: 9.4.0-1ubuntu1~20.04.2
软件名: gcc
版本号: 4:9.3.0-1ubuntu2
软件名: gcc-9
版本号: 9.4.0-1ubuntu1~20.04.2
软件名: gettext
版本号: 0.19.8.1-10build1
软件名: gettext-base
版本号: 0.19.8.1-10build1
软件名: gnupg
版本号: 2.2.19-3ubuntu2.2
软件名: gnupg-l10n
版本号: 2.2.19-3ubuntu2.2
软件名: gnupg-utils
版本号: 2.2.19-3ubuntu2.2
软件名: gpg
版本号: 2.2.19-3ubuntu2.2
软件名: gpg-agent
版本号: 2.2.19-3ubuntu2.2
软件名: gpg-wks-client
版本号: 2.2.19-3ubuntu2.2
软件名: gpg-wks-server
版本号: 2.2.19-3ubuntu2.2
软件名: gpgconf
版本号: 2.2.19-3ubuntu2.2
软件名: gpgsm
版本号: 2.2.19-3ubuntu2.2
软件名: java-common
版本号: 0.72
软件名: krb5-locales
版本号: 1.17-6ubuntu4.7
软件名: locales
版本号: 2.31-0ubuntu9.16
软件名: logsave
版本号: 1.45.5-2ubuntu1
软件名: make
版本号: 4.2.1-1.2
软件名: manpages
版本号: 5.05-1
软件名: manpages-dev
版本号: 5.05-1
软件名: mesa-vulkan-drivers
版本号: 21.2.6-0ubuntu0.1~20.04.2
软件名: mime-support
版本号: 3.64ubuntu1
软件名: openjdk-11-jdk
版本号: 11.0.24+8-1ubuntu3~20.04
软件名: openjdk-11-jdk-headless
版本号: 11.0.24+8-1ubuntu3~20.04
软件名: openjdk-11-jre
版本号: 11.0.24+8-1ubuntu3~20.04
软件名: openjdk-11-jre-headless
版本号: 11.0.24+8-1ubuntu3~20.04
软件名: openssl
版本号: 1.1.1f-1ubuntu2.23
软件名: patch
版本号: 2.7.6-6
软件名: perl
版本号: 5.30.0-9ubuntu0.5
软件名: perl-modules-5.30
版本号: 5.30.0-9ubuntu0.5
软件名: pinentry-curses
版本号: 1.1.0-3build1
软件名: publicsuffix
版本号: 20200303.0012-1
软件名: python-pip-whl
版本号: 20.0.2-5ubuntu1.10
软件名: python2
版本号: 2.7.17-2ubuntu4
软件名: python2-dev
版本号: 2.7.17-2ubuntu4
软件名: python2-minimal
版本号: 2.7.17-2ubuntu4
软件名: python2.7
版本号: 2.7.18-1~20.04.4
软件名: python2.7-dev
版本号: 2.7.18-1~20.04.4
软件名: python2.7-minimal
版本号: 2.7.18-1~20.04.4
软件名: python3
版本号: 3.8.2-0ubuntu2
软件名: python3-dev
版本号: 3.8.2-0ubuntu2
软件名: python3-distutils
版本号: 3.8.10-0ubuntu1~20.04
软件名: python3-lib2to3
版本号: 3.8.10-0ubuntu1~20.04
软件名: python3-minimal
版本号: 3.8.2-0ubuntu2
软件名: python3-pip
版本号: 20.0.2-5ubuntu1.10
软件名: python3-pkg-resources
版本号: 45.2.0-1ubuntu0.2
软件名: python3-setuptools
版本号: 45.2.0-1ubuntu0.2
软件名: python3-wheel
版本号: 0.34.2-1ubuntu0.1
软件名: python3.8
版本号: 3.8.10-0ubuntu1~20.04.12
软件名: python3.8-dev
版本号: 3.8.10-0ubuntu1~20.04.12
软件名: python3.8-minimal
版本号: 3.8.10-0ubuntu1~20.04.12
软件名: shared-mime-info
版本号: 1.15-1
软件名: strace
版本号: 5.5-3ubuntu1
软件名: ucf
版本号: 3.0038+nmu1
软件名: x11-common
版本号: 1:7.7+19ubuntu14
软件名: x11-utils
版本号: 7.7+5
软件名: x11proto-core-dev
版本号: 2019.2-1ubuntu1
软件名: x11proto-dev
版本号: 2019.2-1ubuntu1
软件名: xdg-user-dirs
版本号: 0.17-2ubuntu1
软件名: xorg-sgml-doctools
版本号: 1:1.11-1
软件名: xtrans-dev
版本号: 1.4.0-1
软件名: xz-utils
版本号: 5.2.4-1ubuntu1.1
软件名: zlib1g-dev
版本号: 1:1.2.11.dfsg-2ubuntu1.5
哎~AC君你要小心了
本文只用于学术讨论,请勿作于非法用途
全部评论 6
?你把别人IDE编译器配置弄到了和网站有什么关系
1周前 来自 浙江
0...意思就是可以用C++对网站服务器进行控制
1周前 来自 湖南
0告诉了可以突破的点
1周前 来自 湖南
0这怎么就可以突破了
1周前 来自 浙江
0
AC君老家被偷了
1周前 来自 湖南
0《误闯天家》
1周前 来自 浙江
0发学术贴是何意味
1周前 来自 浙江
0哈哈
1周前 来自 湖南
0
6
1周前 来自 浙江
0你牛大了
1周前 来自 广东
0?
1周前 来自 湖南
0夸你呢,说你真牛
1周前 来自 浙江
0哦哦哦(反应迟钝。。。)
1周前 来自 湖南
0










































有帮助,赞一个