5
5
import io .sentry .Sentry ;
6
6
import net .olympiccode .vhackos .api .entities .AppType ;
7
7
import net .olympiccode .vhackos .api .entities .BruteForceState ;
8
- import net .olympiccode .vhackos .api .entities .impl .BruteForceImpl ;
9
8
import net .olympiccode .vhackos .api .exceptions .ExploitFailedException ;
10
9
import net .olympiccode .vhackos .api .network .BruteForce ;
11
10
import net .olympiccode .vhackos .api .network .ExploitedTarget ;
12
- import net .olympiccode .vhackos .api .network .NetworkManager ;
13
11
import net .olympiccode .vhackos .bot .core .BotService ;
14
12
import net .olympiccode .vhackos .bot .core .vHackOSBot ;
15
13
import org .slf4j .Logger ;
18
16
import javax .script .ScriptEngine ;
19
17
import javax .script .ScriptEngineManager ;
20
18
import javax .script .ScriptException ;
21
- import java .nio .channels .NetworkChannel ;
22
19
import java .util .ArrayList ;
23
20
import java .util .concurrent .Executors ;
24
21
import java .util .concurrent .ScheduledExecutorService ;
28
25
public class NetworkingService implements BotService {
29
26
public static ScheduledExecutorService networkingService ;
30
27
Logger LOG = LoggerFactory .getLogger ("NetworkingService" );
28
+ Cache <String , String > cache = CacheBuilder .newBuilder ()
29
+ .maximumSize (500 )
30
+ .expireAfterWrite (60 * 5 + 30 , TimeUnit .SECONDS ).build ();
31
31
32
32
public NetworkingService () {
33
33
LOG .info ("Creating NetworkingService..." );
34
34
networkingService = Executors .newScheduledThreadPool (1 , new NetworkingServiceFactory ());
35
35
}
36
36
37
- public class NetworkingServiceFactory implements ThreadFactory {
38
- public Thread newThread (Runnable r ) {
39
- return new Thread (r , "vHackOSBot-NetworkingService" );
40
- }
41
- }
42
-
43
-
44
37
@ Override
45
38
public ScheduledExecutorService getService () {
46
39
return networkingService ;
@@ -54,31 +47,28 @@ public void setup() {
54
47
networkingService .scheduleAtFixedRate (() -> runService (), 0 , 60000 , TimeUnit .MILLISECONDS );
55
48
}
56
49
57
- Cache <String , String > cache = CacheBuilder .newBuilder ()
58
- .maximumSize (500 )
59
- .expireAfterWrite (60 *5 +30 , TimeUnit .SECONDS ).build ();
60
-
61
50
public void runService () {
62
51
try {
63
- ((ArrayList <BruteForce >)((ArrayList )vHackOSBot .api .getTaskManager ().getActiveBrutes ()).clone ()).forEach (bruteForce -> {
52
+ ((ArrayList <BruteForce >) ((ArrayList ) vHackOSBot .api .getTaskManager ().getActiveBrutes ()).clone ()).forEach (bruteForce -> {
64
53
if (cache .asMap ().containsKey (bruteForce .getIp ())) return ;
65
54
if (bruteForce .getState () == BruteForceState .SUCCESS ) {
66
55
cache .put (bruteForce .getIp (), "" );
67
56
ExploitedTarget etarget = bruteForce .exploit ();
68
57
ExploitedTarget .Banking banking = etarget .getBanking ();
69
58
70
59
if (banking .isBruteForced ()) {
71
- long av = banking .getAvaliableMoney ();
72
- if (av > 0 && banking .withdraw (NetworkingConfigValues .withdrawPorcentage )) {
73
- LOG .info ("Withdrawed " + av + " of " + banking .getTotal () + " from " + etarget .getIp () + "." );
74
- } else {
75
- LOG .error ("Failed to withdraw from " + etarget .getIp () + "." );
60
+ if (banking .canAttack ()) {
61
+ long av = banking .getAvaliableMoney ();
62
+ if (av > 0 && banking .withdraw (NetworkingConfigValues .withdrawPorcentage )) {
63
+ LOG .info ("Withdrawed " + av + " of " + banking .getTotal () + " from " + etarget .getIp () + "." );
64
+ } else {
65
+ LOG .error ("Failed to withdraw from " + etarget .getIp () + "." );
66
+ }
67
+ if (eval (etarget )) {
68
+ LOG .info ("Removing bruteforce from " + etarget .getIp () + "." );
69
+ bruteForce .remove ();
70
+ }
76
71
}
77
- if (eval (etarget )) {
78
- LOG .info ("Removing bruteforce from " + etarget .getIp () + "." );
79
- bruteForce .remove ();
80
- }
81
-
82
72
} else {
83
73
if (banking .startBruteForce ()) {
84
74
LOG .info ("Started bruteforce at " + etarget .getIp ());
@@ -99,20 +89,20 @@ public void runService() {
99
89
}
100
90
});
101
91
if (vHackOSBot .api .getStats ().getExploits () > 0 ) {
102
- int success = 0 ;
103
- int tries = 6 * 3 ;
92
+ int success = 0 ;
93
+ int tries = 6 * 3 ;
104
94
LOG .info ("Starting exploits..." );
105
- while (success < 6 && tries > 0 ) {
106
- success += scan ();
107
- tries --;
108
- }
109
- LOG .info ("Finished exploits, exploited " + success + " targets in " + tries + " tries." );
95
+ while (success < 6 && tries > 0 ) {
96
+ success += scan ();
97
+ tries --;
98
+ }
99
+ LOG .info ("Finished exploits, exploited " + success + " targets in " + tries + " tries." );
110
100
}
111
101
} catch (Exception e ) {
112
102
Sentry .capture (e );
103
+ LOG .warn ("The networking service has been shutdown due to an error." );
113
104
e .printStackTrace ();
114
105
networkingService .shutdownNow ();
115
- LOG .warn ("The networking service has been shutdown due to an error." );
116
106
}
117
107
}
118
108
@@ -159,4 +149,10 @@ public boolean eval(ExploitedTarget target) {
159
149
}
160
150
return false ;
161
151
}
152
+
153
+ public class NetworkingServiceFactory implements ThreadFactory {
154
+ public Thread newThread (Runnable r ) {
155
+ return new Thread (r , "vHackOSBot-NetworkingService" );
156
+ }
157
+ }
162
158
}
0 commit comments