@@ -158,9 +158,7 @@ public Classification classify(final ConnectionEvent event)
158158 try
159159 {
160160 int delta = module .evaluate (event , findings );
161-
162161 score += Math .max (0 , Math .min (delta , 100 ));
163-
164162 findings .add ("MOD [" + module .moduleName () + "] returned delta=" + delta );
165163 }
166164 catch (Exception e )
@@ -193,14 +191,13 @@ private int checkIpRate(final ConnectionEvent event, final List<String> findings
193191
194192 if (count >= RATE_LIMIT )
195193 {
196- findings .add ("WARN IP " + event .ip + " made " + count + " connections in the last " + RATE_WINDOW_SECS + "s (threshold=" + RATE_LIMIT + ") — rate limited" );
197-
194+ findings .add ("WARN IP " + event .ip + " made " + count + " connections in the last "
195+ + RATE_WINDOW_SECS + "s (threshold=" + RATE_LIMIT + ") — rate limited" );
198196 return 40 ;
199197 }
200198 else if (count >= RATE_LIMIT / 2 )
201199 {
202200 findings .add ("INFO IP " + event .ip + " connection count approaching limit (" + count + "/" + RATE_LIMIT + ")" );
203-
204201 return 15 ;
205202 }
206203 }
@@ -212,20 +209,16 @@ else if (count >= RATE_LIMIT / 2)
212209 private int checkPortScan (final ConnectionEvent event , final List <String > findings )
213210 {
214211 Set <Integer > ports = ipPorts .computeIfAbsent (event .ip , k -> ConcurrentHashMap .newKeySet ());
215-
216212 ports .add (event .port );
217-
218213 int distinct = ports .size ();
219214
220215 if (distinct >= PORT_SCAN_THRESHOLD )
221216 {
222- findings .add ("WARN IP " + event .ip + " has probed " + distinct + " distinct ports " + ports + " — possible port scan" );
223-
217+ findings .add ("WARN IP " + event .ip + " has probed " + distinct + " distinct ports " + ports
218+ + " — possible port scan" );
224219 return 30 ;
225220 }
226-
227221 findings .add ("PASS IP " + event .ip + " port probe count normal (" + distinct + ")" );
228-
229222 return 0 ;
230223 }
231224
@@ -235,25 +228,20 @@ private int checkGeoConcentration(final ConnectionEvent event, final List<String
235228 if (event .countryCode == null || event .countryCode .isBlank ())
236229 {
237230 findings .add ("INFO no geo-location data available for " + event .ip );
238-
239231 return 0 ;
240232 }
241233
242234 int total = totalConnections + 1 ; // +1 for current event
243-
244235 int fromCountry = countryCount .getOrDefault (event .countryCode , 0 ) + 1 ;
245-
246236 int pct = (fromCountry * 100 ) / total ;
247237
248238 if (pct >= GEO_CONCENTRATION && total > 5 ) // require minimum sample
249239 {
250- findings .add ("WARN " + pct + "% of connections originate from " + event .countryCode + " (" + fromCountry + "/" + total + ") — geo concentration flag" );
251-
240+ findings .add ("WARN " + pct + "% of connections originate from " + event .countryCode
241+ + " (" + fromCountry + "/" + total + ") — geo concentration flag" );
252242 return 20 ;
253243 }
254-
255244 findings .add ("PASS geo distribution normal for " + event .countryCode + " (" + pct + "%)" );
256-
257245 return 0 ;
258246 }
259247
@@ -263,23 +251,6 @@ private int checkGeoConcentration(final ConnectionEvent event, final List<String
263251 "<script>" , "SELECT " , "DROP TABLE" , "UNION SELECT"
264252 );
265253
266- // Patterns indicating large memory allocation attempts in submitted source/payload
267- private static final List <String > LARGE_ALLOC_PATTERNS = List .of (
268- "new byte[" , "new int[" , "new long[" , "new char[" , "new Object[" ,
269- "Integer.MAX_VALUE" , "Long.MAX_VALUE" , "1<<30" , "1 << 30" , "1<<31" , "1 << 31"
270- );
271-
272- // Patterns indicating spin loops
273- private static final List <String > SPIN_LOOP_PATTERNS = List .of (
274- "while(true)" , "while (true)" , "for(;;)" , "for ( ; ; )" , "for(; ;)" ,
275- "}while(true)" , "} while (true)"
276- );
277-
278- // System binary execution paths
279- private static final List <String > SYS_BINARY_PATTERNS = List .of (
280- "\" /usr/bin/" , "\" /bin/" , "\" /sbin/" , "\" /usr/sbin/" , "\" /usr/local/bin/" , "exec(\" /"
281- );
282-
283254 private int checkPayload (final ConnectionEvent event , final List <String > findings )
284255 {
285256 if (event .payload == null || event .payload .isBlank ())
@@ -290,8 +261,6 @@ private int checkPayload(final ConnectionEvent event, final List<String> finding
290261
291262 String lower = event .payload .toLowerCase ();
292263 int penalty = 0 ;
293-
294- // ── Standard bad keywords ─────────────────────────────────────────────
295264 for (String kw : BAD_KEYWORDS )
296265 {
297266 if (lower .contains (kw .toLowerCase ()))
@@ -300,48 +269,6 @@ private int checkPayload(final ConnectionEvent event, final List<String> finding
300269 penalty += 15 ;
301270 }
302271 }
303-
304- // ── Large memory allocation ───────────────────────────────────────────
305- for (String pat : LARGE_ALLOC_PATTERNS )
306- {
307- if (event .payload .contains (pat ))
308- {
309- findings .add ("WARN payload contains large-allocation pattern: [" + pat + "] — possible memory exhaustion" );
310- penalty += 20 ;
311- break ;
312- }
313- }
314-
315- // ── Spin loop ─────────────────────────────────────────────────────────
316- for (String pat : SPIN_LOOP_PATTERNS )
317- {
318- if (event .payload .contains (pat ))
319- {
320- findings .add ("WARN payload contains spin-loop pattern: [" + pat + "] — possible CPU exhaustion" );
321- penalty += 25 ;
322- break ;
323- }
324- }
325-
326- // ── System binary execution ───────────────────────────────────────────
327- for (String pat : SYS_BINARY_PATTERNS )
328- {
329- if (event .payload .contains (pat ))
330- {
331- findings .add ("WARN payload references system binary path: [" + pat + "] — possible privilege escalation" );
332- penalty += 30 ;
333- break ;
334- }
335- }
336-
337- // ── Constructor with loop (source-level pattern in payload) ───────────
338- if (event .payload .matches ("(?s).*public\\ s+\\ w+\\ s*\\ ([^)]*\\ )\\ s*\\ {[^}]*(while|for\\ s*\\ (|do\\ s*\\ {)[^}]*\\ }.*" )
339- && !event .payload .contains ("break" ) && !event .payload .contains ("return" ))
340- {
341- findings .add ("WARN payload contains a constructor with a loop and no visible exit — possible constructor hang" );
342- penalty += 20 ;
343- }
344-
345272 if (penalty == 0 ) findings .add ("PASS payload keyword scan clean" );
346273 return penalty ;
347274 }
@@ -428,6 +355,6 @@ public String summary()
428355 }
429356
430357 /** Returns the individual finding lines (PASS / INFO / FAIL). */
431- public java . util . List <String > findings () { return findings ; }
358+ public List <String > findings () { return findings ; }
432359 }
433360}
0 commit comments