From 7dfcc9828bed8b4b03f8e362379270be54142c74 Mon Sep 17 00:00:00 2001 From: yoloyyh <1764163852@qq.com> Date: Mon, 23 Sep 2024 19:57:22 +0800 Subject: [PATCH] feat ipv6 address --- rasp/librasp/src/nodejs.rs | 25 ++++++++++++++++++++++++- rasp/librasp/src/parse_elf.rs | 6 +++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/rasp/librasp/src/nodejs.rs b/rasp/librasp/src/nodejs.rs index 4d5590a46..eebe1440b 100644 --- a/rasp/librasp/src/nodejs.rs +++ b/rasp/librasp/src/nodejs.rs @@ -44,6 +44,7 @@ fn parse_port_from_address(address: &str) -> Option { pub fn get_process_listening_port(pid: i32) -> u16 { let tcp_path = format!("/proc/{}/net/tcp", pid); + // frist get ipv4 listen port if let Ok(content) = std::fs::read_to_string(tcp_path) { for line in content.lines().skip(1) { @@ -55,7 +56,29 @@ pub fn get_process_listening_port(pid: i32) -> u16 { if status == "0A" { if let Some(port) = parse_port_from_address(local_address) { if (NODEJS_INSPECT_PORT_MIN..= NODEJS_INSPECT_PORT_MAX).contains(&port) { - info!("Found listen port {} for pid {}", port, pid); + info!("Found IPv4 listen port {} for pid {}", port, pid); + return port; + } + } + } + } + } + } + + // get ipv6 listen port + let tcp6_path = format!("/proc/{}/net/tcp6", pid); + if let Ok(content) = std::fs::read_to_string(tcp6_path) { + + for line in content.lines().skip(1) { + let parts: Vec<&str> = line.split_whitespace().collect(); + if parts.len() >= 3 { + let local_address = parts[1]; + let status = parts[3]; + + if status == "0A" { + if let Some(port) = parse_port_from_address(local_address) { + if (16680..= NODEJS_INSPECT_PORT_MAX).contains(&port) { + info!("Found IPv6 listen port {} for pid {}", port, pid); return port; } } diff --git a/rasp/librasp/src/parse_elf.rs b/rasp/librasp/src/parse_elf.rs index dc1df4063..db5a0d844 100644 --- a/rasp/librasp/src/parse_elf.rs +++ b/rasp/librasp/src/parse_elf.rs @@ -138,7 +138,7 @@ pub fn find_by_symbol(elf: &Elf, file: &File) -> Result { Ok(version) } else { let msg = format!("file {:?} Failed to find symbol: runtime.buildVersion", file); - warn!("{}", msg); + // warn!("{}", msg); Err(anyhow!(msg)) } } @@ -223,12 +223,12 @@ pub fn find_by_section(elf: &Elf, buffer:&Vec, file: &File) -> Result