-
Notifications
You must be signed in to change notification settings - Fork 17
/
bitcoin-wallet-bruteforce.go
191 lines (156 loc) · 5.15 KB
/
bitcoin-wallet-bruteforce.go
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
package main
import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"encoding/hex"
"fmt"
"log"
"net"
"net/http"
"net/url"
"os"
"strconv"
"sync"
"time"
"encoding/json"
"github.com/btcsuite/btcutil/base58"
"golang.org/x/crypto/ripemd160"
"crypto/sha256"
)
const botToken = "your_bot_token_here"
const chatID = "your_chat_id_here"
type BlockCypherResponse struct {
Balance int `json:"balance"`
}
func getLocalIP() (string, error) {
addrs, err := net.InterfaceAddrs()
if err != nil {
return "", err
}
for _, addr := range addrs {
if ipNet, ok := addr.(*net.IPNet); ok && !ipNet.IP.IsLoopback() {
if ipNet.IP.To4() != nil {
return ipNet.IP.String(), nil
}
}
}
return "", fmt.Errorf("no non-loopback address found")
}
func sendMessage(botToken, chatID, message string) error {
apiURL := fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage?chat_id=%s&text=%s", botToken, chatID, url.QueryEscape(message))
resp, err := http.Get(apiURL)
if err != nil {
return err
}
defer resp.Body.Close()
return nil
}
func generateKeyAndAddress() (string, string, error) {
privateKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
return "", "", err
}
publicKey := privateKey.PublicKey
address, err := publicKeyToAddress(publicKey)
if err != nil {
return "", "", err
}
return hex.EncodeToString(privateKey.D.Bytes()), address, nil
}
func publicKeyToAddress(publicKey ecdsa.PublicKey) (string, error) {
pubKeyBytes := append(publicKey.X.Bytes(), publicKey.Y.Bytes()...)
sha256Hash := sha256.New()
sha256Hash.Write(pubKeyBytes)
sha256Result := sha256Hash.Sum(nil)
ripemd160Hash := ripemd160.New()
ripemd160Hash.Write(sha256Result)
ripemd160Result := ripemd160Hash.Sum(nil)
networkVersion := byte(0x00)
addressBytes := append([]byte{networkVersion}, ripemd160Result...)
checksum := sha256Checksum(addressBytes)
fullAddress := append(addressBytes, checksum...)
return base58.Encode(fullAddress), nil
}
func sha256Checksum(input []byte) []byte {
firstSHA := sha256.New()
firstSHA.Write(input)
result := firstSHA.Sum(nil)
secondSHA := sha256.New()
secondSHA.Write(result)
finalResult := secondSHA.Sum(nil)
return finalResult[:4]
}
func checkBalance(address string) (int, error) {
time.Sleep(3 * time.Second)
url := fmt.Sprintf("https://api.blockcypher.com/v1/btc/main/addrs/%s/balance", address)
resp, err := http.Get(url)
if err != nil {
return 0, err
}
defer resp.Body.Close()
var response BlockCypherResponse
if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
return 0, err
}
return response.Balance, nil
}
func worker(id int, wg *sync.WaitGroup, mutex *sync.Mutex, outputFile string) {
defer wg.Done()
for {
privateKey, publicAddress, err := generateKeyAndAddress()
if err != nil {
log.Printf("Worker %d: Failed to generate key and address: %s", id, err)
continue
}
balance, err := checkBalance(publicAddress)
if err != nil {
log.Printf("Worker %d: Failed to check balance for %s: %s", id, publicAddress, err)
continue
}
fmt.Printf("Privatekey: %s Publicaddress: %s Balance: %d\n", privateKey, publicAddress, balance)
if balance > 0 {
mutex.Lock()
file, err := os.OpenFile(outputFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Printf("Worker %d: Failed to open file: %s", id, err)
mutex.Unlock()
continue
}
if _, err := file.WriteString(fmt.Sprintf("%s:%s:%d\n", privateKey, publicAddress, balance)); err != nil {
log.Printf("Worker %d: Failed to write to file: %s", id, err)
}
file.Close()
mutex.Unlock()
message := fmt.Sprintf("Privatekey: %s Publicaddress: %s Balance: %d", privateKey, publicAddress, balance)
if err := sendMessage(botToken, chatID, message); err != nil {
log.Printf("Worker %d: Failed to send Telegram message: %s", id, err)
}
}
}
}
func main() {
if len(os.Args) != 3 {
fmt.Println("Usage: ./golangscript <threads> <output-file.txt>")
os.Exit(1)
}
numThreads, err := strconv.Atoi(os.Args[1])
if err != nil {
log.Fatalf("Invalid number of threads: %s", err)
}
outputFile := os.Args[2]
var wg sync.WaitGroup
var mutex sync.Mutex
ip, err := getLocalIP()
if err != nil {
log.Fatalf("Failed to get local IP address: %s", err)
}
if err := sendMessage(botToken, chatID, fmt.Sprintf("Started BTC Finder on: %s", ip)); err != nil {
log.Fatalf("Failed to send startup message: %s", err)
}
for i := 0; i < numThreads; i++ {
wg.Add(1)
go worker(i, &wg, &mutex, outputFile)
}
wg.Wait()
}