الكتاب 'فهم القرصنة وأمن المعلومات' يتناول أساسيات الحوسبة، البرمجة، الشبكات، وأمن المعلومات. يتضمن مواضيع مثل تحليل الأكواد، ثغرات النظام، وآليات التشفير. يتوجه الكتاب للمبتدئين ويساعدهم على تطوير مهاراتهم في مجال أمن المعلومات.
اإللكترونيالقرصنة
ة
وأ
المعلوماتمن
Understanding Hacking andInformation Security
Programming
[21]
ال داطل ما ٍمكان يف بتخزينها اجلهاز يقوم املتغريات ذذه
Memory
،
.بعد قيام بالتفصيل األماكن ذذه عن سنتكلم
ال أنواع بعض ماييل
variables
:
int (integer values)
float (decimal floating)
char (single character values)
ناُذ
ن
ق
و
م
تغريينُم َعريفتب
a
و
b
َوعيهامن تحديدب مناُقو
(
int
،)
سيكون كالذم أن أي
object
ُهنوع عدد بيستوعل
"
Integer
"
.حيح َ
ص ددَع ،عدَب ُهقرَعن ال
int a, b;
:بسيط مثال نأطذل
int a = 13, b;
float k;
char z = 'A';
k = 3.14;
z = 'w';
b = a + 5;
تغريُم بتعريف ناُذ مناُق
a
الرقم وذو !ًاسبقُم بداطله ما وحددنا
13
..
آطر تغريُم ددنا َح مُث
b
نوعه ،
"
صحيح عدد
"
نولك
هلداطب حويهَي َ
س ما ُحددن َمل
..
آطر تغريُم قنارَع مُث
k
نوعه
"
عرشي عدد
"
آطر متغري ثم ،
z
بد سيحوي
اطله
ذو واحد حرف
A
..
املتغري داطل وضعها نود التي القيمة حددنا وبعدذا
k
وذي
3.14
..
تغريُللم تغيري بإجراء مناُق مُث
z
احلرف وذو ،بداطله ما استبدلنا حيث جديد من
A
..
ذو ،آطر حرف منه ًالبد ووضعنا
w
..
أطربنا ًاأطري مُث
صديقنا
تغريُملا
b
قيم داطله ن ِّخزُي َ
س ُهأن
املتغري ة
a
وذي
13
عدد عليها ًازائد
5
..
22.
اإللكترونيالقرصنة
ة
وأ
المعلوماتمن
Understanding Hacking andInformation Security
Programming
[22]
قيمة ستكون وبالتايل
b
النهاية يف
18
.
ال بعض لتوضيح اآلن سننتقل
Operators
.همةُملا
Arithmetic Operators
Operation Symbol Example
Addition + b = a + 5
Subtraction - b = a - 5
Multiplication * b = a * 5
Division / b = a / 5
Modulo reduction % b = a % 5
ال توضيحب نقوم َ
س
"
Mod
"
تغريُم ضَفرنل ،ثالَمكو ،ةَسمالق عملية لجراء بعد تبقيةُملا القيمة وذو
a=13
وأردنا
عىل القسمة
5
الناتج قيكون
2
الرقم من ويتبقى
13
ذي ..قيمة ذذه سمةالق عملية بعد
(
3
.)
(13%5 = 3)
االطتصارات بعض أيضا نستخدم
(Shorthand Expressions)
ال دالة يف املستخدمة تلك مثل الدوال بعض يف
For
ًادوم
i++
.
Full Expression Shorthand Explanation
i = i + 1 i++ or ++i Add 1 to the variable
i = i - 1 i-- or --i Subtract 1 from the variable
ال مع القاتَعال ذهَذ استخدام متَي ماَندوع
Arithmetic Operators
قتخت
ل ًاتبع النواتج لف
ستخدمُملا االطتصار نوع
.
23.
اإللكترونيالقرصنة
ة
وأ
المعلوماتمن
Understanding Hacking andInformation Security
Programming
[23]
مثال
:
int a, b;
a = 5;
b = a++ * 6;
نم ًالك سيحوي ماذا
a
و
b
؟
:كالتايل الناتج سيكون ..نعم
b = 30
a = 6
ملاذا؟
ألن
a++
بإضاقة الربنامج ربُخن أننا تعني
1
املتغري قيمة لاىل
a
ولكن
"
بعد
"
العم لمتام
ل
احلسابية ية
!
.
:آطر ثالم لنستعرض
int a, b;
a = 5;
b = ++a * 6;
تغريُملا يمةق تزداد َ
س ُهأن عنيَي وذذا
a
"
قبل
"
:!الرضب مليةَع لجراء
a = a + 1;
b = a * 6;
قيمة تكون وبالتايل
b
النهاية يف
=
36
،
ويكون
(
a = 6
)
عيُم قيمة لضاقة اإلطتصار من كنوع ًاأيض ُنانمكُي.. ،رائع ذذا
بالناتج واإلحتفاظ اجلمع بإجراء قيقوم ،ما ٍتغريُمل نة
.األكواد يف ًاكثري استخدامها يتم ،!الوقت نفس يف بداطله النهائي
24.
اإللكترونيالقرصنة
ة
وأ
المعلوماتمن
Understanding Hacking andInformation Security
Programming
[24]
Full Expression Shorthand Explanation
i = i + 12 i+=12 Add some value to the variable.
i = i - 12 i-=12 Subtract some value from the variable.
i = i * 12 i*=12 Multiply some value by the variable.
i = i / 12 i/=12 Divide some value from the variable.
Comparison Operators
Condition Symbol Example
Less than < (a < b)
Greater than > (a > b)
Less than or
equal to <= (a <= b)
Greater than or
equal to >= (a >= b)
Equal to == (a == b)
Not equal to != (a != b)
ناولَق عند
(a = 5)
،املثال سبيل عىل
..َعنين َُحننَق
ع َ
ض
قيمة
5
ُملا داطل
تغري
a
..
نكتب عندما بينام
(a = = 5)
قنحن ،
تغريُملا لهام َ
حي التي القيمة من قُقََحتال الربنامج من نطلب
a
كانت لذا ما
5
.ال أم
ذناك
symbol
استخدامه مكنُي آطر
ال قبل فردهُمب
condition
ال وذو
)!(
ويعني
"
Not
"
:كامييل
!(a < b) is equivalent to (a >= b)
ال مزي َرب مهتامخب ونقوم
AND
وال
OR
:
Logic Symbol Example
OR || ((a < b) || (a < c))
AND && ((a < b) && !(a < c))
اإللكترونيالقرصنة
ة
وأ
المعلوماتمن
Understanding Hacking andInformation Security
Programming
[40]
Signed and Unsigned
ال عن نتحدث عندما
numerical values
ال يف ختزينها يتم التي األعداد نعني قنحن
memory
الثنائي بالنظام
،
تكون أن لما وذي
Signed
(موجب أي
ة
أو ،)سالبة أو
Unsigned
(موجب أي
ة
.)ققط
:كالتايل تغريُملا ذذا بتعريف نقوم
“unsigned int”
ساحبامل ُّمكََحتال مكنناُي ًاأيض ،
ة
َ
صصَخُملا
ة
ال ذاهل
Numerical variable
بالزياد ًءسوا
ة
ُقصاننبال أو
بإضاقة وذلك
short or long
.بلهَق
توجد
function
ال لغة يف
C
تسمى
sizeof( )
..
أي مساحة حتديد وظيفتها
data type
.نريده
ال ذذه ب ُِّجرنل
function
همُملا تغرياتُملا بعض مساحة عىل فنتعر كي
ة
:
#include <stdio.h>
int main() {
printf("The 'int' data type istt %d bytesn",
sizeof(int));
printf("The 'unsigned int' data type ist %d bytesn",
sizeof(unsigned int));
printf("The 'short int' data type ist %d bytesn",
sizeof(short int));
printf("The 'long int' data type ist %d bytesn",
sizeof(long int));
printf("The 'long long int' data type is %d bytesn",
sizeof(long long int));
printf("The 'float' data type ist %d bytesn",
sizeof(float));
printf("The 'char' data type istt %d bytesn",
sizeof(char));
}
استخدمنا أننا معي الحظ
printf( )
الشاش عىل ما يشء بطباعة لتقوم
ة
:
41.
اإللكترونيالقرصنة
ة
وأ
المعلوماتمن
Understanding Hacking andInformation Security
Programming
[41]
بال يسمى ما استخدمنا لقد
format specifier
وذي
%d
:ييل كام العرض بعملية لتقوم
ال مساحة بعرض الكود ذذا سيقوم
data types
ال
موضح ذو كام له بإدطاهلا قمنا تي
.
reader@hacking:~/booksrc $ gcc datatype_sizes.c
reader@hacking:~/booksrc $ ./a.out
The 'int' data type is 4 bytes
The 'unsigned int' data type is 4 bytes
The 'short int' data type is 2 bytes
The 'long int' data type is 4 bytes
The 'long long int' data type is 8 bytes
The 'float' data type is 4 bytes
The 'char' data type is 1 bytes
reader@hacking:~/booksrc $
Pointers
ال أن ركََذت
(
EIP register
)
نَع بارةع َيذ
pointer
ال لىل شريُي
current instruction
وذلك الربنامج لَمَع أثناء
ال عىل الحتوائها
memory address
ال هذَِب اخلاص
instruction
.
ال َعَم لُمَعاتال أثناء
memory
التي للبيانات ّسخنال لياتَمَعل باستمرار َحتاجن
ال بواسطة استخدامها متَي
functions
،
ال داطل البيانات نسخ تكرار ةَمكاحل َنم قليس وبالتايل
memory
لكل
function
حجز يتطلب ألنه ،نستدعيها
ال مساحة
destination
ال نسخ سيتم (التي
data
ال يف )لليها
memory
األمر كونَي َ
س .!ّسخنال ليةَمَعب البدء قبل
لل ًاكهلُم
memory
.!هلا ًاومستهلك
ال استخدام مكنناُي ذلك من ًالبد
pointer
ّر ُح ُلكب به لنتحرك
ي
ة
داطل
ال
memory
اإلشار طريق عن
ة
لىل
ال عناوين
blocks
.
We use pointers to point to the address of the beginning of that block of memory.
Pointers are 32 bits in size (4 bytes), and is defining by putting (*) to the variable name.
42.
اإللكترونيالقرصنة
ة
وأ
المعلوماتمن
Understanding Hacking andInformation Security
Programming
[42]
:مثال نأطذ دعنا
#include <stdio.h>
#include <string.h>
int main() {
char str_a[20]; // A 20-element character array
char *pointer; // A pointer, meant for a character array
char *pointer2; // another one
strcpy(str_a, "Hello, world!n");
pointer = str_a; // Set the first pointer to the start of the array.
printf(pointer);
pointer2 = pointer + 2; // Set the second one 2 bytes further in.
printf(pointer2); // Print it.
strcpy(pointer2, "y you guys!n"); // Copy into that spot.
printf(pointer); // Print again.
}
ماييل
:الكود ذذا نتائج
reader@hacking:~/booksrc $ gcc -o pointer pointer.c
reader@hacking:~/booksrc $ ./pointer
Hello, world!
llo, world!
Hey you guys!
reader@hacking:~/booksrc $
اإللكترونيالقرصنة
ة
وأ
المعلوماتمن
Understanding Hacking andInformation Security
Programming
[54]
:الكود نتائج
reader@hacking:~/booksrc $ gcc pointer_types.c
reader@hacking:~/booksrc $ ./a.out
[integer pointer] points to 0xbffff7f0, which contains the integer 1
[integer pointer] points to 0xbffff7f4, which contains the integer 2
[integer pointer] points to 0xbffff7f8, which contains the integer 3
[integer pointer] points to 0xbffff7fc, which contains the integer 4
[integer pointer] points to 0xbffff800, which contains the integer 5
[char pointer] points to 0xbffff810, which contains the char 'a'
[char pointer] points to 0xbffff811, which contains the char 'b'
[char pointer] points to 0xbffff812, which contains the char 'c'
[char pointer] points to 0xbffff813, which contains the char 'd'
[char pointer] points to 0xbffff814, which contains the char 'e'
reader@hacking:~/booksrc $
ال أن الحظ
integer pointer
بمقدار يزداد
"
4 bytes
"
.
العدد من انتقلنا ًالقمث
8
احلرف اىل
C
عىل باملرور وذلك
األرقام
:
9, A, B, C
،
ال بنظام نتعامل ألننا وذذا
Hexadecimal
ذو تاحُم حرف آطر حيث
f
،
لىل يعود وبعدذا
احلا كام ،الصفر
من االنتقال يف ل
0xbffff7fc
لىل
0xbffff800
.
ال يزداد قابلُملا ويف
character pointer
بمقدار
"
1 byte
"
.يظهر كام
السابق املثال يف َدرُماو لك صُِّلخت األسطر ذذه
:
A char is 1 byte, an int is (typically) 4 bytes. When you increment a pointer, you increment by
the size of the data being pointed to. So, when you increment a char*, you increment by 1 byte,
and when you increment an int*, you increment 4 bytes.
اإللكترونيالقرصنة
ة
وأ
المعلوماتمن
Understanding Hacking andInformation Security
Programming
[69]
:الشكل ذاهل انتبه
أن نُظأ
نا
َن
:ًالقمث ..كذلك؟ َ
أليس ..ًايد َج ُهمَفه
(i = 3)
،
بينام
(&i = 65524)
.
لنأطذ
املتغري ذذا عىل مثال
i
:
int main()
{
int *ptr, i;
i = 3;
/* address of i is assigned to ptr */
ptr = &i;
/* show i's value using ptr variable */
printf("Value of i : %d", *ptr);
return 0;
}
ّ
تغريُم َعريفتب مناُق
i
و ،
pointer
ُهاسم
ptr
ال ذذا جعلنا مُث ،
pointer
ال لىل شريُي
"
address-of i
"
.
طباعة أردنا ثم
ال ذذا حمتويات
"
block of memory
"
ال لليه شريُي الذي
pointer
،
( الرقم وذو
3
سنضع ناُذ ،)
)*(
ال قبل
pointer
ال لداط نستدعيه عندما
printf( )
،
العملية ذذه ُسمىتو
“Dereferencing of Pointer”
:كاتايل النهاية يف املخرجات وتكون
value of i : 3
70.
اإللكترونيالقرصنة
ة
وأ
المعلوماتمن
Understanding Hacking andInformation Security
Programming
[70]
:اآليت يف األمر تلخيص نستطيع
(&) symbol is used to get address of variable
(*) symbol is used to get value from the address given by pointer.
(*) Symbol when used with Pointer variable it refers to variable being pointed to, this is
called as “Dereferencing of Pointers”.
ييل ما
توضيحي شكل
أطري
:
عر ناُذ
قنا
)
ُهلسم تغريُم
(num
و
pointer)
ُهلسم
(ptr
،تغريُملا ذذا لىل شريُيل
ال بني التشابه نقاط يوضح اجلدول وذذا
ptr
ال و
&num
املتغري قيمة اآلطر الوجه عىل و
num
وال
“Dereferencing of Pointer ptr”
الرمز يف لِّثََمتُملا
*ptr
.!املعنى نفس حيمل كالذم حيث
Variable Value in it
num 50
&num 1002
ptr 1002
*ptr 50
اإللكترونيالقرصنة
ة
وأ
المعلوماتمن
Understanding Hacking andInformation Security
Programming
[72]
Scenario Behavior
When We assign address of integer variable to void
pointer
Void Pointer Becomes Integer Pointer
When We assign address of character variable to void
pointer
Void Pointer Becomes Character
Pointer
When We assign address of floating variable to void
pointer
Void Pointer Becomes Floating
Pointer
عن أتكلم أن أود ًاوأطري
Function
تسمى
atoi( )
ال من للتحويل مَُستخدت
(
data type
character
)
ال اىل
(
integer data type
)
..
قمنا كيف يوضح مثال ييل قيام
أرقام جمموعة بوضع
(integers)
ُمتلف نوع من متغري يف
character)
)
:الشاشة عىل وعرضها
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int val;
char str[20];
strcpy(str, "98993489");
val = atoi(str);
printf("String value = %s, Int value = %dn", str, val);
return(0);
}
73.
اإللكترونيالقرصنة
ة
وأ
المعلوماتمن
Understanding Hacking andInformation Security
Programming
[73]
:كالتايل جالنتائ تكون
String value = 98993489, Int value = 98993489
ال ثالم تسبق التي قدمةُملا من انتهينا ..ًاحسن
Heap Segment
.
Heap Example:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]) {
char *char_ptr; // A char pointer
int *int_ptr; // An integer pointer
int mem_size;
if (argc < 2) // If there aren't command-line arguments,
mem_size = 50; // use 50 as the default value.
else
mem_size = atoi(argv[1]);
printf("t[+] allocating %d bytes of memory on the heap for
char_ptrn", mem_size);
char_ptr = (char *) malloc(mem_size); // Allocating heap memory
if(char_ptr == NULL) { // Error checking, in case malloc( ) fails
fprintf(stderr, "Error: could not allocate heap memory.n");
exit(-1);
}
strcpy(char_ptr, "This is memory is located on the heap.");
printf("char_ptr (%p) --> '%s'n", char_ptr, char_ptr);
printf("t[+] allocating 12 bytes of memory on the heap for
74.
اإللكترونيالقرصنة
ة
وأ
المعلوماتمن
Understanding Hacking andInformation Security
Programming
[74]
int_ptrn");
int_ptr = (int *) malloc(12); // Allocated heap memory again
if(int_ptr == NULL) { // Error checking, in case malloc( ) fails
fprintf(stderr, "Error: could not allocate heap memory.n");
exit(-1);
}
*int_ptr = 31337; // Put the value of 31337 where int_ptr is pointing.
printf("int_ptr (%p) --> %dn", int_ptr, *int_ptr);
printf("t[-] freeing char_ptr's heap memory...n");
free(char_ptr); // Freeing heap memory
printf("t[+] allocating another 15 bytes for char_ptrn");
char_ptr = (char *) malloc(15); // Allocating more heap memory
if(char_ptr == NULL) { // Error checking, in case malloc( ) fails
fprintf(stderr, "Error: could not allocate heap memory.n");
exit(-1);
}
strcpy(char_ptr, "new memory");
printf("char_ptr (%p) --> '%s'n", char_ptr, char_ptr);
printf("t[-] freeing int_ptr's heap memory...n");
free(int_ptr); // Freeing heap memory
printf("t[-] freeing char_ptr's heap memory...n");
free(char_ptr); // Freeing the other block of heap memory
}
ال باستخدام مناُق البداية يف
cmd-line arguments
..
ال أن ركََذت
arg[0]
،نفسه الربنامج اسم ذو
مُث
arg[1]
أول ذي
string
.الربنامج لسم بعد ..َحنن تابتهاكب نقوم
اإللكترونيالقرصنة
ة
وأ
المعلوماتمن
Understanding Hacking andInformation Security
Programming
[84]
:النتائج ُشاذدنل
reader@hacking:~/booksrc $ gcc -o simplenote simplenote.c
reader@hacking:~/booksrc $ ./simplenote
Usage: ./simplenote <data to add to /tmp/notes>
reader@hacking:~/booksrc $ ./simplenote "this is a test note"
[DEBUG] buffer @ 0x804a008: 'this is a test note'
[DEBUG] datafile @ 0x804a070: '/tmp/notes'
[DEBUG] file descriptor is 3
Note has been saved.
reader@hacking:~/booksrc $ cat /tmp/notes
this is a test note
reader@hacking:~/booksrc $ ./simplenote "great, it works"
[DEBUG] buffer @ 0x804a008: 'great, it works'
[DEBUG] datafile @ 0x804a070: '/tmp/notes'
[DEBUG] file descriptor is 3
Note has been saved.
reader@hacking:~/booksrc $ cat /tmp/notes
this is a test note
great, it works
reader@hacking:~/booksrc $
reader@hacking:~/booksrc $
85.
اإللكترونيالقرصنة
ة
وأ
المعلوماتمن
Understanding Hacking andInformation Security
Programming
[85]
File Permissions
ال َ
َربتعُي
file permissions
األ َنم
التشغيل أنظمة يف ةّمهُملا مور
ال َنم ةَموع َ
جم صيص َ
خت َمت .
flags
جمهاَد ُنانمكُي التي
وابةَب باستخدام ًاعَم
"
OR
."
ال ذذه
flags
َث لىل ةَمقسُم
أنو ةَثالَثل الحيات َ
ص ُعطيتل موعات َ
جم الث
:ييل كام ،منيَخدتسُملا َنم اع
User (Owner)
S_IRUSR Give the file read permission for the user (owner).
S_IWUSR Give the file write permission for the user (owner).
S_IXUSR Give the file execute permission for the user (owner).
Group
S_IRGRP Give the file read permission for the group.
S_IWGRP Give the file write permission for the group.
S_IXGRP Give the file execute permission for the group.
Others
S_IROTH Give the file read permission for other (anyone).
S_IWOTH Give the file write permission for other (anyone).
S_IXOTH Give the file execute permission for other (anyone).
التشغيل ظامن يف لفَم ُلكل
Linux
منيستخدُملا َنم أنواع ثالثةل ىَطُعت التي الصالحيات َنم موعة َ
جم
:
Owner, Group, and Others
:ثالمب ذذا دُشاذنل
reader@hacking:~/booksrc $ ls -l /etc/passwd simplenote*
-rw-/r--/r-- 1 root root 1424 2015-09-06 09:45 /etc/passwd
-rwx/r-x/r-x 1 reader reader 8457 2015-09-07 02:51 simplenote
-rw-/---/--- 1 reader reader 1872 2015-09-07 02:51 simplenote.c
reader@hacking:~/booksrc $
86.
اإللكترونيالقرصنة
ة
وأ
المعلوماتمن
Understanding Hacking andInformation Security
Programming
[86]
لفَم أول أن ظُالحن
/etc/passwd
الحيات َ
ص لعطاء َمت
"
read and write
"
ال لىل
owner
،
و
read
ال لىل ققط
group
،
و
read
ال لىل ًاأيض
others
.
بتحديد مناُق لذا
group
لضاقة ُنانمكُيق ،
users
ذذا لىل
group
ذذا الحيات َ
ص كونمتلَي َ
س ،لليه لضاقتهم جردُموب ،
group
َكان قإذا ،!
group
لل
Admins
ال صالحيات َحنُمت َ
سَق
Admin
ذاَهل نتميَي نَم ميعجل
group
.
َذ
:أكثر الصورة حتتض َيك اتّيالصالح َعديلت يهق متَي ر َ
آط ثالم دُشاذن اّي
reader@hacking:~/booksrc $ chmod 731 simplenote.c
reader@hacking:~/booksrc $ ls -l simplenote.c
-rwx/-wx/--x 1 reader reader 1826 2007-09-07 02:51 simplenote.c
reader@hacking:~/booksrc $ chmod ugo-wx simplenote.c
reader@hacking:~/booksrc $ ls -l simplenote.c
-r--/---/--- 1 reader reader 1826 2007-09-07 02:51 simplenote.c
reader@hacking:~/booksrc $ chmod u+w simplenote.c
reader@hacking:~/booksrc $ ls -l simplenote.c
-rw-/---/--- 1 reader reader 1826 2007-09-07 02:51 simplenote.c
reader@hacking:~/booksrc $
لفَللم َصاريحت عطيُي َ
س ُهأن األول السطر يف ظالح
simplenote
األمر باستخدام
chmod
:كالتايل
7 for the owner, 3 for Group, and 1 for Others
تعني ماذا
7
ذذه؟؟
ًان َ
س َح
ةَلَدعاُملا ذذه لتأم ..
:
( 4 + 2 + 1 ) = 7
Since 4 is read flag, and 2 is write flag, and 1 is the execute flag!, then the sum is 7
اإلالقرصنة
لكتروني
ة
المعلوماتوأمن
Understanding Hacking andInformation Security
Networking
[122]
connect(int fd, struct sockaddr *remote_host, socklen_t addr_length)
Connects a socket (described by file descriptor fd) to a remote host. Returns 0 on success and -1
on error.
bind(int fd, struct sockaddr *local_addr, socklen_t addr_length)
Binds a socket to a local address so it can listen for incoming connections. Returns 0 on success
and -1 on error.
listen(int fd, int backlog_queue_size)
Listens for incoming connections and queues connection requests up to backlog_queue_size.
Returns 0 on success and -1 on error.
accept(int fd, sockaddr *remote_host, socklen_t *addr_length)
Accepts an incoming connection on a bound socket. The address information from the remote
host is written into the remote_host structure, and the actual size of the address structure is
written into *addr_length.
This function returns a new socket file descriptor to identify the connected
socket or -1 on error.
send(int fd, void *buffer, size_t n, int flags)
Sends n bytes from *buffer to socket fd; returns the number of bytes sent or -1 on error.
recv(int fd, void *buffer, size_t n, int flags)
Receives n bytes from socket fd into *buffer; returns the number of bytes received or -1 on error.
ال لنشاء عند أنه الحظ
Socket
،
سن
ب قوم
تحديد
األ ذذه
مور
:
Domain
ال نوع وذو
Protocol Family
مع ستتعامل كنت اذا ما حتديد يمكنك ًالقمث
IPv4
أم
IPv6
.!غريذم أم
123.
اإلالقرصنة
لكتروني
ة
المعلوماتوأمن
Understanding Hacking andInformation Security
Networking
[123]
Type
ال اِب َعنينو
Socket Type
كان لذا ما
TCP or UDP
.
Protocol
كهاُرتَن َ
س
0
عنىَمب..
unspecified
ال نوع نادَد َح ألننا
protocol
ال يف
Argument
األوىل
ًاقَبسُم
.
ال هذَذ
protocol families
لَمَع َمت
define
:سارَملا ذاَذ َربَع اَهل
/bits/socket.h
ال ذذه تويات ُ
حم ذ ُ
نأط َ
س
library
..أجزاء ةدع عىل
بال اخلاص وذو ،جزء بأول لنبدأ
protocol families
:
/* Protocol families. */
#define PF_UNSPEC 0 /* Unspecified. */
#define PF_LOCAL 1 /* Local to host (pipes and file-domain). */
#define PF_UNIX PF_LOCAL /* Old BSD name for PF_LOCAL. */
#define PF_FILE PF_LOCAL /* Another nonstandard name for PF_LOCAL. */
#define PF_INET 2 /* IP protocol family. */
#define PF_AX25 3 /* Amateur Radio AX.25. */
#define PF_IPX 4 /* Novell Internet Protocol. */
#define PF_APPLETALK 5 /* Appletalk DDP. */
#define PF_NETROM 6 /* Amateur radio NetROM. */
#define PF_BRIDGE 7 /* Multiprotocol bridge. */
#define PF_ATMPVC 8 /* ATM PVCs. */
#define PF_X25 9 /* Reserved for X.25 project. */
#define PF_INET6 10 /* IP version 6. */
...
اإلالقرصنة
لكتروني
ة
المعلوماتوأمن
Understanding Hacking andInformation Security
Networking
[128]
ال
"
Extra padding
"
؟؟
.
ال باقي لةَكمتل وذذا ،حاجة دون لضاقتهم َمت دَقَل
16 bytes
..
مَلَعت َامك ُهألن
..
ة َحاجب َُحنن
!قحسب ملاييل
:
- 2 bytes for “family type”
“port number”
- and 2 bytes for
“IP Address” field
for
(
- and (8 bits * 4 = 32 bits = 4 bytes
املج قيكون
موع
8 bytes
بإضاقة الباقي بإكامل مناُقَق ،!ققط
Padding
.
Big-Endian Byte Ordering
ال أن ظ َالحُملا من
IP Address
وال
Port Number
ال يف مانَستخدُملا
“AF_INET Socket address structure”
ال عانَبتَي َ
س
"
Network Byte Ordering
"
من ًالبد
ال
”x-86 little-Endian byte ordering”
ال ماذذا
Endian
؟..
Endianness refers to the order of the Bytes; It also describes the order of byte transmission over a
digital link.
Big-endian is the most common format in data networking; fields in the protocols such as IPv4,
IPv6, TCP, and UDP, are transmitted in big-endian order.
إلرسال ة َحاجب ناُذ َُحنن
"
Bits over the link
.."
اإلالقرصنة
لكتروني
ة
المعلوماتوأمن
Understanding Hacking andInformation Security
Networking
[130]
htonl(long value) Host-to-Network Long
This function converts 32-bit (4-byte) quantities from host byte order to network byte order. htonl means
host to network long!
htons(short value) Host-to-Network Short
This function converts 16-bit (2-byte) quantities from host byte order to network byte order.
ntohl(long value) Network-to-Host Long
This function converts 32-bit quantities from network byte order to host byte order.
ntohs(long value) Network-to-Host Short
This function converts 16-bit (2-byte) quantities from network byte order to host byte order.
Conversion between IPv4 and 32-bit int
الصيغة ذذه ُبتنك عندما
54.208.202.125
عليها طلقُي والتي ًالمث
"
the internet standard dot notation
"
قلن
ال يفهمها
Socket
،!
ال أن حيث
functions
نِّكوُملا
ة
بال لَمتتعا ُهل
"
32-bits order
"
د َُواجتل احلاجة ظهرت ناُذ ومن
functions
ال من بالتحويل تقوم
ASCII
ال لىل
"
32-bits integer
"
.!والعكس
ال ذذه عىل نظرة نلق دعنا
functions
.
#
ال
function
:األوىل
inet_aton(char *ascii_addr, struct in_addr *network_addr)
This function converts the specified string in the Internet standard dot notation “*ascii_addr”
to a network address “*network_addr”, and stores the address in the structure provided
“struct in_addr”.
The converted address will be in Network Byte Order (bytes ordered from left to right).
131.
اإلالقرصنة
لكتروني
ة
المعلوماتوأمن
Understanding Hacking andInformation Security
Networking
[131]
َت ذل
ّذ
ُك
ال ذذا ر
struct in_addr
؟
لنه ،!هب ّرككَذُأ دعني
Struct
ال حيمل
IP Address
ال بصيغة
32-bits int
َمت
تعريفه
ال لداط
"
Socket address structure
"
بالعائلة اخلاص
AF_INET
،
ال وذي
.Address Family for IPv4
عمل تم
Define
لل
Structure
نهَع ِّ
ربَعُي الذي
امللف يف ا
in.h
.
عىل ُهد َ
جت
ظامن يف التايل سارَملا
Linux
:
uer/include/netinet/in.h
بال بمقارنته مناُق ندماع ًاسبقُم ُهاستخدمنا وقد
General Structure
..
عادلةُم ماييل
توضح
ا من التحويل عملية
ل
"
IP Address in Dotted notation
"
لىل
ال
integer
.
أن ضَفرنل
ال
Address
:ييل كام
The address is aaa.bbb.ccc.ddd
:كالتايل التحويل معادلة قتكون
number = (aaa*256^3) + (bbb*256^2) + (ccc*256^1) + (ddd*256^0)
رقم أكرب
سيكون
4294967295
لل لقابُملا الرقم ألنه
(
Address: 255.255.255.255
)
،
سيكون رقم وأصغر
(0)
الرقم ألنه
لل لقابُملا
(
Address: 0.0.0.0
)
،
ال ذذا أن ظالح
integer
يكون أن دُبال
unsigned
،
ضَ َ
فرتُي ال ُهألن
وجود
IP
.!بسال مَقَر لم َ
حي
#
ال
function
الثانية
:
و
ال نم لُِّحوتس التي
Network
ال لىل
ASCII
:النحو ذذا عىل ستكون
inet_ntoa(struct in_addr *network_addr)
“This function converts the specified Internet host address to a string in the Internet standard dot
notation”.
اإلالقرصنة
لكتروني
ة
المعلوماتوأمن
Understanding Hacking andInformation Security
Networking
[137]
Some Definitions
ُذ
ن
أ أن ُ
بحُأ ُقطتنين َاك
عنهم حتدث
قب
،ه َقرَفال هذَذ نم اإلنتهاء َ
ل
ال مُوذ
Function Prototype
ال و
Define
#
Function prototype
ال تعريف ذذا
"
function prototype
:"
a function prototype or function interface is a declaration of a function that specifies the
function's name and type signature (parameter types, and return type), but omits the function
body. While a function definition specifies how the function does what it does (the
"implementation"), a function prototype specifies its interface.
استخدمنا لقد
:بمثال يعنيه ما لك سأوضح ،األكواد بعض يف ًاسبقُم ه
Consider the following function prototypes:
int myfunction(int n);
This prototype specifies that in this program, there is a function named "myfunction" which
takes a single integer argument "n" and returns an integer.
ال ذذه كتابة سيتم الربنامج داطل ما ٍمكان ويف
function
.!الفعلية
#Define
ال ذذا
Directive
احلقيق يف ذو ،القادمة األكواد يف مهَستخدن َ
س ًاأيض ،عليه طلقونُي كام
ة
ال شبهُي
variable
ليس ُهلكن
با قيمته يف يتحكم أن للربنامج مكنُي تغريُملقا ،!كذلك
َ
َربتعُي اآلطر بينام ،ستمرار
"
constant name
،"
قال
#define
ال ذاَذ استخدام نم ُكنِّكَمُي ذذا
const value
الكود داطل مكان أي يف
دِّدَُحن ماَندع ًالثَمَق ،
port
لَقبتَسنل ينهَعب
138.
اإلالقرصنة
لكتروني
ة
المعلوماتوأمن
Understanding Hacking andInformation Security
Networking
[138]
لَمَعب نقوم َ
سَق ،ليهَع اإلتصال
define
ال ذاَهل
port
بأ جَمالربنا دايةب يف
:باآليت ُهُخربن ن
"
لفظة وجدت ما متى
port
مُق
هقم َرب اباستبداهل
"
،
ًالمث وذو
3544
:ييل كام
#define port 3544
حَبصَأ لقد
نا
زجاذ اآلن
ين
ال
القادمة الفقرة ستقبال
..
سنقوم
بطرح
ال باستخدام عميل مثال
"
Socket functions
."
Server Example
سنقو املثال ذذا يف
ل كود بكتابة م
Server
ال بانتظار يقوم
session
ال من
client
:ييل امل ًاققو
The server listens for TCP connections on port 6900, and when a client connects,
it (the server) sends a message “Hello, Server”.
قبالباست بدأَي مُث
Data
ال ذاَذ نم
client
لىل
ال لقَغ متَي أن
connection
.
:التفاصيل لنشاذد ذيا
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "error.h"
139.
اإلالقرصنة
لكتروني
ة
المعلوماتوأمن
Understanding Hacking andInformation Security
Networking
[139]
#define PORT 6900 // The port users will be connecting to
int main(void) {
int sockfd, new_sockfd; // Listen on sock_fd, new connection on new_fd
struct sockaddr_in host_addr, client_addr; // My address information
socklen_t sin_size;
int recv_length=1, yes=1;
char buffer[1024];
if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1)
fatal("in socket");
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes,
sizeof(int)) == -1)
fatal("setting socket option SO_REUSEADDR");
host_addr.sin_family = AF_INET; // Host byte order
host_addr.sin_port = htons(PORT); // Short, network byte order
host_addr.sin_addr.s_addr = 0; // Automatically fill with my IP.
memset(&(host_addr.sin_zero), '0', 8); // Zero the rest of the struct.
if (bind(sockfd, (struct sockaddr *)&host_addr, sizeof(struct
sockaddr)) == -1)
fatal("binding to socket");
if (listen(sockfd, 5) == -1)
fatal("listening on socket");
while(1) { // Accept loop.
sin_size = sizeof(struct sockaddr_in);
new_sockfd = accept(sockfd, (struct sockaddr *)&client_addr,
&sin_size);
if(new_sockfd == -1)
fatal("accepting connection");
اإلالقرصنة
لكتروني
ة
المعلوماتوأمن
Understanding Hacking andInformation Security
Networking
[159]
ُلك ..ترى كام
Field
ل شريُي
منها ًابعض لك سنوضح ،ما ٍيشء ىل
:
Version: These 4 bits specify the IP protocol version of the datagram, here it is IPv4.
Total Length: This is the total length of the IP datagram (header plus data),
measured in bytes.
Identifier, flags, fragmentation offset: These three fields have to do with so-called
IP fragmentation "
قليل بعد اخلاصية ذذه عن سنتكلم
"
Time-to-live: to ensure that datagrams do not circulate forever, this field is decremented by one
each time the datagram is processed
by a router. If the TTL field reaches 0, the datagram must be dropped.
Protocol: indicates the specific transport-layer protocol, For example, a
value of 6 indicates that the data portion is passed to TCP, while a value of 17
indicates that the data is passed to UDP.
اإلالقرصنة
لكتروني
ة
المعلوماتوأمن
Understanding Hacking andInformation Security
Networking
[161]
ال يوضح بسيط مثال وذذا
msg type 3
ICMP
:
IP Fragmentation
ال
MTU
ال ذي
"
Maximum Transmission Unit
"
لل حجم أكرب تعني ُ
حيث
Packet
بني باإلنتقال هلا املسموح
ال
Hosts
.
The maximum transmission unit (MTU) is the size of the largest network layer protocol data
unit that can be communicated in a single network transaction.
اإلالقرصنة
لكتروني
ة
المعلوماتوأمن
Understanding Hacking andInformation Security
Networking
[166]
ال بعض بتوضيح سنقوم
Fields
ال ذذا يف املهمة
Header
:
اطرت
لك ت
ال هلذه تعريفات أقضل
Fields
،نظري وجهة من
ُنمكُي
نا
تسميته
ا
ًاأيض
بال
Mechanisms
التي
ال هاُميستخد
TCP
ال عملية لتنفيذ
Reliable Connection
.
Checksum: Used to detect bit errors in a transmitted packet.
Timer: Used to timeout/retransmit a packet, possibly because
the packet (or its ACK) was lost within the channel.
Because timeouts can occur when a packet is delayed but not lost,
or when a packet has been received by the receiver but the receiver-to-sender ACK has been lost,
also when a duplicate copies of a packet may be received by a receiver.
Sequence number: Used for sequential numbering of packets of data flowing from sender to
receiver.
Gaps in the sequence numbers of received packets allow the receiver to detect a
lost packet. Packets with duplicate sequence numbers allow the receiver to detect
duplicate copies of a packet.
Acknowledgment: Used by the receiver to tell the sender that a packet or set of packets has been
received correctly.
Acknowledgments will typically carry the sequence number of the packet or packets being
acknowledged.
Negative acknowledgment: Used by the receiver to tell the sender that a packet has not been
received correctly. Negative acknowledgments will typically carry the sequence number of the
packet that was not received correctly.
167.
اإلالقرصنة
لكتروني
ة
المعلوماتوأمن
Understanding Hacking andInformation Security
Networking
[167]
Window: The sender may be restricted to sending only packets with sequence numbers that fall
within a given range.
By allowing multiple packets to be transmitted but not yet acknowledged, sender utilization can
be increased over a stop-and-wait mode of operation.
Definitions from: Ref (2)
ال ذذه عىل تعرقنا أن وبعد واآلن
Mechanisms
ال عىل لنتعرف ذيا
Field
بال اخلاص
Flags
:ربُق عن
ال طبقة تقوم
Transport
لل ِسيع تصنيف بعملية
Segments
ال ذذه عىل بالتدقيق
Fields
:وذي
ال
Sequence number
ال و
Ack number
ال نوع ًاأطري و
TCP Flag
ال ذذه حتمله الذي
Segment
أن الحظ .
ال من ًالك
Sequence
ال و
Ack
عن عبارة
32 bits
.
ال ذذه قائدة وما
“Sequence”
وال
“ACK”
؟..
“The sequence number and acknowledgment number are used to maintain state”
س
:األمور تسري كيف لنفهم مثال نأطذ
اإلالقرصنة
لكتروني
ة
المعلوماتوأمن
Understanding Hacking andInformation Security
Security & Attacks
[181]
ال ذذه ِبا ُّرُ َمت التي احلاالت ًامع ُشاذدنس
Process
:
Ready: The process is ready to resume or begin processing as soon as it is scheduled for
execution. If the CPU is available when the process reaches this state, it will transition directly
into the running state.
Waiting: “waiting for a resource”, the process is ready for continued execution but is waiting for
a device or access request.
Running: the process here executes on the CPU and keeps going until it finishes, or it blocks for
some reason.
Stopped When a process finishes or must be terminated (because an error occurs, a required
resource is not available, or a resource request can’t be met), it goes into a stopped state.
اإلالقرصنة
لكتروني
ة
المعلوماتوأمن
Understanding Hacking andInformation Security
Security & Attacks
[188]
السيد استخدم لذا بالطبع
“Leech”
ال بروتوكول ناُذ
FTPS
ال من ًالبد
FTP
لن
تظهر
ال
Session
ال ألن
FTPS
ال مَخدتسَي
SSL
ال عملية تشفري يف
Login
.
ال استخدام نم ًالَدَب لثوبامل
Telnet
ال استخدام فضلُي
SSH
َحقيقتل
.ناآلم اإلتصال
ال من ًالتفصي أكثر أدوات ُوجدت
tcpdump
ساباح بالتقاط تقوم
ال ثلم بارشُم بشكل منيَخدتسُملا ت
dsniff
.
Dsniff:
reader@hacking:~/booksrc $ sudo dsniff -n
dsniff: listening on eth0
-----------------
12/10/02 21:43:21 tcp 192.168.0.193.32782 -> 192.168.0.118.21 (ftp)
USER leech
PASS l8@nite
Building Our Sniffer!
ال برامج تعمل كيف قرب عن سنتعرف واآلن
Network Sniffing
املختلف
ة
.
:ل ُالرج ذذا ُهيقول ما عىل نظرة ُلقن تعال
Packet sniffers can be coded by either using sockets api provided by the kernel, or by using some
packet capture library like libpcap.
Basic Sniffer using sockets
To code a very simply sniffer in C the steps would be:
1. Create a raw socket.
2. Put it in a recvfrom loop and receive data on it.
A raw socket when put in recvfrom loop receives all incoming packets. This is because it is not
bound to a particular address or port.
189.
اإلالقرصنة
لكتروني
ة
المعلوماتوأمن
Understanding Hacking andInformation Security
Security & Attacks
[189]
sock_raw = socket(AF_INET , SOCK_RAW , IPPROTO_TCP);
while(1)
{
data_size = recvfrom(sock_raw , buffer , 65536 , 0 , &saddr , &saddr_size);
}
That’s all. The buffer will hold the data sniffed or picked up. The sniffing part is actually
complete over here. The next task is to actually read the captured packet, analyze it and present it
to the user in a readable format.
…
ال سيستخدم أنه ربنا ُ
خي أن ل ُالرج ذذا ريدُي
Row Socket
َيل
ال داطل حيدث ما طالله من فكش
OSI Layers
،
وكام
يظهر
ال نوع حدد ققد الكود يف
Protocol Family
ب
IPv4
،
ال نوع واطتار
Socket
ليكون
Row Socket
،
ثم
ال بروتوكول مراقبة ريدُي أنه حدد
TCP
.
ال استخدم ثم
recvfrom( )
ال تستقبل والتي
Arguments
تراذا التي
بعمل يقوم كي استخدمها ،باألعىل
Capture
لل
traffic
كا َربَع املار
ال يف زينه َ
وخت الشبكة رت
buffer
،
لكتمَي ولكي
ال ذذا
Sniffer
مَستخدن أن دُبال ،الرائع
function
ال ذذه ضرَوع زرَق لَمَعل
data
.
كذلك أليس
!
،
..سنستخدم؟ قامذا
مَخدتنس َ
س
ال
dump( )
السابق الفصل يف حناذا َ
رش التي
.!
ُكنمكُي
راجعتهاُم
.عملها آلية تتذكر كي
ال ذذا ُشاذدنل ذيا
Sniffer
ال لدطال بعد
Dump( )
:عليه
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "error.h"
اإلالقرصنة
لكتروني
ة
المعلوماتوأمن
Understanding Hacking andInformation Security
Security & Attacks
[206]
الكو ذذا سنطرح
عىل د
أجزاء ثالثة
عىل لِّه َ
ُسن كي
ناسُفأن
.اإلستيعاب عملية
أننا الحظ
لنستبد سوف
ال
function
ال يف استخدمناذا التي
sniffer
بإسم كانت والتي السابق
pcap_next( )
..
.. وظيفتها؟ نسيت ذل
وظيفتها كانت
يف تتمثل
ال بل َج
packet
.التالية
لذلك سنستخدم
function
أطرى
ذي ،منها أقضل
pcap_loop( )
،
م قاعلية أكثر ُعدتو
نها
.
ماييل
ال
prototype
:ِبا اخلاص
int pcap_loop(pcap_t *handle, int count, pcap_handler caught_packet,
u_char *args);
ال ماذذه
Arguments
جزعُملا
ة
تقلق ال.. .!!
..
سيكون
رامُيما عىل يشء كل
.
لن
ال ِبذا بدأ
Handle
:
ال تعريف عطيكُأ دعني
Handle
..ًاجيد لتفهمه التشغيل أنظمة نظر وجهة من
السيد لنا عرفُي
Michael Sikorski
ال
Handles
ييل كام
:
Handles are items that have been opened or created in the OS, such as a window, process,
module, menu, file, and so on. Handles are like pointers in that they refer to an object or memory
location somewhere else. However, unlike pointers, handles cannot be used in arithmetic
operations, and they do not always represent the object’s address.
The only thing you can do with a handle is store it and use it in a later function call to refer to
the same object.
!جيد ذذا
..
ال ذذا قكرة سنستخدم كيف
handle
ال ذذه يف ناُذ
pcap_loop( )
؟..
اإلالقرصنة
لكتروني
ة
المعلوماتوأمن
Understanding Hacking andInformation Security
Security & Attacks
[225]
If we analyze the figure, we see:
The application layer sends the data (to be transferred to remote destination) to the transport
layer.
The transport layer puts its header in the beginning and sends this complete packet
(TCP-header + app-data) to the IP layer.
On the same lines, The IP layer puts its header in front of the data received from TCP
So now the structure of IP datagram becomes (IP-header + TCP-header + app-data).
This IP datagram is passed to the ethernet layer which on the same lines adds its own header
to IP datagram and then the whole packet is transmitted over network.
On the destination host, the reverse process happens. This means that each layer reads its own
header in the packet and then strips the header so that finally application receives the app-data.
صاحب
:أسفلها والرشح الصورة
HIMANSHU ARORA
موقع من
thegeekstuff.com
اآلن سننطلق
ال قلسفة فَشتَكنل
"
ARP Poisoning
"
ARP Poisoning Attack
بال تعلقةُملا التفاصيل من العديد تفهم اآلن َ
أنت
Packet Capturing
،
ُريدن التي األمور بعض لنا يتبقى
احلديث نود
عنها
.
كال برنامج باستخدام نقوم عندما
WireShark
ال أو
TCPDump
ب لةتصُملا األجهزة أحد عىل
Switch
قهذا
ال ةَبَقراُم نم كنَنتم َ
س أننا يعني
traffic
ل القادم
من الصادر أو لينا
عندنا
.
لك
ن
لن
ما مراقبة من نتمكن
ت
بقية ُهفعل
ال نفس يف عناَم التي األجهزة
Broadcast Domain
!!
.
اإلالقرصنة
لكتروني
ة
المعلوماتوأمن
Understanding Hacking andInformation Security
Security & Attacks
[230]
“Nemesis is a command-line network packet crafting and injection utility.
Nemesis can natively craft and inject ARP, DNS, ETHERNET, ICMP, IGMP, IP, OSPF, RIP,
TCP and UDP packets”.
Using the IP and the Ethernet injection modes, almost any custom packet can be crafted and
injected.
ال ملف شكل وذذا
Source
:حتميله بعد
اإلالقرصنة
لكتروني
ة
المعلوماتوأمن
Understanding Hacking andInformation Security
Security & Attacks
[244]
بتخصيص ربجمنيُملا أحد قام لذا ًالقمث
buffer
نام لستقبَيل
inputs
،
ال ذذا وكان
buffer
ي
س
بتوع
6 bytes
،
ُقق
منا
بإدطال ُنحن
8 bytes
ثُحيد قسوف ،!ذلك من ًالبد
Overflow
ال هلذا
buffer
.
بال اإلجراء ذذا سمىُي
Buffer Overrun
أو
Buffer Overflow
،
ال ألن
2 bytes
املساح عن الزائدين
ة
َ
صصَخُملا
ة
األزم ذذه يف سيتسببان
ة
ال ..
“Overflow”
.ثاحلاد
من حالة يوضح مثال ذذا
ال حاالت
BOF
.
اكتشاقها تم
طاصية تفعيل أثناء
التصحيح
يف اإلمالئي
برنامج
ال
Word
.
“Buffer Overrun Detected error after you installs Office 2003 Service Pack 3 for Hebrew”
The Hebrew version of Microsoft Office Word 2003 Service Pack 3 may stop responding when
you run a spelling and grammar check or when you use a custom dictionary that was created
before Service Pack 3.
You may receive the following error message:
Microsoft Visual C ++ Runtime library
buffer overrun detected! Program: C:Program FilesMicrosoft OfficeOffice11Winword.exe, A
buffer overrun has been detected which has corrupted the program's internal state. The program
cannot safely continue execution and must now be terminated.
س
بس مثال نأطذ
الثغرة ذذه ثُد َ
حت كيف لنفهم يط
.
245.
اإلالقرصنة
لكتروني
ة
المعلوماتوأمن
Understanding Hacking andInformation Security
Security & Attacks
[245]
تأمل
عيَم
ذ
:الكود ذا
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
int value = 5;
char buffer_one[8], buffer_two[8];
strcpy(buffer_one, "one"); /* Put "one" into buffer_one. */
strcpy(buffer_two, "two"); /* Put "two" into buffer_two. */
printf("[BEFORE] buffer_two is at %p and contains '%s'n",
buffer_two, buffer_two);
printf("[BEFORE] buffer_one is at %p and contains '%s'n",
buffer_one, buffer_one);
printf("[BEFORE] value is at %p and is %d (0x%08x)n", &value,
value, value);
printf("n[STRCPY] copying %d bytes into buffer_twonn",
strlen(argv[1]));
strcpy(buffer_two, argv[1]); /* Copy first argument into
buffer_two. */
printf("[AFTER] buffer_two is at %p and contains '%s'n",
buffer_two, buffer_two);
printf("[AFTER] buffer_one is at %p and contains '%s'n",
buffer_one, buffer_one);
printf("[AFTER] value is at %p and is %d (0x%08x)n", &value,
value, value);
}
:الكود ذذا يف
استقبال دد َ
صب َُحنن
input
ُملا نم
ال وذو مَخدتس
argv[1]
ال يف وضعهب َقومنل
buffer_two
.
246.
اإلالقرصنة
لكتروني
ة
المعلوماتوأمن
Understanding Hacking andInformation Security
Security & Attacks
[246]
بإداطل سنقوم
Input
ًالمث ..عشوائية
“1234567890”
لّدَعُمب
10 bytes
،
أهنا الحظ
char array
ستتعامل أهنا أي
ال مع
وكأنه رقم
char
قسيشغل
1 byte
ققط
.
:النتائج ُشاذدنل ذيا
reader@hacking:~/booksrc $ gcc -o overflow_example overflow_example.c
reader@hacking:~/booksrc $ ./overflow_example 1234567890
[BEFORE] buffer_two is at 0xbffff7f0 and contains 'two'
[BEFORE] buffer_one is at 0xbffff7f8 and contains 'one'
[BEFORE] value is at 0xbffff804 and is 5 (0x00000005)
[STRCPY] copying 10 bytes into buffer_two
[AFTER] buffer_two is at 0xbffff7f0 and contains '1234567890'
[AFTER] buffer_one is at 0xbffff7f8 and contains '90'
[AFTER] value is at 0xbffff804 and is 5 (0x00000005)
reader@hacking:~/booksrc $
السط يف ُالحظن
ال ر
bold
حدوث تم أنه
Overflow
وضع اولة ُ
حم بسبب ،بالفعل
10 bytes
ص ّ
ص ُ
ُم تغريُم داطل
بيستوعل
8 bytes
.ققط
ال ذذه قامت وبالتايل
2 bytes
الزائد
ة
بعمل
overflow
تغريُللم
buffer_one
ال ألن وذذا ..لنا َرَهَظ كام
buffer
ال
زائد
ة
املألوف عن
بِّبُست
overflow
تغُللم
األطرى ريات
القريب
ة
منها
ال داطل
memory
.
لدطال ب ُِّجرنس
input
:ثُحيد ما ُشاذدنو ًانسبي كبرية
reader@hacking:~/booksrc $ ./overflow_example
AAAAAAAAAAAAAAAAAAAAAAAAAAAAA
[BEFORE] buffer_two is at 0xbffff7e0 and contains 'two'
[BEFORE] buffer_one is at 0xbffff7e8 and contains 'one'
[BEFORE] value is at 0xbffff7f4 and is 5 (0x00000005)
[STRCPY] copying 29 bytes into buffer_two
[AFTER] buffer_two is at 0xbffff7e0 and contains
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
[AFTER] buffer_one is at 0xbffff7e8 and contains
'AAAAAAAAAAAAAAAAAAAAA'
247.
اإلالقرصنة
لكتروني
ة
المعلوماتوأمن
Understanding Hacking andInformation Security
Security & Attacks
[247]
[AFTER] value is at 0xbffff7f4 and is 1094795585 (0x41414141)
Segmentation fault (core dumped)
reader@hacking:~/booksrc $
املتغري أن الحظ
“int value 5”
حدث ًاأيض
له
overflow
.!املرة ذذه
ال سنزيد
Buffer
:الكود ذذا لنخترب أكثر
reader@hacking:~/booksrc $ ./notesearch
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
-------[ end of note data ]-------
Segmentation fault
reader@hacking:~/booksrc $
دوث ُح يف َ
َسببت قد ُهأن ظُالحن
crash
.للربنامج
The Stack
..نبدأ أن قبل
س
عضَبب ك ُِّركَذُأ
ًاسابق ناقشناذا التي املعلومات
ماييل ،
كتاب من األسطر بعض
“the shellcoder’s handbook”
:
"When a program is executed, it is laid out in an organized manner—various elements of the
program are mapped into memory. First, the operating system creates an address space in which
the program will run. This address space includes the actual program instructions as well as any
required data. Next, information is loaded from the program’s executable file to the newly
created address space. There are three types of segments: .text, .bss, and .data. The .text segment
is mapped as read-only, whereas .data and .bss are writable. The .bss and .data segments are
248.
اإلالقرصنة
لكتروني
ة
المعلوماتوأمن
Understanding Hacking andInformation Security
Security & Attacks
[248]
reserved for global variables. The .data segment contains static initialized data, and the .bss
segment contains uninitialized data. The final segment, .text, holds the program instructions.
Finally, the stack and the heap are initialized".
↑ Lower addresses (0x08000000)
Shared libraries
.text
.bss
Heap (grows ↓)
Stack (grows ↑)
env pointer
Argc
↓ Higher addresses (0xbfffffff)
ال مع نتعامل ُناك متى تتذكر ذل
Stack
..
؟
معها تعاملنا
ندماع
ا
حت
جنا
لجراء
Function Call
.
س
ذ ُ
نأط
ُزذن
ة
طفيف
ة
ال لداط
Stack
و
عملية
ال
Function Call
.!ذذه
Let’s think about what happens in a function call:
When a function call is executed, the arguments need to be evaluated to values.
Then, control flow jumps to the body of the function, and code begins executing there.
Once a return statement has been encountered, we're done with the function, and return back to
the function call.
ليةَمَع ُلكل
“function call”
،
ال يف نَّكوتَي
Stack
ال هذهل ص ّ
ص ُُم زء ُج
function
عليه ُطلقن .
“Stack Frame”
.
بال يبدأ صغري برنامج داطل أننا ًامع لنتخيل
main( )
،
ال تكون ُ
يث َح
Stack
اهليئة ذذه عىل حينها
،
يف يبدو كام
،التالية الصفحة
يف
رقم الشكل
(
1
)
:
اإلالقرصنة
لكتروني
ة
المعلوماتوأمن
Understanding Hacking andInformation Security
Security & Attacks
[251]
لىل شريُي اليشء ذذا
ال
Address
ال عليه فقَي َكان الذي
Stack Pointer
َمتقو أن قبل
foo( )
ال ُ
حيث لىل تحريكهب
Local Variables
.ِبا اخلاصة
Points to the location where the stack pointer was, just before foo( ) moved the stack pointer
for foo( )'s own local variables.
ع؟املوض ذلك لىل شريُي وملاذا
ال يتمكن كي
Stack Pointer
بالعودة
لليه
تنتهي أن بعد أطرى ًةمر
foo( )
عملها من
.
؟ًالذ يعود كيف
بتنفيذ
instruction
:ِبذه أشبه
move [%EBP, %ESP]
ال قينتقل
SP
ال لىل
FP
حدوث ذلك ويسبب
reduce
لل
stack
.
الشكل يف موضح ذو كام
رقم
(
4
(
Figure 4
252.
اإلالقرصنة
لكتروني
ة
المعلوماتوأمن
Understanding Hacking andInformation Security
Security & Attacks
[252]
لك سأوضح
ال عملية
function call
عميل بمثال
..
بالرتتيب اخلطوات ماييل
:
1. Push the parameters in the reverse order (right to left).
2. "Call" function now. It implicitly pushes the return address into STACK.
[[ call func ]]
(انتبه
!
..
ال َبني طل َ
خت ال
return address
وال
return value
)
------ Now enters the called procedure ------
3. Push the current EBP ie. Frame Pointer (FP) of calling function into stack. We need to do
this to continue with the execution of calling function after return from the called
function. [[ pushl %ebp ]]
4. Copy the ESP to EBP. (yes, this location will be new FRAME POINTER)
[[ movl %esp, %ebp ]]
5. Allocate space on stack for local variables. It's done by decrementing ESP.
[[ subl $4, %esp ]]
------ Do some processing ------
6. Put the value to be returned in EAX.
----- Start unwinding STACK ------
7. Copy current EBP to ESP, it will reduce stack's size. Now we have old FP at the top of
the stack.
[[ movl %ebp, %esp]]
8. Pop a 32 bit value (which is old frame pointer) and stuff it into EBP. (undoing Step 3)
[[ popl %ebp ]]
9. The "ret" instruction pops a 32 bit value from the stack and stuffs into the program
counter.
[[ ret ]]
** Steps 7 and 8 are combined in single instruction "leave".
اإلالقرصنة
لكتروني
ة
المعلوماتوأمن
Understanding Hacking andInformation Security
Security & Attacks
[266]
Data Execution Prevention (DEP):
is a set of hardware, and software, technologies that perform additional checks on memory, to
help prevent malicious code from running on a system. The primary benefit of DEP is to help
prevent code execution by raising an exception, when execution occurs.
Address Space Layout Randomization (ASLR):
ASLR randomizes the base addresses of loaded applications, and DLLs, every
time the Operating System is booted.
..رحلتنا نبدأل ذيا
التالية الصفحة يف
مَستخدُملا البيئة عن ِّ
عربُي شكل
ة
اإل يف
.طتبار
ال بتنصيب قيه مناُق
SLmail
وال
Debugger
ال عىل بنا اخلاص
Win XP
.
..األوىل طوةُخلا لىل نأيت
Preparing and Sending our Buffer
ال لعدادات من البداية يف تأكد
Firewall
بال اخلاص
Windows
ال بمرور يسمح أنه
traffic
املنفذ عرب
110
وذو ،
ال منفذ
POP3
،
ي أو
ال ليقاف مكنك
Firewall
.أردت لن مؤقت بشكل
اإللكترونيالقرصنة
ة
المعلوماوأمن
ت
Understanding Hacking andInformation Security
Cryptography
[338]
Nonrepudiation
provides assurance to the recipient that the message was actually originated by
the sender and not someone masquerading as the sender. It prevents the sender from claiming
that they never sent the message in the first place
“it prevents ether sender or receiver from denying a transmitted message”
ال ماذذا
Masquerading
؟..
ال أنواع من نوع لنه
Active Attacks
ال قيه يقوم الذي
Attacker
ب
انتحال
ال ولسال أحدذم شخصية
Data
ُهوكأن
ذو
ذلك
.الشخص
339.
اإللكترونيالقرصنة
ة
المعلوماوأمن
ت
Understanding Hacking andInformation Security
Cryptography
[339]
ال يوضح شكل ذذا
:Masquerading Attack
اخلاصية ذذه
-
Nonrepudiation
-
ال لنا رذاِّقوُي ال
Symmetric Cryptography
.
ال ذذا يمتلك شخص أي ببساطة ألنه
Shared Secret Key
.!يل ولرساهلا الرسالة تشفري من سيتمكن
Because any communicating party can encrypt and decrypt messages with the shared secret key,
there is no way to tell where a given message originated.
ال لىل أطرى ًةمر لنعود ذيا..واآلن
Asymmetric Cryptography
.
ال عن نتكلم كنا
Asymmetric Cryptosystem
..
و
ب
عىل عرضه
املفاذيم
عرقناذا التي اجلديدة
اآلن
،
ُ
حي أنه ُالحظن
ماييل لنا قق
:
Confidentiality, integrity, and Nonrepudiation
.
اإللكترونيالقرصنة
ة
المعلوماوأمن
ت
Understanding Hacking andInformation Security
Cryptography
[377]
قِّبَطُت األطرى الناحية يف
Alice
ال
Key
ال عىل ل ُ
صَحتل
(h’)
.
ال بتطبيق قتقوم
MD5
الرسالة عىل ًاأيض
(M)
ال قينتج ،
(h)
،
بال ُهُقارنتل
(h’)
.
Digital Signature Standard (DSS)
ال ذذا ما
(
DSS
؟..)
Digital Signature Security Standard (DSS) is a technology for creating digital signatures that was
developed by the National Security Agency and adopted by the United States government as its
digital-signature standard. DSS defines the Digital Signature Algorithm (DSA), DSA does not
encrypt message digests with the private key or decrypt the message digest with the public key!.
it uses special mathematical functions to generate a digital signature composed of two 160-bit
numbers (s & r) that are derived from the message digest and the private key. Then it uses the
public key to verify the signature.
ال ذذه تعمل كيف
Algorithm
؟
ال تستخدم لهنا
Hash Function
إلنتاج
hash code
ُملا الرسالة من
ال مََخدتسُي ثم ،لرساهلا راد
hash code
ك ذذا
input
ال لاىل
(
Signature Algorithm
.)
ال ذذه تعتمد
Signature
ال استخدام عىل
private key
ال عىل وتعتمد ،التشفري يف
public key
لال ،التشفري قك يف
ال وذو ،العملية ذذه يف ًاأيض ثالث عنرص تستقبل أهنا
Global Public Key (Pug)
ال من جمموعة عن بارةع ُهلن
parameters
.الطرقني الك يستخدمها التي
اإللكترونيالقرصنة
ة
المعلوماوأمن
ت
Understanding Hacking andInformation Security
Cryptography
[391]
Inside Secure Socket Layer (SSL)
ال مََخدتسُي
SSL
ال أو
TLS
البيانات تشفري يف
ال بني
Web Servers
وال
Browsers
اإلنرتنت عرب
.
بقيامه وذلك
عىل الطرقني بني التواقق بإجراء
ال أنواع
Algorthims
نوم ،وترتيبها اإلتصال تأمني يف مةَستخدُملا
البيانات لُدَبات مَث
.بأمان
مقدم ماييل
ة
ِسيع
ة
موقع من عنه
info.ssl.com
SSL is the standard security technology for establishing an encrypted link between a web server and a
browser. This link ensures that all data passed between the web server and browsers remain private and
integral. SSL is an industry standard and is used by millions of websites in the protection of their online
transactions with their customers.
To be able to create an SSL connection a web server requires an SSL Certificate. When you choose to
activate SSL on your web server you will be prompted to complete a number of questions about the
identity of your website and your company. Your web server then creates two cryptographic keys - a
Private Key and a Public Key.
The Public Key does not need to be secret and is placed into a Certificate Signing Request (CSR) - a data
file also containing your details. You should then submit the CSR. During the SSL Certificate application
process, the Certification Authority will validate your details and issue an SSL Certificate containing your
details and allowing you to use SSL. Your web server will match your issued SSL Certificate to your
Private Key. Your web server will then be able to establish an encrypted link between the website and
your customer's web browser.
Typically an SSL Certificate will contain your domain name, your company name, your address, your
city, your state and your country. It will also contain the expiration date of the Certificate and details of
the Certification Authority responsible for the issuance of the Certificate. When a browser connects to a
secure site it will retrieve the site's SSL Certificate and check that it has not expired, it has been issued by
a Certification Authority the browser trusts, and that it is being used by the website for which it has been
issued. If it fails on any one of these checks the browser will display a warning to the end user letting
them know that the site is not secured by SSL.
اإللكترونيالقرصنة
ة
المعلوماوأمن
ت
Understanding Hacking andInformation Security
Cryptography
[395]
ال يقوم
Client (Browser)
ال ببدء ناُذ
Session
ال مع
Web Server
ال ذذه لرسال طريق عن
Msg
وحتوي ،
:اآليت
Version
The Client sends the version number that it supports. For example, for SSLv3, the version
number is 3.0. For TLS, the version number is 3.1.
Random
من نكوُم عشوائي رقم عن عبارة ذو
26 Byte
ال من كل ُهخيتار
Server
وال
Client
ُلكل
Connection
ثُحيد
.بينهم
Session ID (if any)
This is included if the Client wants to resume a previous session. If the Session ID Length is 0, it
indicates a new session.
Cipher Suite
This is the list of cipher suites that are supported by the Client.
ال ذذا لتوضيح ثالَمكو
Cipher Suite
َن َ
س
ضعر
:أحدذم
)TLS_RSA_WITH_DES_CBC_SHA(
TLS is the protocol version, RSA is the algorithm that will be used for key exchange, DES_CBC
is the encryption algorithm, and SHA is the hash function.
ال ماذذا ولكن
CBC
ال مع مََخدتسُملا
DES Cryptosystem
؟..
ال أنواع ال أحد لنه
“Modes of Operation”
َتسُملا
َخد
َم
ة
يف
ال تشفري
Blocks of Data
زياد بغرض
ة
يف التعقيد
ال بني العالقة
Plaintext
وال
Ciphertext
.
ل مثال ماييل
“Client Hello”
بال التقاطها َّمت
WireShark
.
اإللكترونيالقرصنة
ة
المعلوماوأمن
ت
Understanding Hacking andInformation Security
Cryptography
[408]
لىل اإلنتقال
Ephemeral Diffie-Hellman
ال اعتامد ضعف نقطة عىل تعرقنا أن وبعد واآلن
session key
ال على
private key
..
ال باستخدام سنقوم
DH
العملي هلذه
ة
مل
ُهل ا
لمكانية من
رائع
ة
الضعف نقطة عىل التغلب يف
.!ذذه
When we use Diffie–Hellman key exchange in SSL, it is only used for deriving a session keys,
the authentication of the server is done by the server’s private key.
The use of Diffie–Hellman key exchange is to use a separate method to derive session key
independent from the server's private key.
ذلك؟ يتم وكيف
بطريق األمر سنوضح
ة
طبسُم
ة
..
ًامع لنتصور
ال باستخدام يتواصالن طرقان وجود أنه
DH
لنرى لالطرتاق القناة ذذه ض ُِّعرنس الوقت نفس ويف ،
!حيدث أن مايمكن
اإللكترونيالقرصنة
ة
المعلوماوأمن
ت
Understanding Hacking andInformation Security
Cryptography
[410]
ال
العملي ذذه عن عربُي التايل شكل
ة
:األرقام باستخدام
The number (1,048,576) is the shared secret.
The numbers (16 and 32) are the public keys.
The random numbers (4 and 5) are the private keys.
The common number (2 in this example) would normally be passed system-to-system as
part of the application’s negotiation.
قكرة عرقنا لقد
عمل
Diffie-Hellman
،
ق
تعني امذا
لفظة
“Ephemeral”
ذذه
؟
مر كل قفي ،األلوان مثال عىل باإلسقاط
ة
ال يقوم
client
بببدء
session
جديد
ة
م
ال ع
server
اطتيار يتم
لونني
ِّ
ِسيني
Secret Colors
،جديدين
أي
“New Random intgers”
.
ال مفهوم ماحيقق وذذا
PFS
Static Diffie-Hellman key exchanges always use the same Diffie-Hellman private keys. So, each
time the same parties do a DH key exchange, they end up with the same shared secret.
When a key exchange uses Ephemeral Diffie-Hellman (DHE), a temporary DH key is generated
for every connection and thus the same key is never used twice. This enables “Forward Secrecy”.
* Note- The perfect forward secrecy offered by (DHE) comes at a price, “more computation”.
The (ECDHE) variants use elliptic curve cryptography to reduce this computational cost.
411.
اإللكترونيالقرصنة
ة
المعلوماوأمن
ت
Understanding Hacking andInformation Security
Cryptography
[411]
ال أن نعرف كيف
Server
ال أو
Browser
ال يدعم
PFS
؟..
بال اإلتصال طريق عن
Server
ال لك سيظهر
cipher suite
:كامييل بينكم ستخدمُملا
RSA keys are used here for authentication purposes
ECDHE is for the key exchange
AES is for the encryption itself
اإللكترونيالقرصنة
ة
المعلوماوأمن
ت
Understanding Hacking andInformation Security
[429]
XSS Attack types:
Persistent XSS
where the malicious string originates from the website's database.
Reflected XSS
where the malicious string originates from the victim's request.
DOM-based XSS
where the vulnerability is in the client-side code rather than Server-side code.
Persistent XSS
:اهلجوم من النوع ذذا تنفيذ ططوات يوضح شكل ماييل
اإللكترونيالقرصنة
ة
المعلوماوأمن
ت
Understanding Hacking andInformation Security
[437]
Core Layer
Core Layer is considered as the back bone of networks, The Core Layer routers move
information on the network as fast as possible.
Core Layer consists of biggest, fastest, and most expensive routers with the highest model
numbers.
Aggregation Layer
The purpose of this layer is to provide boundary definition by implementing access lists and
other filters. Therefore the Distribution Layer defines policy for the network. Distribution Layer
includes layer 3 switches. it ensures that packets are properly routed between subnets and
VLANs in the enterprise.
438.
اإللكترونيالقرصنة
ة
المعلوماوأمن
ت
Understanding Hacking andInformation Security
[438]
Access Layer
Access layer switches ensures that packets are delivered to the end devices,
It includes Access Switches which are connected to the end devices (Computers, and Servers).
من نوعني بتوضيح سنقوم
ال
Patterns
Traffic
ال يف عليهم تعارفُملا
Data Center
.
:األول النوع
South Traffic
-
North
ال من النوع ذذا
Traffic
ًاأيض عليه قُطلن
“Client-Server Traffic”
.
Traffic between Data Center and any thing else outside, (Traffic that travels in and out of the
data center).
األمثل بعض ذذه
ة
..عليه
ال
Traffic
بال اخلاص
HTTP/HTTPs
ال أو ،
Exchange
ال أو ،
SharePoint
.
ال أن يتضح
Network Model
األنواع ذذه مثل مع التعامل يف جيدة كفاءة ثبتُي باألعىل عنه تكلمنا الذي
ال من
Traffic
ال بني األغلب يف تكون التي
Remote Clients
وال
Servers
ال بداطل
Data Center
.
ذذا
ال
Network Model
ال مبدأ عىل بنيَم
Redundancy
نقول كام أو طلل أي حدوث حالة يف واحلامية
:
“Resiliency against any failure”
.
ال تفعيل طريق عن وذلك
Spanning Tree Protocol
.
ل بج َح ذلك عن ينتج الربوتوكول ذذا تفعيل عند ولكن
50%
ال من
Network Links
بالصفحة بالشكل يظهر كام
املاضي
ة
.