-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
504 lines (439 loc) · 14 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
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
package main
import (
"LiburX/Utils/logger/sl"
"bufio"
"bytes"
"context"
"encoding/hex"
"encoding/json"
"flag"
"fmt"
"io"
"io/fs"
"io/ioutil"
"log"
"log/slog"
"math/big"
"math/rand"
"net/http"
"os"
"regexp"
"strings"
"sync"
"time"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rpc"
"github.com/tyler-smith/go-bip39"
"gopkg.in/yaml.v2"
)
type Config struct {
BatchSize int `yaml:"batchSize"`
RateLimit int `yaml:"rateLimit"`
ETHChain bool `yaml:"ETHChain"`
BSCChain bool `yaml:"BSCChain"`
EthRpcList []string `yaml:"EthRpcList"`
BscRpcList []string `yaml:"BscRpcList"`
SendWebhook bool `yaml:"sendWebhook"`
Log0Wallet bool `yaml:"log0Wallets"`
}
type WebhookData struct {
Content string `json:"content"`
Embeds []WebhookEmbed `json:"embeds"`
}
type WebhookEmbed struct {
Title string `json:"title"`
Description string `json:"description"`
Image WImage `json:"image"`
Footer WFooter `json:"footer"`
Color int `json:"color"`
}
type WImage struct {
URL string `json:"url"`
}
type WFooter struct {
IconURL string `json:"icon_url"`
Text string `json:"text"`
}
type WebhookInfo struct {
Name string `json:"name"`
Owner string `json:"owner"`
After int `json:"after"`
}
type Webhook struct {
Url string
Name string
Owner string
Alive bool
Ratelimit int
TotalSent int
TotalMissed int
}
var webhooks []Webhook
var ThongBaoMessage *WebhookData
var whRegex = regexp.MustCompile(`(?i)^.*(discord|discordapp)\.com\/api\/webhooks\/([\d]+)\/([a-z0-9_-]+)$`)
func init() {
ThongBaoMessage = &WebhookData{
Content: "@everyone FOUND WALLET HAVE BALANCE!!!!",
Embeds: []WebhookEmbed{
{
Title: "wallet_scanner @127.0.0.3107",
Description: "**Address**: `%address%`\n**Balance**: `%eth% | %bnb%`\n**Seed**: `%seed%`\n**PrivateKey**: `%privatekey%`",
Image: WImage{
URL: "https://cdn.discordapp.com/avatars/921245954923987005/5d5c39ac4d55d112633166148486e8a5.png?size=1024",
},
Footer: WFooter{
IconURL: "https://cdn.discordapp.com/avatars/921245954923987005/5d5c39ac4d55d112633166148486e8a5.png?size=1024",
Text: "wallet_scanner @127.0.0.3107",
},
Color: 14194190,
},
},
}
mfile, err := os.OpenFile("message.json", os.O_RDWR|os.O_CREATE, fs.ModePerm)
if err != nil {
fmt.Println("Failed to read message.json!")
} else {
defer mfile.Close()
mb, err := io.ReadAll(mfile)
if err != nil {
panic(err)
}
if len(mb) < 10 {
newone, _ := json.MarshalIndent(ThongBaoMessage, "", " ")
mfile.Write(newone)
} else {
err = json.Unmarshal(mb, ThongBaoMessage)
if err != nil {
fmt.Println("Failed to read unmarshal spam message data!")
}
}
}
wfile, err := os.OpenFile("webhooks.txt", os.O_RDWR, fs.ModePerm)
if err != nil {
fmt.Println("Failed to open webhooks.txt!", err)
return
}
defer wfile.Close()
scanner := bufio.NewScanner(wfile)
for scanner.Scan() {
line := scanner.Text()
if whRegex.MatchString(line) {
webhooks = append(webhooks, Webhook{Url: line, Alive: true})
}
}
if err := scanner.Err(); err != nil {
fmt.Println("Failed to read webhooks.txt!", err)
panic(err)
}
if len(webhooks) == 0 {
fmt.Println("No valid webhooks found in file.")
}
}
func executeWebhookForWallet(walletAddress, ethbalance, bnbbalance, walletPhrase, walletPrivateKey string) error {
for _, webhook := range webhooks {
if !webhook.Alive {
continue
}
client := &http.Client{}
message := *ThongBaoMessage
for i := range message.Embeds {
message.Embeds[i].Description = strings.ReplaceAll(message.Embeds[i].Description, "%address%", walletAddress)
message.Embeds[i].Description = strings.ReplaceAll(message.Embeds[i].Description, "%eth%", ethbalance)
message.Embeds[i].Description = strings.ReplaceAll(message.Embeds[i].Description, "%bnb%", bnbbalance)
message.Embeds[i].Description = strings.ReplaceAll(message.Embeds[i].Description, "%seed%", walletPhrase)
message.Embeds[i].Description = strings.ReplaceAll(message.Embeds[i].Description, "%privatekey%", walletPrivateKey)
}
postBody, err := json.Marshal(message)
if err != nil {
fmt.Println("Error marshaling JSON:", err)
continue
}
req, err := http.NewRequest("POST", webhook.Url, bytes.NewReader(postBody))
if err != nil {
fmt.Println("Error creating POST request:", err)
continue
}
req.Header.Set("User-Agent", "Mozilla/5.0")
req.Header.Set("Content-Type", "application/json")
res, err := client.Do(req)
if err != nil {
fmt.Println("Error sending POST request:", err)
continue
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK && res.StatusCode != http.StatusNoContent {
bodyBytes, _ := io.ReadAll(res.Body)
fmt.Printf("Webhook POST failed, status: %d, body: %s\n", res.StatusCode, string(bodyBytes))
if res.StatusCode == http.StatusNotFound || res.StatusCode == http.StatusForbidden {
fmt.Println("Webhook not found or forbidden; marking as inactive")
webhook.Alive = false
}
} else {
fmt.Println("Webhook POST successful to discord!")
}
time.Sleep(44 * time.Millisecond)
}
return nil
}
func loadConfig(filename string) (Config, error) {
var config Config
yamlFile, err := ioutil.ReadFile(filename)
if err != nil {
return config, err
}
err = yaml.Unmarshal(yamlFile, &config)
if err != nil {
return config, err
}
return config, nil
}
var totalChecked int
func RandomProvider(apiKeys []string) string {
if len(apiKeys) == 0 {
log.Println("No API keys provided.")
return ""
}
rand.Seed(time.Now().UnixNano())
randomIndex := rand.Intn(len(apiKeys))
provider := apiKeys[randomIndex]
return provider
}
func GenWallet(mode string) (string, string, string, error) {
switch mode {
case "randomprivatekey":
privateKey, err := crypto.GenerateKey()
if err != nil {
return "", "", "", err
}
address := crypto.PubkeyToAddress(privateKey.PublicKey).Hex()
privateKeyBytes := crypto.FromECDSA(privateKey)
privateKeyHex := hex.EncodeToString(privateKeyBytes)
return address, "", privateKeyHex, nil
case "random12seed":
entropy, err := bip39.NewEntropy(128)
if err != nil {
return "", "", "", err
}
mnemonic, err := bip39.NewMnemonic(entropy)
if err != nil {
return "", "", "", err
}
seed := bip39.NewSeed(mnemonic, "")
privateKey, err := crypto.ToECDSA(seed[:32])
if err != nil {
return "", "", "", err
}
address := crypto.PubkeyToAddress(privateKey.PublicKey).Hex()
privateKeyHex := hexutil.Encode(crypto.FromECDSA(privateKey))[2:]
return address, mnemonic, privateKeyHex, nil
case "test":
privatekeytest := "0000000000000000000000000000000000000000000000000000000000000013"
privateKeyBytes, err := hex.DecodeString(privatekeytest)
if err != nil {
return "", "", "", err
}
privateKey, err := crypto.ToECDSA(privateKeyBytes)
if err != nil {
return "", "", "", err
}
address := crypto.PubkeyToAddress(privateKey.PublicKey).Hex()
privateKeyHex := hex.EncodeToString(privateKeyBytes)
return address, "", privateKeyHex, nil
default:
return "", "", "", fmt.Errorf("unsupported mode: %s", mode)
}
}
func BatchWallets(batchSize int, mode string) ([]string, []string, []string, error) {
addresses := make([]string, batchSize)
mnemonics := make([]string, batchSize)
privateKeys := make([]string, batchSize)
for i := 0; i < batchSize; i++ {
address, mnemonic, privateKey, err := GenWallet(mode)
if err != nil {
return nil, nil, nil, err
}
addresses[i] = address
mnemonics[i] = mnemonic
privateKeys[i] = privateKey
}
return addresses, mnemonics, privateKeys, nil
}
func checkBalances(ethClient, bscClient *rpc.Client, addresses []string, ethChain, bscChain bool) ([]*big.Float, []*big.Float, error) {
batchSize := len(addresses)
ethBalances := make([]*big.Float, batchSize)
bscBalances := make([]*big.Float, batchSize)
if ethChain {
err := FetchBalances(ethClient, addresses, ethBalances)
if err != nil {
return nil, nil, err
}
} else {
for i := range ethBalances {
ethBalances[i] = big.NewFloat(0)
}
}
if bscChain {
err := FetchBalances(bscClient, addresses, bscBalances)
if err != nil {
return nil, nil, err
}
} else {
for i := range bscBalances {
bscBalances[i] = big.NewFloat(0)
}
}
return ethBalances, bscBalances, nil
}
func FetchBalances(client *rpc.Client, addresses []string, balances []*big.Float) error {
batchSize := len(addresses)
batchElems := make([]rpc.BatchElem, batchSize)
for i, address := range addresses {
batchElems[i] = rpc.BatchElem{
Method: "eth_getBalance",
Args: []interface{}{address, "latest"},
Result: new(string),
}
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
err := client.BatchCallContext(ctx, batchElems)
if err != nil {
slog.Error("Failed to batch call context", sl.Err(err))
return err
}
for i, elem := range batchElems {
if elem.Error != nil {
slog.Error("Request error", slog.String("address", addresses[i]), slog.String("error", elem.Error.Error()))
balances[i] = big.NewFloat(0)
continue
}
balanceStr := *(elem.Result.(*string))
balance := new(big.Int)
balance.SetString(balanceStr[2:], 16)
balances[i] = new(big.Float).Quo(new(big.Float).SetInt(balance), big.NewFloat(1e18))
}
return nil
}
func FormatBalance(balance *big.Float) string {
balanceStr := balance.Text('f', 18)
return strings.TrimRight(strings.TrimRight(balanceStr, "0"), ".")
}
func ProcessBatch(batchSize int, mode string, ethRpcList, bscRpcList []string, config Config) error {
ethProviderURL := RandomProvider(ethRpcList)
bscProviderURL := RandomProvider(bscRpcList)
ethClient, err := rpc.DialContext(context.Background(), ethProviderURL)
if err != nil {
return err
}
defer ethClient.Close()
bscClient, err := rpc.DialContext(context.Background(), bscProviderURL)
if err != nil {
return err
}
defer bscClient.Close()
addresses, mnemonics, privateKeys, err := BatchWallets(batchSize, mode)
if err != nil {
return err
}
ethBalances, bscBalances, err := checkBalances(ethClient, bscClient, addresses, config.ETHChain, config.BSCChain)
if err != nil {
return err
}
for i, ethBalance := range ethBalances {
bscBalance := bscBalances[i]
ethBalanceStr := FormatBalance(ethBalance)
bnbBalanceStr := FormatBalance(bscBalance)
if ethBalance.Cmp(big.NewFloat(0)) > 0 || bscBalance.Cmp(big.NewFloat(0)) > 0 {
var entry string
if ethBalance.Cmp(big.NewFloat(0)) > 0 && bscBalance.Cmp(big.NewFloat(0)) > 0 {
entry = fmt.Sprintf("✅ %s | ETH: %s | BNB: %s | %s | %s | %s\n", addresses[i], ethBalanceStr, bnbBalanceStr, mnemonics[i], privateKeys[i], mode)
} else if ethBalance.Cmp(big.NewFloat(0)) > 0 {
entry = fmt.Sprintf("✅ %s | ETH: %s | BNB: OwO | %s | %s | %s\n", addresses[i], ethBalanceStr, mnemonics[i], privateKeys[i], mode)
} else {
entry = fmt.Sprintf("✅ %s | ETH: OwO | BNB: %s | %s | %s | %s\n", addresses[i], bnbBalanceStr, mnemonics[i], privateKeys[i], mode)
}
fmt.Print(entry)
file, err := os.OpenFile("result.txt", os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
if err != nil {
fmt.Println("Failed to open result file:", err)
return err
}
defer file.Close()
if _, err := file.WriteString(entry); err != nil {
fmt.Println("Failed to write to result file:", err)
return err
}
if config.SendWebhook {
err := executeWebhookForWallet(addresses[i], ethBalanceStr, bnbBalanceStr, mnemonics[i], privateKeys[i])
if err != nil {
fmt.Println("Failed to send webhook:", err)
}
}
} else {
entry := fmt.Sprintf("❌ %s | ETH: %s | BNB: %s | %s | %s\n", addresses[i], ethBalanceStr, bnbBalanceStr, privateKeys[i], mode)
fmt.Print(entry)
if config.Log0Wallet {
file, err := os.OpenFile("0wallets.txt", os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
if err != nil {
fmt.Println("Failed to open 0wallets file:", err)
return err
}
defer file.Close()
if _, err := file.WriteString(entry); err != nil {
fmt.Println("Failed to write to 0wallets file:", err)
return err
}
}
}
totalChecked++
}
return nil
}
func RetryCheckBalance(batchSize int, retries int, mode string, ethRpcList []string, bscRpcList []string, config Config, wg *sync.WaitGroup) {
defer wg.Done()
for attempt := 0; attempt < retries; attempt++ {
err := ProcessBatch(batchSize, mode, ethRpcList, bscRpcList, config)
if err == nil {
return
}
fmt.Printf("Error: %s. Retrying in %d seconds...\n", err.Error(), 1<<attempt)
time.Sleep(time.Duration(1<<attempt) * time.Second)
}
fmt.Println("Failed after multiple retries.")
}
var mode string
func init() {
flag.StringVar(&mode, "mode", "random12seed", "Mode Support: randomprivatekey or random12seed")
flag.Parse()
}
func main() {
config, err := loadConfig("config.yaml")
if err != nil {
log.Fatalf("error loading config: %v", err)
}
fmt.Println(config.EthRpcList)
fmt.Println(config.BscRpcList)
fmt.Println("Supported Chains:")
if config.ETHChain {
fmt.Println("- Ethereum")
}
if config.BSCChain {
fmt.Println("- Binance Smart Chain")
}
fmt.Println("")
walletsPerCycle := config.BatchSize * config.RateLimit
fmt.Println("PerCycle:", walletsPerCycle)
fmt.Println("")
fmt.Println("Waiting 3 sec...")
time.Sleep(3 * time.Second)
var wg sync.WaitGroup
for {
for i := 0; i < config.RateLimit; i++ {
wg.Add(1)
go RetryCheckBalance(config.BatchSize, 5, mode, config.EthRpcList, config.BscRpcList, config, &wg)
}
wg.Wait()
fmt.Printf("Total wallets checked: %d\n", totalChecked)
}
}