Css Lab Manul
Css Lab Manul
LAB MANUAL
SE-VI Semester
DATE
Experiment No.2:
Date of Performance :
Date of Submission :
Aim: Implementation and analysis of RSA cryptosystem
THEORY: RSA was invented by Ron Rivest, Adi Shamir, and Len Adleman and hence, it is termed
as RSA cryptosystem. We will see two aspects of the RSA cryptosystem, firstly generation of key pair
and secondly encryption-decryption algorithms.
RSA Encryption
● Suppose the sender wish to send some text message to someone whose public key is (n, e).
● The sender then represents the plaintext as a series of numbers less than n.
DBMS Lab Manual|2023
RSA Decryption
● The decryption process for RSA is also very straightforward. Suppose that the receiver
of public-keypair (n, e) has received a ciphertext C.
● Receiver raises C to the power of his private key d. The result modulo n will be
the plaintext P.Plaintext = Cd mod n
● Returning again to our numerical example, the ciphertext C = 82 would get decrypted
to number 10using private key 29 −
Plaintext = 8229 mod 91 = 10
Program:
1. #include<stdio.h>
2.
3. #include<conio.h>
4.
5. #include<stdlib.h>
6.
7. #include<math.h>
8.
9. #include<string.h>
10. long int p,q,n,t,flag,e[100],d[100],temp[100],j,m[100],en[100],i;
11.
12. char msg[100];
13.
14. int prime(long int);
15.
16. void ce();
17.
18. long int cd(long int);
19.
20. void encrypt();
21.
M. K. Nivekar, Assistant Prof. GMVIT Tala Page 13
DBMS Lab Manual|2023
68. m[i]=msg[i];
69.
70. n=p*q;
71.
72. t=(p-1)*(q-1);
73.
74. ce();
75.
76. printf("\nPOSSIBLE VALUES OF e AND d ARE\n");
77.
78. for (i=0;i<j-1;i++)
79.
80. printf("\n%ld\t%ld",e[i],d[i]);
81.
82. encrypt();
83.
84. decrypt();
85.
86. getch();
87.
88. }
89.
90. int prime(long int pr) {
91.
92. int i;
93.
94. j=sqrt(pr);
95.
96. for (i=2;i<=j;i++) {
97.
98. if(pr%i==0)
99.
100. return 0;
101.
102. }
103.
104. return 1;
105.
106. }
107.
108. void ce() {
109.
110. int k;
111.
112. k=0;
113.
160. }
161.
162. void encrypt() {
163.
164. long int pt,ct,key=e[0],k,len;
165.
166. i=0;
167.
168. len=strlen(msg);
169.
170. while(i!=len) {
171.
172. pt=m[i];
173.
174. pt=pt-96;
175.
176. k=1;
177.
178. for (j=0;j<key;j++) {
179.
180. k=k*pt;
181.
182. k=k%n;
183.
184. }
185.
186. temp[i]=k;
187.
188. ct=k+96;
189.
190. en[i]=ct;
191.
192. i++;
193.
194. }
195.
196. en[i]=-1;
197.
198. printf("\nTHE ENCRYPTED MESSAGE IS\n");
199.
200. for (i=0;en[i]!=-1;i++)
201.
202. printf("%c",en[i]);
203.
204. }
205.
DATE
Experiment No.3:
Date of Performance :
Date of Submission :
Aim: Write a program to implement diffie-hellman algorithm.
THEORY: Diffie-Hellman key exchange is a cryptographic protocol that allows two parties
that have no prior Knowledge of each other to jointly establish a shared secret key over an
insecure communications Channel. This key can then be used to encrypt subsequent
communications using a symmetric key Cipher. The diffie–hellman key exchange algorithm
solves the following dilemma. Alice and bob want to Share a secret key for use in a
symmetric cipher, but their only means of communication is insecure. Every piece of
information that they exchange is observed by their adversary eve. How is it possible For
alice and bob to share a key without making it available to eve? At first glance it appears that
Alice and bob face an impossible task. It was a brilliant insight of diffie and hellman that the
Difficulty of the discrete logarithm problem for f*p provides a possible solution. The
simplest, and original, implementation of the protocol uses the multiplicative group of
integers Modulo p, where p is prime and g is primitive root mod p. Here is an example of the
protocol: 1. Alice and bob agree to use a prime number p=23 and base g=5. 2. Alice chooses
a secret integer xa=6, then sends bob (g^xa) mod p. 56 mod 23 = 8. 3. Bob chooses a secret
integer xb=15, then sends alice (g^xb) mod p. 515 mod 3 = 19. 4. Alice computes ya = (g^xa)
mod p. 196 mod 23 = 2. 5. Bob computes yb = (g^xb) mod p. 815 mod 23 = 2 2 In the
original description, the diffie-hellman exchange by itself does not provide authentication of
The communicating parties and is thus vulnerable to a man-in-the-middle attack. A person in
the Middle may establish two distinct diffie-hellman key exchanges, one with alice and the
other with Bob, effectively masquerading as alice to bob, and vice versa, allowing the
attacker to decrypt (and Read or store) then re-encrypt the messages passed between them. A
method to authenticate the Communicating parties to each other is generally needed to
prevent this type of attack.
The Diffie-Hellman algorithm is used to establish a shared secret between two parties that
can be used for secret communication to exchange data over a public network.
/* this program calculates the Key for two persons using the Diffie Hellman Key exchange
algorithm */
#include<stdio.h>
long int power(int a,int b,int mod)
{
long long int t;
if(b==1)
return a;
t=power(a,b/2,mod);
if(b%2==0)
return (t*t)%mod;
else
return (((t*t)%mod)*a)%mod;
}
long long int calculateKey(int a,int x,int n)
{
return power(a,x,n);
}
int main()
{
int n,g,x,a,y,b;
// both the persons will be agreed upon the common n and g
printf("Enter the value of n and g : ");
scanf("%d%d",&n,&g);
// first person will choose the x
printf("Enter the value of x for the first person : ");
scanf("%d",&x); a=power(g,x,n);
// second person will choose the y
printf("Enter the value of y for the second person : ");
scanf("%d",&y); b=power(g,y,n);
printf("key for the first person is : %lld\n",power(b,x,n));
printf("key for the second person is : %lld\n",power(a,y,n));
return 0;
}
Output:
Conclusion: The Diffie-Hellman key exchange algorithm is used to make secure channel to
share secret key between sender and receiver.
DATE
Experiment No 4:
Date of Performance :
Date of Submission :
AIM : For varying message sizes, test integrity of message using MD-5, SHA-1, and analyse
the performance of the two protocols. Use crypt APIs
THEORY:
MD5 (Message Digest algorithm 5) is a widely used cryptographic hash function with
a 128 bit hash value. An MD5 hash is typically expressed as a 32 digit hexadecimal number.
MD5 processes a variable length message into a fixed length output of 128 bits. The input
message is broken up into chunks of 512 bit blocks (sixteen 32bit little endian integers) ; The
message is padded so that its length is divisible by 512. The padding works as follows: first a
single bit, 1, is appended to the end of the message. This is followed by as many zeros as are
required to bring the length of the message up to 64 bits less than a multiple of 512. The
remaining bits are filled up with a 64bit integer representing the length of the original
message, in bits.
Figure 1: One MD5 operation. MD5 consists of 64 of these operations, grouped in four
rounds of 16 operations. F is a nonlinear function; one function is used in each round. Mi
denotes a 32bit block of the message input, and Ki denotes a 32bit constant, different for each
operation. The main MD5 algorithm operates on a 128bit state, divided into four 32bit words,
denoted A, B, C and D. These are initialized to certain fixed constants. The main algorithm
then operates on each 512bit message block in turn, each block modifying the state. The
processing of a message block consists of four similar stages, termed rounds; each round is
composed of 16 similar operations based on a nonlinear function F, modular addition, and left
M. K. Nivekar, Assistant Prof. GMVIT Tala Page 23
DBMS Lab Manual|2023
rotation. Figure 1 illustrates one operation within a round. There are four possible functions
F; a different one is used in each round:
Algorithm:
1. Append Padding Bits
The message is "padded" (extended) so that its length (in bits) is congruent to 448,
modulo 512. That is, the message is extended so that it is just 64 bits shy of being a multiple
of 512 bits long. Padding is always performed, even if the length of the message is already
congruent to 448, modulo 512. Padding is performed as follows: a single "1" bit is appended
to the message, and then "0" bits are appended so that the length in bits of the padded
message becomes congruent to 448, modulo 512. In all, at least one bit and at most 512 bits
are appended.
2. Append Length
A 64 bit representation of b (the length of the message before the padding bits were added) is
appended to the result of the previous step. In the unlikely event that b is greater than 2^64,
then only the low order 64 bits of b are used. (These bits are appended as two 32bit words
and appended low order word first in accordance with the previous conventions.) At this
point the resulting message (after padding with bits and with b) has a length that is an exact
multiple of 512 bits. Equivalently, this message has a length that is an exact multiple of 16
(32 bit) words. Let M[0 ... N1] denote the words of the resulting message, where N is a
multiple of 16.
3. Initialize MD Buffer
A fourword buffer (A,B,C,D) is used to compute the message digest. Here each of A, B, C, D
is a 32bit register. These registers are initialized to the following values in hexadecimal,
loworder bytes first).
5. Output
The message digest produced as output is A, B, C, D. That is, we begin with the low order
byte of A, and end with the highorder byte of D.
Output:
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
public class SimpleMD5Example
M. K. Nivekar, Assistant Prof. GMVIT Tala Page 24
DBMS Lab Manual|2023
{
public static void main(String[] args)
{
String passwordToHash = "password";
String generatedPassword = null;
try {
// Create MessageDigest instance for MD5
// for hashing using MD5 can be replaced by SHA1 in following line
MessageDigest md = MessageDigest.getInstance("MD5");
//Add password bytes to digest
md.update(passwordToHash.getBytes());
//Get the hash's bytes
byte[] bytes = md.digest();
//This bytes[] has bytes in decimal format;
//Convert it to hexadecimal format
StringBuilder sb = new StringBuilder();
for(int i=0; i< bytes.length ;i++)
{
sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1));
}
//Get complete hashed password in hex format
generatedPassword = sb.toString();
}
catch (NoSuchAlgorithmException e)
{
e.printStackTrace();
}
System.out.println(generatedPassword);
}
}
Output:
5f4dcc3b5aa765d61d8327deb882cf99
DATE
EXPERIMENT NO: 5
Date of Performance :
Date of Submission :
AIM : Study the use of network reconnaissance tools like WHOIS, dig, traceroute, NSlookup
to gather information about networks and domain registrars.
THEORY:
1. WHOIS : WHOIS is the Linux utility for searching an object in a WHOIS database. The
WHOIS database of a domain is the publicly displayed information about a domains
ownership, billing, technical, administrative, and nameserver information. Running a WHOIS
on your domain will look the domain up at the registrar for the domain information. All
domains have WHOIS information.
WHOIS database can be queried to obtain the following information via WHOIS:
• Administrative contact details, including names, email addresses, and telephone numbers
• Mailing addresses for office locations relating to the target organization
• Details of authoritative name servers for each given domain
Example
Querying Facebook.com
ssc@ssc-OptiPlex-380:~$ whois facebook.com
Whois Server Version 2.0
Domain names in the .com and .net domains can now be registered with many different
competing registrars.
Go to http://www.internic.net
for detailed information.
Server Name: FACEBOOK.COM.BRETLANDTRUSTMERCHANDISINGDEPART.COM
IP Address: 69.63.176.11
Registrar: GOOGLE INC.
FACEBOOK.COM.DISABLE.YOUR.TIMELINE.NOW.WITH.THE.ORIGINAL.TIMELIN
E REMOVE.NET
IP Address: 8.8.8.8
Registrar: ENOM, INC.
>>> Last update of whois database: Fri, 17 Jul 2015 04:12:12 GMT <<<
The Registry database contains ONLY .COM, .NET, .EDU domains and Registrars.
LAB MANUAL [SSL]
For more information on Whois status codes, please visit
https://www.icann.org/resources/pages/epp-status-codes-2014-06-16-en.
Domain Name: facebook.com
Registry Domain ID: 2320948_DOMAIN_COM-VRSN
Registrar WHOIS Server: whois.markmonitor.com
Registrar URL: http://www.markmonitor.com
Updated Date: 2014-10-28T12:38:28-0700
reation Date: 1997-03-28T21:00:00-0800
Registrar Registration Expiration Date: 2020-03-29T21:00:00-0700
Registrar: MarkMonitor, Inc.
Registrar IANA ID: 292
Registrar Abuse Contact Email: [email protected]
Registrar Abuse Contact Phone: +1.2083895740
Domain Status: clientUpdateProhibited (https://www.icann.org/epp#clientUpdateProhibited)
Domain Status: clientTransferProhibited
(https://www.icann.org/epp#clientTransferProhibited)
Domain Status: clientDeleteProhibited (https://www.icann.org/epp#clientDeleteProhibited)
Registry Registrant ID:
Registrant Name: Domain Administrator
Registrant Organization: Facebook, Inc.
Registrant Street: 1601 Willow Road,
Registrant City: Menlo Park
Registrant State/Province: CA
Registrant Postal Code: 94025
Registrant Country: US
Registrant Phone: +1.6505434800
Registrant Phone Ext:
Registrant Fax: +1.6505434800
Registrant Fax Ext:
Registrant Email: [email protected]
Registry Admin ID:
Admin Name: Domain Administrator
Admin Organization: Facebook, Inc.
Admin Street: 1601 Willow Road,
Admin City: Menlo Park
Admin State/Province: CA
Admin Postal Code: 94025
M. K. Nivekar, Assistant Prof. GMVIT Tala Page 29
DBMS Lab Manual|2023
Admin Country: US
Admin Phone: +1.6505434800
Admin Phone Ext:
Admin Fax: +1.6505434800
Admin Fax Ext:
Admin Email: [email protected]
Registry Tech ID:
Tech Name: Domain Administrator
Tech Organization: Facebook, Inc.
Tech Street: 1601 Willow Road,
Tech City: Menlo Park
Tech State/Province: CA
MarkMonitor AntiFraud(TM)
Professional and Managed Services
Visit MarkMonitor at http://www.markmonitor.com
Contact us at +1.8007459229
In Europe, at +44.02032062220
ssc@ssc-OptiPlex-380:~$
2. Dig - Dig is a networking tool that can query DNS servers for information. It can be very
helpful for diagnosing problems with domain pointing and is a good way to verify that your
configuration is working. The most basic way to use dig is to specify the domain we wish to
query:
Example
$ dig duckduckgo.com
; <<>> DiG 9.8.1-P1 <<>> duckduckgo.com
;; global options: +cmd
;; Got answer:
LAB MANUAL [SSL]
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 64399
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;duckduckgo.com. IN A
;; ANSWER SECTION:
duckduckgo.com. 99 IN A 107.21.1.61
duckduckgo.com. 99 IN A 184.72.106.253
duckduckgo.com. 99 IN A 184.72.106.52
duckduckgo.com. 99 IN A 184.72.115.86
;; Query time: 33 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Fri Aug 23 14:26:17 2013
;; MSG SIZE rcvd: 96
The lines above act as a header for the query performed. It is possible to run dig in batch
mode,
so proper labeling of the output is essential to allow for correct analysis.
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 64399
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 0
The next section gives us a technical summary of our query results. We can see that the query
was successful, certain flags were used, and that 4 "answers" were received.
;; QUESTION SECTION:
;duckduckgo.com. IN A
M. K. Nivekar, Assistant Prof. GMVIT Tala Page 31
DBMS Lab Manual|2023
;; ANSWER SECTION:
duckduckgo.com. 99 IN A 107.21.1.61
duckduckgo.com. 99 IN A 184.72.106.253
duckduckgo.com. 99 IN A 184.72.106.52
duckduckgo.com. 99 IN A 184.72.115.86
These lines simply provide some statistics about the actual query results. The query time can
be indicative of problems with the DNS servers.
3. Traceroute - traceroute prints the route that packets take to a network host. Traceroute
utility uses the TTL field in the IP header to achieve its operation. For users who are new to
TTL field, this field describes how much hops a particular packet will take while traveling on
network. So, this effectively outlines the lifetime of the packet on network. This field is
usually set to 32 or 64. Each time the packet is held on an intermediate router, it decreases the
TTL value by 1. When a router finds the TTL value of 1 in a received packet then that packet
is not forwarded but instead discarded. After discarding the packet, router sends an ICMP
error message of ―Time exceeded‖ back to the source from where packet generated. The
ICMP packet that is sent back contains the IP address of the router.
So now it can be easily understood that traceroute operates by sending packets with TTL
value starting from 1 and then incrementing by one each time. Each time a router receives the
packet, it checks the TTL field, if TTL field is 1 then it discards the packet and sends the
ICMP error packet containing its IP address and this is what traceroute requires. So traceroute
incrementally fetches the IP of all the routers between the source and the destination.
Example:
$traceroute example.com
traceroute to example.com (64.13.192.208), 64 hops max, 40 byte packets
1 72.10.62.1 (72.10.62.1) 1.000 ms 0.739 ms 0.702 ms
M. K. Nivekar, Assistant Prof. GMVIT Tala Page 32
DBMS Lab Manual|2023
4. Nslookup - The nslookup command is used to query internet name servers interactively for
information. nslookup, which stands for "name server lookup", is a useful tool for finding out
information about a named domain. By default, nslookup will translate a domain name to an
IP address (or vice versa). For instance, to find out what the IP address of microsoft.com is,
you could run the command:
Example:
$nslookup microsoft.com
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
Name:
microsoft.com
Address: 134.170.185.46
Name:
microsoft.com
Address: 134.170.188.221
Here, 8.8.8.8 is the address of our system's Domain Name Server. This is the server our
system is configured to use to translate domain names into IP addresses. "#53" indicates that
we are communicating with it on port 53, which is the standard port number domain name
servers use to accept queries. Below this, we have our lookup information for microsoft.com.
Our name server returned two entries, 134.170.185.46and 134.170.188.221. This indicates
that microsoft.com uses a round robin setup to distribute server load. When you
accessmicrsoft.com, you may be directed to either of these servers and your packets will be
routed to the correct destination. You can see that we have received a "Non-authoritative
answer" to our query. An answer is "authoritative" only if our DNS has the complete zone
file information for the domain in question. More often, our DNS will have a cache of
information representing the last authoritative answer it received when it made a similar
query, this information is passed on to you, but the server qualifies it as "non- authoritative":
he information was recently received from an authoritative source, but the DNS server is not
itself that authority.
CONCLUSION: Various reconnaissance tools are studied and used to gather primary
network information.
DATE
EXPERIMENT NO: 6
Date of Performance :
Date of Submission :
AIM : Study of packet sniffer tools : Wireshark
THEORY:
Wireshark, a network analysis tool formerly known as Ethereal, captures packets in real time
and display them in human-readable format. Wireshark includes filters, color-coding and
other features that let you dig deep into network traffic and inspect individual packets.
Features of Wireshark :
Capturing Packets
After downloading and installing wireshark, you can launch it and click the name of an
interface under Interface List to start capturing packets on that interface. For example, if you
want to capture traffic on the wireless network, click your wireless interface. You can
configure advanced features by clicking Capture Options.
Filtering Packets
If you‘re trying to inspect something specific, such as the traffic a program sends when
phoning home, it helps to close down all other applications using the network so you can
narrow down the traffic. Still, you‘ll likely have a large amount of packets to sift through.
That‘s where Wireshark‘s filters come in.
The most basic way to apply a filter is by typing it into the filter box at the top of the window
and clicking Apply (or pressing Enter). For example, type ―dns‖ and you‘ll see only DNS
packets. When you start typing, Wireshark will help you autocomplete your filter.
Outputs:
1)Home screen:
2) Main screen:
http.request:
tcp.port==443:
CONCLUSION: Wireshark installation and network traffic analysis using Packet sniffing is
done. Detailed information about packets are explored by applying filters.
DATE:
EXPERIMENT NO: 7
Date of Performance :
Date of Submission :
AIM : Download and install NMAP. Use it with different options to scan open ports, perform
OS fingerprinting, do a ping scan, TCP port scan, UDP port scan.
THEORY:
Nmap (Network Mapper) is a security scanner originally written by Gordon Lyon (also
known by his pseudonym Fyodor Vaskovich) used to discover hosts and services on a
computer network, thus creating a "map" of the network. To accomplish its goal, Nmap sends
specially crafted packets to the target host and then analyzes the responses. Unlike many
simple port scanners that just send packets at some predefined constant rate, Nmap accounts
for the network conditions (latency fluctuations, network congestion, the target interference
with the scan) during the run. Also, owing to the large and active user community providing
feedback and contributing to its features, Nmap has been able to extend its discovery
capabilities beyond simply figuring out whether a host is up or down and which ports are
open and closed; it can determine the operating system of the target, names and versions of
the listening services, estimated uptime, type of device, and presence of a firewall.
• Host Discovery – Identifying hosts on a network. For example, listing the hosts which
respond to pings or have a particular port open.
• Port Scanning – Enumerating the open ports on one or more target hosts.
• Version Detection – Interrogating listening network services listening on remote devices to
determine the application name and version number.
• OS Detection – Remotely determining the operating system and some hardware
characteristics of network devices.
• For target specifications: nmap <target‘s URL or IP with spaces between them>
• For OS detection: nmap -O <target-host's URL or IP>
• For version detection: nmap -sV <target-host's URL or IP>
SYN scan is the default and most popular scan option for good reasons. It can be performed
quickly, scanning thousands of ports per second on a fast network not hampered by restrictive
firewalls. It is also relatively unobtrusive and stealthy since it never completes TCP
connections
OUTPUT:
Intense Scan : nmap -T4 -A 192.168.21.141
Host Details :
CONCLUSION: NMAP is studied and different types of nmap scans are used to gather host
and network related information.
DATE
EXPERIMENT NO: 8
Date of Performance :
Date of Submission :
AIM : To implement a program in Java for password cracking using Brute Force.
THEORY:
A brute-force attack is a cryptanalytic attack that can, in theory, be used to attempt to decrypt
any encrypted data (except for data encrypted in an information-theoretically secure manner.
Such an attack might be used when it is not possible to take advantage of other weaknesses in
an encryption system (if any exist) that would make the task easier.
We assume the input to be a password to be of length 4 and having only lowercase letters.
We try all possible combinations of lower-case letters to try and decode the password.
Input:
import java.util.Scanner;
import java.util.concurrent.TimeUnit;
public class Main {
static String newPass = "";
static String chars =
"0123456789aABbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyzZ";
public static void main(String[] args) {
Scanner userIn = new Scanner(System.in);
String password = userIn.nextLine();
System.out.println("Is using symbols an option? if so type in [Y] if not type in [N]");
String choose = userIn.nextLine();
boolean decideSymb = true;
boolean again = true;
while (again == true) {
if (choose.equalsIgnoreCase("y")) {
again = false;
M. K. Nivekar, Assistant Prof. GMVIT Tala Page 44
DBMS Lab Manual|2023
} else if (choose.equalsIgnoreCase("n")) {
again = false;
decideSymb = false;
} else {
System.out.println("Try again! \nIs using symbols an option? if so type in [Y] if not type
in [N]");
}
}
choose = userIn.nextLine();
mins
long start = System.currentTimeMillis();
crack(password, decideSymb);
long end = System.currentTimeMillis();
long milliSecs = TimeUnit.MILLISECONDS.toSeconds(end - start);
;
long secs = milliSecs / 1000;
long mins = secs / 60;
long hours = mins / 60;
long days = hours / 24;
long years = days / 365;
days -= (years * 365);
hours -= (days * 24);
mins -= (hours * 60);
secs -= (mins * 60);
milliSecs -= (secs * 1000);
System.out.println("The password is: " + newPass);
if (years > 0) {
if (years == 1) {
System.out.println("it took\n" + years + "year\n" + days + " days\n" + hours + " hours\n" +
+ " mins\n" + secs + " secs\n" + milliSecs + " milliseconds\nto find the password");
} else {
System.out.println("it took\n" + years + "years\n" + days + " days\n" + hours + " hours\n"
+ mins
}
+ " mins\n" + secs + " secs\n" + milliSecs + " milliseconds\nto find the password");
secs
} else if (days > 0) {
if (days == 1) {
System.out.println("it took\n" + days + " day\n" + hours + " hours\n" + mins + " mins\n" +
+ " secs\n" + milliSecs + " milliseconds\nto find the password");
} else {
M. K. Nivekar, Assistant Prof. GMVIT Tala Page 45
DBMS Lab Manual|2023
System.out.println("it took\n" + days + " days\n" + hours + " hours\n" + mins + " mins\n"
+ secs
+ " secs\n" + milliSecs + " milliseconds\nto find the password");
}
} else if (hours > 0) {
if (hours == 1) {
System.out.println("it took\n" + hours + " hour\n" + mins + " mins\n" + secs + " secs\n" +
milliSecs
+ " milliseconds\nto find the password");
} else {
System.out.println("it took\n" + hours + " hours\n" + mins + " mins\n" + secs + " secs\n" +
milliSecs
}
+ " milliseconds\nto find the password");
} else if (mins > 0) {
if (mins == 1) {
System.out.println("it took\n" + mins + " min\n" + secs + " secs\n" + milliSecs
+ " milliseconds\nto find the password");
} else {
System.out.println("it took\n" + mins + " mins\n" + secs + " secs\n" + milliSecs
+ " milliseconds\nto find the password");
}
} else if (secs > 0) {
if (secs == 1) {
System.out.println("it took\n" + secs + " sec\n" + milliSecs + " milliseconds\nto find the
password");
} else {
System.out.println("it took\n" + secs + " secs\n" + milliSecs + " milliseconds\nto find the
password");
}
} else {
System.out.println("it took\n" + milliSecs + " milliseconds\nto find the password");
}
System.exit(0);
}
private static void crack(String password, boolean decideSymb) {
if (decideSymb == true) {
chars =
"1234567890#%&@aABbCcDdEeFfGgHh!IiJjKkLlMmNnOoPpQqRr$SsTtUuVvWwXxYy
zZ";
}
M. K. Nivekar, Assistant Prof. GMVIT Tala Page 46
DBMS Lab Manual|2023
chars.indexOf(newPass.charAt(newPass.length() - 1 - howManyZs)) + 2)
+ reset0s;
} else {
indInChars = chars.indexOf(newPass.charAt(lastInd)) + 1;
newPass = newPass.substring(0, lastInd) + chars.charAt(indInChars);
}
System.out.println(newPass);
}
}
if (newPass.equals(password)) {
break;
}
}
}
}
Output:
1. Print the password
2. Print the iteration number in which the password was cracked successfully
DATE
EXPERIMENT NO: 9
Date of Performance :
Date of Submission :
THEORY:
SQL Injection (SQLi) is a type of an injection attack that makes it possible to execute
malicious SQL statements. These statements control a database server behind a web
application. Attackers can use SQL Injection vulnerabilities to bypass application security
measures. They can go around authentication and authorization of a web page or web
application and retrieve the content of the entire SQL database. They can also use SQL
Injection to add, modify, and delete records in the database.
An SQL Injection vulnerability may affect any website or web application that uses an SQL
database such as MySQL, Oracle, SQL Server, or others. Criminals may use it to gain
unauthorized access to your sensitive data: customer information, personal data, trade secrets,
intellectual property, and more. SQL Injection attacks are one of the oldest, most prevalent,
and most dangerous web application vulnerabilities. The OWASP organization (Open Web
Application Security Project) lists injections in their OWASP Top 10 2017 document as the
number one threat to web application security.
Attackers can use SQL Injections to find the credentials of other users in the database.
They can then impersonate these users. The impersonated user may be a database
administrator with all database privileges.
SQL lets you select and output data from the database. An SQL Injection vulnerability
could allow the attacker to gain complete access to all data in a database server.
SQL also lets you alter data in a database and add new data. For example, in a
financial application, an attacker could use SQL Injection to alter balances, void
transactions, or transfer money to their account.
You can use SQL to delete records from a database, even drop tables. Even if the
administrator makes database backups, deletion of data could affect application
availability until the database is restored. Also, backups may not cover the most
recent data.
In some database servers, you can access the operating system using the database
server. This may be intentional or accidental. In such case, an attacker could use an
SQL Injection as the initial vector and then attack the internal network behind a
firewall.
There are several types of SQL Injection attacks: in-band SQLi (using database errors or
UNION commands), blind SQLi, and out-of-band SQLi. You can read more about them in
the following articles: Types of SQL Injection (SQLi), Blind SQL Injection: What is it.
To follow step-by-step how an SQL Injection attack is performed and what serious
consequences it may have, see: Exploiting SQL Injection: a Hands-on Example.
Attacker steps:
1. Attacker include evil.js in xss payload & send it to admin
2. When admin is logged in admin panel & clicks on the xss payload, the sql injection request
sent to the authenticated vulnerable page
3. the returned data from sql injection is posted back to attacker site i.e. malicious.com is
logged in user_pass.html
Cross-Site Scripting (XSS) is one of the most popular and vulnerable attacks which is known
by every advanced tester. It is considered one of the riskiest attacks for web applications and
can bring harmful consequences too.
XSS is often compared with similar client-side attacks, as client-side languages are mostly
being used during this attack. However, an XSS attack is considered riskier, because of its
ability to damage even less vulnerable technologies.
Attacker can type the malicious script instead of the correct username or email address:
when wrong credentials are typed, an error message like “Sorry your username or your
credentials are wrong” will be displayed.
the username is a parameter that is typed by the user in the login form. Including the
username parameter in the output is a mistake. This way an attacker can type the malicious
script instead of the correct username or email address.
<script>alert(document.cookie)</script>
For Example:
%3cscript%3ealert(document.cookie)%3c/script%3e
DATE