Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CYBSC-5300 Project- Sayontani-Saqib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tanibose
CYBSC-5300 Project- Sayontani-Saqib
Commits
78157230
Commit
78157230
authored
3 months ago
by
tanibose
Browse files
Options
Downloads
Patches
Plain Diff
Attacker code
parent
865999f8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
attacker.py
+54
-0
54 additions, 0 deletions
attacker.py
with
54 additions
and
0 deletions
attacker.py
0 → 100644
+
54
−
0
View file @
78157230
import
socket
import
signal
import
sys
import
time
# Socket configuration
HOST
=
'
127.0.0.1
'
# Localhost
PORT
=
65432
# Port of the main script
def
send_signal
(
signal_value
):
"""
Sends a signal to the main script to indicate an attack or stop signal.
"""
with
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
as
client_socket
:
try
:
client_socket
.
connect
((
HOST
,
PORT
))
client_socket
.
sendall
(
str
(
signal_value
).
encode
())
print
(
f
"
[INFO] Sent signal:
{
signal_value
}
"
)
except
ConnectionRefusedError
:
print
(
"
[ERROR] Failed to connect to the main script. Is it running?
"
)
sys
.
exit
(
1
)
def
cleanup
(
signal_received
,
frame
):
"""
Cleanup when the script is interrupted (CTRL+C).
Sends a signal to stop the attack.
"""
print
(
"
\n
[INFO] Stopping attack...
"
)
send_signal
(
0
)
# Signal to stop the attack
sys
.
exit
(
0
)
def
launch_attack
():
"""
Launches a simulated DoS attack by continuously sending the attack signal.
"""
print
(
"
[INFO] Starting DoS attack...
"
)
send_signal
(
1
)
# Signal to indicate the attack has started
while
True
:
# Simulate sending attack packets (e.g., using hping3)
# Uncomment the below line if hping3 is available and configure accordingly
# os.system(f"hping3 --flood --icmp {TARGET_IP}")
print
(
"
[INFO] Simulating attack... (Press CTRL+C to stop)
"
)
time
.
sleep
(
5
)
# Simulate attack duration
if
__name__
==
"
__main__
"
:
# Handle CTRL+C gracefully
signal
.
signal
(
signal
.
SIGINT
,
cleanup
)
try
:
launch_attack
()
except
Exception
as
e
:
print
(
f
"
[ERROR]
{
e
}
"
)
cleanup
(
None
,
None
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment