UNCLASSIFIED

Skip to content
Snippets Groups Projects
Commit 9097090c authored by Jeffrey Mathiowetz's avatar Jeffrey Mathiowetz
Browse files

gensite genslides

parent 4050ebe1
No related merge requests found
Pipeline #121981 passed with stages
in 1 minute and 36 seconds
= link:https://net.cybbh.io/public/networking/latest/12_programming/fg.html[PACKET CREATION AND SOCKET PROGRAMMING,window=_blank]
= link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html[PACKET CREATION AND SOCKET PROGRAMMING,window=_blank]
112-CCTC18 - Networking
v4, 2023-01-01
//.images
......@@ -55,7 +55,7 @@ image::slide_background_fade.png[background, size=100%]
== link:https://net.cybbh.io/public/networking/latest/points.html#:~:text=Socket%20Creation%20and,539[Assessment,window=_blank]
== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/00_Administrative/points.html#points-breakdown-by-module:~:text=Socket%20Creation%20and,539[Assessment,window=_blank]
* You will be assessed via CTFd challenges where you will need to score 56/80 points to achieve a 70%.
......@@ -63,7 +63,7 @@ image::slide_background_fade.png[background, size=100%]
== link:https://net.cybbh.io/public/networking/latest/12_programming/fg.html#_12_1_understanding_socket_types_for_network_functions[Socket Types,window=_blank]
== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#51-understanding-socket-types-for-network-functions[Socket Types,window=_blank]
* Stream Sockets - Connection oriented and sequenced; methods for connection establishment and tear-down. Used with TCP, SCTP, and Bluetooth.
* Datagram Sockets - Connectionless; designed for quickly sending and receiving data. Used with UDP.
......@@ -73,28 +73,27 @@ image::slide_background_fade.png[background, size=100%]
== User Space vs. Kernel Space Sockets
=== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#52-differentiate-user-spacekernel-space-sockets[User Space Sockets,window=_blank]
* User Space Sockets
* The most common sockets that do not require elevated privileges to perform actions on behalf of user applications.
** Stream Sockets
** Datagram Sockets
* Kernel Space Sockets
** RAW Sockets
image::slide_background_fade.png[background, size=100%]
== link:https://net.cybbh.io/public/networking/latest/12_programming/fg.html#_12_2_differentiate_user_spacekernel_space_sockets[Socket Creation and Privilege Level,window=_blank]
=== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#52-differentiate-user-spacekernel-space-sockets[Kernel Space Sockets,window=_blank]
* User Space Sockets - The most common sockets that do not require elevated privileges to perform actions on behalf of user applications.
* Kernel Space Sockets - Attempts to access hardware directly on behalf of a user application to either prevent encapsulation/decapsulation or to create packets from scratch, which requires elevated privileges.
* Attempts to access hardware directly on behalf of a user application to either prevent encapsulation/decapsulation or to create packets from scratch, which requires elevated privileges.
** RAW Sockets
image::slide_background_fade.png[background, size=100%]
=== link:https://net.cybbh.io/public/networking/latest/12_programming/fg.html#_12_2_1_user_space_applications_and_sockets[User Space Applications/Sockets,window=_blank]
=== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#521-user-space-applications-and-sockets[User Space Applications/Sockets,window=_blank]
* Using tcpdump or wireshark to read a file
* Using nmap with no switches
......@@ -106,7 +105,7 @@ image::slide_background_fade.png[background, size=100%]
=== link:https://net.cybbh.io/public/networking/latest/12_programming/fg.html#_12_2_2_kernel_space_applications_and_sockets[Kernel Space Applications/Sockets,window=_blank]
=== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#522-kernel-space-applications-and-sockets[Kernel Space Applications/Sockets,window=_blank]
* Using tcpdump or wireshark to capture packets on the wire
* Using nmap for OS identification or to set specific flags when scanning
......@@ -116,7 +115,7 @@ image::slide_background_fade.png[background, size=100%]
=== link:https://net.cybbh.io/public/networking/latest/12_programming/fg.html#_12_2_2_kernel_space_applications_and_sockets[Kernel Space Applications/Sockets,window=_blank]
=== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#522-kernel-space-applications-and-sockets[Kernel Space Applications/Sockets,window=_blank]
* Using Scapy to craft or modify a packet for transmission
* Using Python to craft or modify RAW Sockets for transmission
......@@ -127,7 +126,7 @@ image::slide_background_fade.png[background, size=100%]
== link:https://net.cybbh.io/public/networking/latest/12_programming/fg.html#_12_4_implement_network_programming_with_python3[Understanding Python Terminology,window=_blank]
== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#54-implement-network-programming-with-python3[Understanding Python Terminology,window=_blank]
* Libraries (https://docs.python.org/3/[Standard Python Library, window=_blank])
** https://docs.python.org/3/py-modindex.html[Modules, window=_blank] (_import_ _module_)
......@@ -141,7 +140,7 @@ image::slide_background_fade.png[background, size=100%]
=== String
=== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#541-understanding-python-libraries:~:text=integer%20w/%20variable.-,Text%20Type%3A,-strings%20%2D%20Textual%20data[String, window=_blank]
* my_string = "Hello World"
* https://docs.python.org/3/glossary.html#term-bytes-like-object[Bytes-like-object,window=_blank]
......@@ -151,7 +150,7 @@ image::slide_background_fade.png[background, size=100%]
=== Integer
=== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#541-understanding-python-libraries:~:text=or%20%22float%22%20etc.-,Numeric%20Type%3A,-integer%20(int)[Numeric, window=_blank]
* int = 1234
* float = 3.14
......@@ -185,7 +184,7 @@ image::slide_background_fade.png[background, size=100%]
=== link:https://net.cybbh.io/public/networking/latest/12_programming/fg.html#_12_4_2_how_imports_work[How Imports Work,window=_blank]
=== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#542-how-imports-work[How Imports Work,window=_blank]
* import {module}
* import {module} as {name}
......@@ -197,29 +196,30 @@ image::slide_background_fade.png[background, size=100%]
== link:https://net.cybbh.io/public/networking/latest/12_programming/fg.html#_12_4_4_understanding_socket_api_functions[Network Programming with Python3,window=_blank]
== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#543-using-python3-to-create-sockets[Using python3 to create sockets,window=_blank]
image::tcp-socket.png[height=500px]
* Network sockets primarily use the Python3 Socket library and *socket.socket* function.
----
import socket
s = socket.socket(socket.FAMILY, socket.TYPE, socket.PROTOCOL)
----
image::slide_background_fade.png[background, size=100%]
=== link:https://net.cybbh.io/public/networking/latest/12_programming/fg.html#_12_4_3_using_python3_to_create_sockets[Network Programming with Python3,window=_blank]
=== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#544-understanding-socket-api-functions[Network Programming with Python3,window=_blank]
* Network sockets primarily use the Python3 Socket library and *socket.socket* function.
----
import socket
s = socket.socket(socket.FAMILY, socket.TYPE, socket.PROTOCOL)
----
image::tcp-socket.png[height=500px]
image::slide_background_fade.png[background, size=100%]
=== link:https://net.cybbh.io/public/networking/latest/12_programming/fg.html#_12_4_4_1_socket_socket_socket[The socket.socket Function,window=_blank]
=== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#5441-socket-socketsocket[socket.socket(),window=_blank]
* Inside the socket.socket. function, you have these arguments, in order:
[source, python]
----
socket.socket( *family*, *type*, *proto* )
......@@ -233,6 +233,149 @@ image::slide_background_fade.png[background, size=100%]
=== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#5442-setsockopt-socketsetsockopt[socket.setsockopt(),window=_blank]
* Set server socket options:
[source, python]
----
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
----
image::slide_background_fade.png[background, size=100%]
=== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#5443-bind-socketbind[socket.bind(),window=_blank]
* Bind the Server Listening port to an address:
[source, python]
----
s.bind(('', 12345))
----
image::slide_background_fade.png[background, size=100%]
=== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#5444-listen-socketlisten[socket.listen(),window=_blank]
* Prepares server for incoming connections:
[source, python]
----
s.listen()
----
image::slide_background_fade.png[background, size=100%]
=== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#5445-accept-socketaccept[socket.accept(),window=_blank]
* Server will accept incoming TCP connections from Client:
[source, python]
----
s.accept()
----
image::slide_background_fade.png[background, size=100%]
=== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#5446-connect-socketconnect[socket.connect(),window=_blank]
* Client will establish TCP connection to Server:
[source, python]
----
s.connect()
----
image::slide_background_fade.png[background, size=100%]
=== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#5447-send-socketsend[socket.send(),window=_blank]
* Send data over established TCP socket:
[source, python]
----
s.send(b"Hello World")
----
image::slide_background_fade.png[background, size=100%]
=== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#5448-sendall-socketsendall[socket.sendall(),window=_blank]
* Repeats `send` until all data sent:
[source, python]
----
s.send(b"Hello World")
----
image::slide_background_fade.png[background, size=100%]
=== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#5449-sendto-socketsendto[socket.sendto(),window=_blank]
* Send data over UDP socket:
[source, python]
----
s.sendto(b"Hello World", (172.16.1.15, 1111))
----
image::slide_background_fade.png[background, size=100%]
=== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#54410-recv-socketrecv[socket.recv(),window=_blank]
* Receive data ONLY from remote socket:
[source, python]
----
data = s.recv(1024)
----
image::slide_background_fade.png[background, size=100%]
=== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#54411-recvfrom-socketrecvfrom[socket.recvfrom(),window=_blank]
* Receive data and remote address from remote socket:
[source, python]
----
data, addr = s.recvfrom(1024)
----
image::slide_background_fade.png[background, size=100%]
=== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#54412-recvfrom-socketclose[socket.close(),window=_blank]
* Close connection and free used resources:
[source, python]
----
s.close()
----
image::slide_background_fade.png[background, size=100%]
== Python3 Libraries and References
|===
......@@ -245,13 +388,13 @@ image::slide_background_fade.png[background, size=100%]
== link:https://net.cybbh.io/public/networking/latest/12_programming/fg.html#_12_5_demonstration_of_creating_stream_and_dgram_sockets[Stream and Dgram Socket Demos,window=_blank]
== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#55-demonstration-of-creating-stream-and-dgram-sockets[Stream and Dgram Socket Demos,window=_blank]
image::slide_background_fade.png[background, size=100%]
=== link:https://net.cybbh.io/public/networking/latest/12_programming/fg.html#_12_5_1_tcp_stream_client[Stream Socket Sender Demo,window=_blank]
=== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#551-tcp-stream-client[Stream Socket Sender Demo,window=_blank]
#!/usr/bin/python3
import socket
......@@ -269,7 +412,7 @@ image::slide_background_fade.png[background, size=100%]
=== link:https://net.cybbh.io/public/networking/latest/12_programming/fg.html#_12_5_2_tcp_stream_server_optional[Stream Socket Receiver Demo,window=_blank]
=== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#552-tcp-stream-server-optional[Stream Socket Receiver Demo,window=_blank]
----
#!/usr/bin/python3
......@@ -297,7 +440,7 @@ image::slide_background_fade.png[background, size=100%]
=== link:https://net.cybbh.io/public/networking/latest/12_programming/fg.html#_12_5_3_udp_dgram_client[Datagram Socket Sender Demo,window=_blank]
=== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#553-udp-dgram-client[Datagram Socket Sender Demo,window=_blank]
#!/usr/bin/python3
import socket
......@@ -308,12 +451,13 @@ image::slide_background_fade.png[background, size=100%]
s.sendto(message, (ip_addr, port))
data, addr = s.recvfrom(1024)
print(data.decode())
s.close()
image::slide_background_fade.png[background, size=100%]
=== link:https://net.cybbh.io/public/networking/latest/12_programming/fg.html#_12_5_4_udp_dgram_server_optional[Datagram Socket Receiver Demo,window=_blank]
=== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#554-udp-dgram-server-optional[Datagram Socket Receiver Demo,window=_blank]
----
#!/usr/bin/python3
......@@ -358,7 +502,7 @@ image::slide_background_fade.png[background, size=100%]
== link:https://net.cybbh.io/public/networking/latest/12_programming/fg.html#_12_6_encoding_and_decoding[Encoding and Decoding,window=_blank]
== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#56-encoding-and-decoding[Encoding and Decoding,window=_blank]
* Encoding
** The process of taking bits and converting them using a specified cipher.
......@@ -390,11 +534,11 @@ image::slide_background_fade.png[background, size=100%]
=== link:https://net.cybbh.io/public/networking/latest/12_programming/fg.html#_12_6_1_hex_encodingdecoding[Hex Encoding and Decoding,window=_blank]
=== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#561-hex-encodingdecoding[Hex Encoding and Decoding,window=_blank]
Encode text to Hex:
echo "Message" | xxd
echo "Message" | xxd -p
Encode file to Hex:
......@@ -414,12 +558,13 @@ image::slide_background_fade.png[background, size=100%]
message = b'Message'
hidden_msg = binascii.hexlify(message)
new_msg = binascii.unhexlify(hidden_msg)
image::slide_background_fade.png[background, size=100%]
=== link:https://net.cybbh.io/public/networking/latest/12_programming/fg.html#_12_6_2_base64_encodingdecoding[Base64 Encoding and Decoding,window=_blank]
=== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#562-base64-encodingdecoding[Base64 Encoding and Decoding,window=_blank]
Encode text to base64:
......@@ -443,17 +588,18 @@ image::slide_background_fade.png[background, size=100%]
message = b'Message'
hidden_msg = base64.b64encode(message)
new_msg = base64.b64decode(hidden_msg)
image::slide_background_fade.png[background, size=100%]
== link:https://net.cybbh.io/public/networking/latest/12_programming/fg.html#_12_7_demonstration_of_creating_raw_sockets[Raw IPV4 and TCP Socket Demos,window=_blank]
== link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/fg.html#57-demonstration-of-creating-raw-sockets[Raw IPV4 and TCP Socket Demos,window=_blank]
Follow along with the instructor on the Internet Host
* https://git.cybbh.space/net/public/-/raw/master/modules/networking/activities/resources/ipraw.py[ipraw.py shell,window=_blank]
* https://git.cybbh.space/net/public/-/raw/master/modules/networking/activities/resources/tcpraw.py[tcpraw.py shell,window=_blank]
* https://git.cybbh.space/cted/tech-college/cttsb/cctc/net/Net/-/raw/main/Resources/ipraw.py[ipraw.py shell,window=_blank]
* https://git.cybbh.space/cted/tech-college/cttsb/cctc/net/Net/-/raw/main/Resources/tcpraw.py[tcpraw.py shell,window=_blank]
image::slide_background_fade.png[background, size=100%]
......@@ -461,6 +607,8 @@ image::slide_background_fade.png[background, size=100%]
== PACKET CREATION AND SOCKET PROGRAMMING Complete
link:https://cted.cybbh.io/tech-college/cttsb/cctc/net/Net/Modules/05_Socket_Programming/col.html[Check on Learning, window=_blank]
Check intel on the CTF server for new information regarding mission tasks
image::slide_background_blk.png[background, size=100%]
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment