-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
232 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module torflux | ||
|
||
go 1.22.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
// Copyright(C) 2024 NOXCIS [https://github.com/NOXCIS] | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
"bufio" | ||
"bytes" | ||
"fmt" | ||
"net" | ||
"os" | ||
"strings" | ||
"time" | ||
) | ||
|
||
const ( | ||
logDir = "./log" | ||
logFile = logDir + "/tor_circuit_refresh_log.txt" | ||
bufferSize = 8192 | ||
torControlPort1 = 9051 | ||
torControlPort2 = 9054 | ||
socketTimeout = 5 * time.Second | ||
) | ||
|
||
// logMessage logs messages to a file and optionally prints to the console. | ||
func logMessage(message string, addNewlines, toConsole bool) { | ||
timestamp := time.Now().Format("2006-01-02 15:04:05") | ||
logMsg := fmt.Sprintf("[%s] %s", timestamp, message) | ||
|
||
if toConsole { | ||
fmt.Println(logMsg) | ||
} | ||
|
||
// Ensure log directory exists | ||
if err := os.MkdirAll(logDir, 0755); err != nil { | ||
fmt.Fprintf(os.Stderr, "[ERROR] Could not create log directory: %v\n", err) | ||
return | ||
} | ||
|
||
// Open or create log file | ||
f, err := os.OpenFile(logFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "[ERROR] Could not open log file: %v\n", err) | ||
return | ||
} | ||
defer f.Close() | ||
|
||
writer := bufio.NewWriter(f) | ||
writer.WriteString(logMsg + "\n") | ||
if addNewlines { | ||
writer.WriteString(strings.Repeat("\n", 5)) | ||
} | ||
writer.Flush() | ||
} | ||
|
||
// sendSignal sends a NEWNYM signal to the Tor control port and retrieves circuit status. | ||
func sendSignal(port int, password string, statusBuffer *bytes.Buffer) bool { | ||
address := fmt.Sprintf("127.0.0.1:%d", port) | ||
conn, err := net.DialTimeout("tcp", address, socketTimeout) | ||
if err != nil { | ||
logMessage("[TOR-FLUX] [ERROR] Connection to Tor control port failed", false, false) | ||
return false | ||
} | ||
defer conn.Close() | ||
|
||
conn.SetDeadline(time.Now().Add(socketTimeout)) | ||
|
||
reader := bufio.NewReader(conn) | ||
|
||
// Authenticate | ||
if password != "" { | ||
authCmd := fmt.Sprintf("AUTHENTICATE \"%s\"\r\n", password) | ||
fmt.Fprint(conn, authCmd) | ||
|
||
resp, _ := reader.ReadString('\n') | ||
if !strings.Contains(resp, "250") { | ||
logMessage("[TOR-FLUX] [ERROR] Tor authentication failed", false, false) | ||
return false | ||
} | ||
} | ||
|
||
// Send NEWNYM signal | ||
fmt.Fprint(conn, "SIGNAL NEWNYM\r\n") | ||
resp, _ := reader.ReadString('\n') | ||
if !strings.Contains(resp, "250") { | ||
logMessage("[TOR-FLUX] [ERROR] Failed to send NEWNYM signal", false, false) | ||
return false | ||
} | ||
|
||
// Get circuit status | ||
fmt.Fprint(conn, "GETINFO circuit-status\r\n") | ||
for { | ||
line, err := reader.ReadString('\n') | ||
if err != nil { | ||
break | ||
} | ||
statusBuffer.WriteString(line) | ||
} | ||
|
||
logMessage("[TOR-FLUX] Current Circuit Status:", false, false) | ||
logMessage(statusBuffer.String(), false, false) | ||
logMessage("[TOR-FLUX] New Tor Circuits Requested Successfully.", false, false) | ||
|
||
return true | ||
} | ||
|
||
func main() { | ||
password := os.Getenv("VANGUARD") | ||
if password == "" { | ||
logMessage("[TOR-FLUX] [ERROR] Tor control port password (VANGUARD) is not set or empty.", false, true) | ||
os.Exit(1) | ||
} | ||
|
||
logMessage("[TOR-FLUX] Starting Tor circuit refresh...", false, true) | ||
|
||
// Send NEWNYM signal and get circuit statuses | ||
statusBuffer1 := &bytes.Buffer{} | ||
statusBuffer2 := &bytes.Buffer{} | ||
sendSignal(torControlPort1, password, statusBuffer1) | ||
sendSignal(torControlPort2, password, statusBuffer2) | ||
|
||
logMessage("[TOR-FLUX] Tor circuit refresh completed.", true, true) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[2024-11-30 12:52:17] [TOR-FLUX] Starting Tor circuit refresh... | ||
[2024-11-30 12:52:22] [TOR-FLUX] Current Circuit Status: | ||
[2024-11-30 12:52:22] 250+circuit-status= | ||
287 EXTENDED $08B85FE2212DC548403FB684265D2B63B9C2C237~Femb01tNWh,$E8965A79FB2F335194141E8968755524840C44B6~Piratenpartei08 BUILD_FLAGS=NEED_CAPACITY PURPOSE=GENERAL TIME_CREATED=2024-11-30T17:52:16.723281 | ||
279 BUILT $08B85FE2212DC548403FB684265D2B63B9C2C237~Femb01tNWh,$9308F49A225022FA39011033E1C31EFF5B7B5000~freeiranandtheworld,$AD08584AC6A2A421DAEDF227DA6F0DE53DFE40B6~FreeExit BUILD_FLAGS=NEED_CAPACITY PURPOSE=GENERAL TIME_CREATED=2024-11-30T17:50:13.021081 | ||
281 BUILT $08B85FE2212DC548403FB684265D2B63B9C2C237~Femb01tNWh,$67BE9A0658EF0106FCCB98FF1C68D6AAFFFC3CA9~ChocolateBit,$A5AEBB58BD8E17F74DEC3F6F8B8ACF410A8B1A9A~berenstainbears BUILD_FLAGS=NEED_CAPACITY PURPOSE=GENERAL TIME_CREATED=2024-11-30T17:50:43.141214 | ||
284 BUILT $08B85FE2212DC548403FB684265D2B63B9C2C237~Femb01tNWh,$06E72526BBE040C51C5ADFBAA07ADD9AEB5E1FA1~wien,$5A8292926C5E5A246D35B843A72942FCEC235BAC~FreeExit BUILD_FLAGS=NEED_CAPACITY PURPOSE=GENERAL TIME_CREATED=2024-11-30T17:51:16.335735 | ||
278 BUILT $08B85FE2212DC548403FB684265D2B63B9C2C237~Femb01tNWh,$6E207FAFBC87E3E1199B0D3DDC61EE095DC9B5EA~OgheiK2ZoogoaGooc4E,$311A4533F7A2415F42346A6C8FA77E6FD279594C~DigiGesTor3e2 BUILD_FLAGS=NEED_CAPACITY PURPOSE=GENERAL TIME_CREATED=2024-11-30T17:49:56.897035 | ||
275 BUILT $08B85FE2212DC548403FB684265D2B63B9C2C237~Femb01tNWh,$DB5DE88B4914F60CDEEF581ECCA8DEA59EF26A90~Piratenpartei06,$14AE2154A26F1D42C3C3BEDC10D05FDD9F8545BB~freeasf BUILD_FLAGS=NEED_CAPACITY PURPOSE=GENERAL TIME_CREATED=2024-11-30T17:49:32.692689 | ||
274 BUILT $08B85FE2212DC548403FB684265D2B63B9C2C237~Femb01tNWh,$D8514224881C60572E06351F2BD650BA14ACA75C~experiment626,$9C61FC0A01401EDF71C4048665E53968E81351FC~DigiGesTor5e2 BUILD_FLAGS=NEED_CAPACITY PURPOSE=GENERAL TIME_CREATED=2024-11-30T17:49:21.620934 | ||
283 BUILT $08B85FE2212DC548403FB684265D2B63B9C2C237~Femb01tNWh,$DDDA625FF6C1F1F4554281C2D6DC3FBAD092CB5F~TurtleRelay,$9AA3FF35E7A549D2337E962333D366E102FE4D50~DigiGesTor3e1 BUILD_FLAGS=NEED_CAPACITY PURPOSE=GENERAL TIME_CREATED=2024-11-30T17:51:05.249282 | ||
277 BUILT $08B85FE2212DC548403FB684265D2B63B9C2C237~Femb01tNWh,$706A7674A217BA905FE677E82236B7B968A23DB7~rofltor04,$8C25BA134D579B8AAF420E01215EB2CF06AAE907~DigiGesTor5e4 BUILD_FLAGS=NEED_CAPACITY PURPOSE=GENERAL TIME_CREATED=2024-11-30T17:49:45.821602 | ||
286 BUILT $08B85FE2212DC548403FB684265D2B63B9C2C237~Femb01tNWh,$D7C218579374ED6525E12362A0B2A3DAEB0B5CEC~Unnamed,$BCF55F865EE6EF17E25EFEAF851BC429F190B85D~DigiGesTor5e1 BUILD_FLAGS=NEED_CAPACITY PURPOSE=GENERAL TIME_CREATED=2024-11-30T17:51:47.531552 | ||
. | ||
250 OK | ||
|
||
[2024-11-30 12:52:22] [TOR-FLUX] New Tor Circuits Requested Successfully. | ||
[2024-11-30 12:52:27] [TOR-FLUX] Current Circuit Status: | ||
[2024-11-30 12:52:27] 250+circuit-status= | ||
2118 BUILT $08B85FE2212DC548403FB684265D2B63B9C2C237~Femb01tNWh,$69A412D32D4012972877914E7222DDB7C3C76D42~prsv,$2B4D5AA9997D4DDFF02BC52E173CF0C8FFFD1B9C~JustExiting BUILD_FLAGS=NEED_CAPACITY PURPOSE=GENERAL TIME_CREATED=2024-11-30T17:33:07.373796 | ||
2105 BUILT $08B85FE2212DC548403FB684265D2B63B9C2C237~Femb01tNWh,$D89C4A0F59305D4ECF8B6B614AAA7A8B63ACFD63~Meunvon,$3687FEC7E73F61AC66F7AE251E7DEE6BBD8C0252~Quintex33 BUILD_FLAGS=NEED_CAPACITY,NEED_UPTIME PURPOSE=CONFLUX_LINKED TIME_CREATED=2024-11-30T17:32:39.296581 | ||
2176 BUILT $08B85FE2212DC548403FB684265D2B63B9C2C237~Femb01tNWh,$593A4431DA2E315883406AECE1D1188E02F23D8F~klarheit,$B7047FBDE9C53C39011CA84E5CB2A8E3543066D0~Quintex11 BUILD_FLAGS=NEED_CAPACITY,NEED_UPTIME PURPOSE=CONFLUX_LINKED TIME_CREATED=2024-11-30T17:34:45.760770 | ||
2053 BUILT $08B85FE2212DC548403FB684265D2B63B9C2C237~Femb01tNWh,$923DE89BAD9206721D2B1D60AC7E987097EDF070~DyingHead,$1E5E5C0F0E10F5CA69D0F634B2420BD4CF60C80C~NeelTorExit3D BUILD_FLAGS=NEED_CAPACITY,NEED_UPTIME PURPOSE=CONFLUX_LINKED TIME_CREATED=2024-11-30T17:29:16.630924 | ||
1784 BUILT $08B85FE2212DC548403FB684265D2B63B9C2C237~Femb01tNWh,$C00C926124C9DCC6647964931B56BD874B931E8D~striga,$267AA485F9292289FF2500280BC63EC85BD9FFF3~PflashPunk BUILD_FLAGS=NEED_CAPACITY PURPOSE=GENERAL TIME_CREATED=2024-11-30T17:22:28.704792 | ||
2192 BUILT $08B85FE2212DC548403FB684265D2B63B9C2C237~Femb01tNWh,$8F83B3999B8E16F6C4C7E41665E23FADA300D4C4~InterFlowers404,$887CB7C9DD87ADD7B0A2771280AC17ED913136A5~Emerald173 BUILD_FLAGS=NEED_CAPACITY PURPOSE=GENERAL TIME_CREATED=2024-11-30T17:47:48.262733 | ||
2193 BUILT $08B85FE2212DC548403FB684265D2B63B9C2C237~Femb01tNWh,$4D4CFA0CC8EED2A51C6D73EABA999EAAE833D0B7~YoYuD1N04NoExit,$81EDFBC8F6F5C7CF0ADD5F8E08BC8FABA04089C6~CalyxInstitute17 BUILD_FLAGS=NEED_CAPACITY PURPOSE=GENERAL TIME_CREATED=2024-11-30T17:47:49.644234 | ||
2194 BUILT $08B85FE2212DC548403FB684265D2B63B9C2C237~Femb01tNWh,$30ABFEA883B663C22D35B7467F13476304B40581~glenda1,$B0E93B10BD817250A818ABF7F5C2444AF364DD67~SkyLights BUILD_FLAGS=NEED_CAPACITY PURPOSE=GENERAL TIME_CREATED=2024-11-30T17:47:50.642987 | ||
. | ||
250 OK | ||
|
||
[2024-11-30 12:52:27] [TOR-FLUX] New Tor Circuits Requested Successfully. | ||
[2024-11-30 12:52:27] [TOR-FLUX] Tor circuit refresh completed. | ||
|
||
|
||
|
||
|
||
|