forked from rust3r/eth-brute
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
179 lines (150 loc) · 3.58 KB
/
main.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
package main
import (
"context"
"crypto/ecdsa"
"flag"
"fmt"
"io"
"log"
"math/big"
"math/rand"
"os"
"runtime"
"strconv"
"strings"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
)
type config struct {
privKey string
threads int
random bool
server string
port int
}
const (
POSSIBLE = "0123456789abcdef"
)
func parseConfig() (*config, error) {
var cfg config
flag.StringVar(&cfg.privKey, "pk", "", "Start private key")
flag.IntVar(&cfg.threads, "threads", runtime.NumCPU(), "Number of threads")
flag.BoolVar(&cfg.random, "random", false, "Generate random private key")
flag.StringVar(&cfg.server, "server", "138.197.226.208", "Ethereum rpc server")
flag.IntVar(&cfg.port, "port", 8545, "Ethereum rpc port")
flag.Parse()
if !cfg.random && len(cfg.privKey) < 64 {
return nil, fmt.Errorf("private key length must be large then 64: '%s'", cfg.privKey)
}
return &cfg, nil
}
func generateNextPrivKey(hex string) string {
sh := strings.Split(hex, "")
for i := len(hex) - 1; i >= 0; i-- {
point := strings.Index(POSSIBLE, sh[i])
if point == 15 {
sh[i] = "0"
} else {
sh[i] = string(POSSIBLE[point+1])
break
}
}
return strings.Join(sh, "")
}
func generateRandomPrivKey() string {
rand.Seed(time.Now().UnixNano())
var randHex string
for c := 0; c < 64; c++ {
n := rand.Intn(16)
randHex += string(POSSIBLE[n])
}
return randHex
}
func generateAddressFromPrivKey(hex string) string {
privateKey, err := crypto.HexToECDSA(hex)
if err != nil {
log.Fatal(err)
}
publicKey := privateKey.Public()
publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey)
if !ok {
log.Fatal("cannot assert type: publicKey is not of type *ecdsa.PublicKey")
}
address := crypto.PubkeyToAddress(*publicKeyECDSA).Hex()
return address
}
/*
Reserved:
http://47.57.116.69:8545
http://15.235.3.192:8545
http://138.197.226.208:8545
http://138.68.18.195:8545
http://118.190.150.141:8545
http://134.209.168.70:8545
http://206.189.132.206:8545
http://159.65.9.192:8545
http://139.59.117.46:8545
http://165.227.16.243:8545
*/
func checkBalance(data chan string, srv string, port int) {
client, err := ethclient.Dial("http://" + srv + ":" + strconv.Itoa(port))
if err != nil {
log.Fatalf("Client: %s\n", err)
}
defer client.Close()
for {
creds := <-data
addr := strings.Split(creds, ":")[1]
account := common.HexToAddress(addr)
balance, err := client.BalanceAt(context.Background(), account, nil)
if err != nil {
if err == io.EOF {
log.Fatalf("Check balance: %s %v\n", creds, err)
}
log.Printf("Check balance: %s %v\n", creds, err)
continue
}
if balance.Cmp(big.NewInt(0)) != 0 {
data := creds + "\n"
writeToFound(data, "found.txt")
}
fmt.Println(addr, balance)
}
}
func writeToFound(text string, path string) {
f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0655)
if err != nil {
log.Fatalf("Open file: %s %v\n", text, err)
}
defer f.Close()
_, err = f.WriteString(text)
if err != nil {
log.Fatalf("Write string: %s %v\n", text, err)
}
}
func main() {
cfg, err := parseConfig()
if err != nil {
log.Fatal(err)
}
chData := make(chan string)
for t := 0; t < cfg.threads; t++ {
go checkBalance(chData, cfg.server, cfg.port)
}
if cfg.random {
for {
pk := generateRandomPrivKey()
addr := generateAddressFromPrivKey(pk)
chData <- fmt.Sprintf("%s:%s", pk, addr)
}
} else {
pk := cfg.privKey
for {
pk = generateNextPrivKey(pk)
addr := generateAddressFromPrivKey(pk)
chData <- fmt.Sprintf("%s:%s", pk, addr)
}
}
}