~/Short Notes#

JavaScript: OS Detection

var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";

document.write('Your OS: '+OSName);
//Your OS: Linux

JavaScript: Browser Detection

var nVer = navigator.appVersion;
var nAgt = navigator.userAgent;
var browserName  = navigator.appName;
var fullVersion  = ''+parseFloat(navigator.appVersion); 
var majorVersion = parseInt(navigator.appVersion,10);
var nameOffset,verOffset,ix;

if ((verOffset=nAgt.indexOf("OPR/"))!=-1) {
 browserName = "Opera";
 fullVersion = nAgt.substring(verOffset+4);
}
else if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
 browserName = "Opera";
 fullVersion = nAgt.substring(verOffset+6);
 if ((verOffset=nAgt.indexOf("Version"))!=-1) 
   fullVersion = nAgt.substring(verOffset+8);
}
else if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
 browserName = "Microsoft Internet Explorer";
 fullVersion = nAgt.substring(verOffset+5);
}
else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
 browserName = "Chrome";
 fullVersion = nAgt.substring(verOffset+7);
}
else if ((verOffset=nAgt.indexOf("Safari"))!=-1) {
 browserName = "Safari";
 fullVersion = nAgt.substring(verOffset+7);
 if ((verOffset=nAgt.indexOf("Version"))!=-1) 
   fullVersion = nAgt.substring(verOffset+8);
}
else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
 browserName = "Firefox";
 fullVersion = nAgt.substring(verOffset+8);
}
else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) < 
          (verOffset=nAgt.lastIndexOf('/')) ) 
{
 browserName = nAgt.substring(nameOffset,verOffset);
 fullVersion = nAgt.substring(verOffset+1);
 if (browserName.toLowerCase()==browserName.toUpperCase()) {
  browserName = navigator.appName;
 }
}
if ((ix=fullVersion.indexOf(";"))!=-1)
   fullVersion=fullVersion.substring(0,ix);
if ((ix=fullVersion.indexOf(" "))!=-1)
   fullVersion=fullVersion.substring(0,ix);

majorVersion = parseInt(''+fullVersion,10);
if (isNaN(majorVersion)) {
 fullVersion  = ''+parseFloat(navigator.appVersion); 
 majorVersion = parseInt(navigator.appVersion,10);
}

document.write(''
 +'Browser name  = '+browserName+'<br>'
 +'Full version  = '+fullVersion+'<br>'
 +'Major version = '+majorVersion+'<br>'
 +'navigator.appName = '+navigator.appName+'<br>'
 +'navigator.userAgent = '+navigator.userAgent+'<br>'
)
//Browser name = Chrome
//Full version = 88.0.4324.182
//Major version = 88
//navigator.appName = Netscape
//navigator.userAgent = Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36

JavaScript: Screen Size Detection

var screenW = 640, screenH = 480;
if (parseInt(navigator.appVersion)>3) {
 screenW = screen.width;
 screenH = screen.height;
}
else if (navigator.appName == "Netscape" 
    && parseInt(navigator.appVersion)==3
    && navigator.javaEnabled()
   ) 
{
 var jToolkit = java.awt.Toolkit.getDefaultToolkit();
 var jScreenSize = jToolkit.getScreenSize();
 screenW = jScreenSize.width;
 screenH = jScreenSize.height;
}

document.write(
 "Screen width = "+screenW+"<br>"
+"Screen height = "+screenH
)
//Screen width = 1366
//Screen height = 768

JavaScript: Windows Size Detection

var winW = 630, winH = 460;
if (document.body && document.body.offsetWidth) {
 winW = document.body.offsetWidth;
 winH = document.body.offsetHeight;
}
if (document.compatMode=='CSS1Compat' &&
    document.documentElement &&
    document.documentElement.offsetWidth ) {
 winW = document.documentElement.offsetWidth;
 winH = document.documentElement.offsetHeight;
}
if (window.innerWidth && window.innerHeight) {
 winW = window.innerWidth;
 winH = window.innerHeight;
}

document.writeln('Window width = '+winW);
document.writeln('Window height = '+winH);
//Window width = 918
//Window height = 358

JavaScript: Is Java enabled?

var javaOK = navigator.javaEnabled();

if (javaOK) document.write(''
  + 'Java is enabled: \n'
  + 'javaEnabled() returned '
  + javaOK.toString().bold()
 )
else document.write(''
  + 'Java is NOT enabled: \n'
  + 'javaEnabled() returned '
  + javaOK.toString().bold()
 )
//Java is NOT enabled: 
//javaEnabled() returned false

bash: ./Script.sh: /bin/bash^M: bad interpreter: No such file or directory

sed -i -e 's/\r$//' Script.sh

Deleting lines that are the same.

awk '!seen[$0]++' wordlist.txt > wordlist2.txt

Make the first letter uppercase.

sed -i 's/^\(.*\)$/\L\1/' wordlist.txt > wordlist2.txt

Make the first letter lowercase.

sed -i 's/^\(.\)/\U\1/' wordlist.txt > wordlist2.txt

Filter specific length characters.

grep -P '^.{7,7}$' wordlist.txt > wordlist_7_7
grep -P '^.{2,7}$' wordlist.txt > wordlist_7_7
grep -P '^.{10,12}$' wordlist.txt > wordlist_7_7
etc...

[0-9] / [a-z] / [A-Z] delete...

sed -e '/^ *[0-9]\+ *$/d' rockyou.txt > rockyou_0-9_del.txt
sed -e '/^ *[a-z]\+ *$/d' rockyou.txt > rockyou_a-z_del.txt
sed -e '/^ *[A-Z]\+ *$/d' rockyou.txt > rockyou_A-Z_del.txt

Print all 5 characters which are [0-9][a-z][A-Z].

sed -e '/^[a-zA-Z0-9]\{5,5\}$/b' -e d rockyou.txt > rockyou_5_5_characters.txt
etc..

How many are there.

root@ihsan:/usr/share/wordlists# LC_ALL=C grep -F "ihsan" rockyou.txt | wc -l
89
root@ihsan:/usr/share/wordlists# LC_ALL=C grep -F "password" rockyou.txt | wc -l
3959
root@ihsan:/usr/share/wordlists# 

Adding words to the beginning / end of the words in the list.

root@ihsan:~/Desktop# cat test.txt
password
iloveyou
princess
1234567
rockyou
12345678
abc123
nicole
daniel
babygirl
root@ihsan:~/Desktop# sed 's/^/IHSAN/; s/$/SENCAN/' test.txt > test_add.txt
root@ihsan:~/Desktop# cat test_add.txt
IHSANpasswordSENCAN
IHSANiloveyouSENCAN
IHSANprincessSENCAN
IHSAN1234567SENCAN
IHSANrockyouSENCAN
IHSAN12345678SENCAN
IHSANabc123SENCAN
IHSANnicoleSENCAN
IHSANdanielSENCAN
IHSANbabygirlSENCAN
root@ihsan:~/Desktop#

File splitting operations

root@ihsan:~/Desktop/Test# ls -al
toplam 136656
drwxr-xr-x 2 root root      4096 Şub 18 02:29 .
drwxr-xr-x 8 root root      4096 Şub 18 02:28 ..
-rw-r--r-- 1 root root 139921507 Oca  9 21:13 rockyou.txt
root@ihsan:~/Desktop/Test# split --bytes=10m rockyou.txt # --bytes=500k (1m=1MB / 500k=500KB) etc.....
root@ihsan:~/Desktop/Test# ls -al
toplam 273300
drwxr-xr-x 2 root root      4096 Şub 18 02:29 .
drwxr-xr-x 8 root root      4096 Şub 18 02:28 ..
-rw-r--r-- 1 root root 139921507 Oca  9 21:13 rockyou.txt
-rw-r--r-- 1 root root  10485760 Şub 18 02:29 xaa
-rw-r--r-- 1 root root  10485760 Şub 18 02:29 xab
-rw-r--r-- 1 root root  10485760 Şub 18 02:29 xac
-rw-r--r-- 1 root root  10485760 Şub 18 02:29 xad
-rw-r--r-- 1 root root  10485760 Şub 18 02:29 xae
-rw-r--r-- 1 root root  10485760 Şub 18 02:29 xaf
-rw-r--r-- 1 root root  10485760 Şub 18 02:29 xag
-rw-r--r-- 1 root root  10485760 Şub 18 02:29 xah
-rw-r--r-- 1 root root  10485760 Şub 18 02:29 xai
-rw-r--r-- 1 root root  10485760 Şub 18 02:29 xaj
-rw-r--r-- 1 root root  10485760 Şub 18 02:29 xak
-rw-r--r-- 1 root root  10485760 Şub 18 02:29 xal
-rw-r--r-- 1 root root  10485760 Şub 18 02:29 xam
-rw-r--r-- 1 root root   3606627 Şub 18 02:29 xan
root@ihsan:~/Desktop/Test# 

Specific range filtering.

rockyou.txt 14.344.399

sed '1000,14000000 d' rockyou.txt > rockyou_1k.txt
sed '10000,14344399 d' rockyou.txt > rockyou_10k.txt
sed '100000,14344399 d' rockyou.txt > rockyou_100k.txt
sed '500000,14344399 d' rockyou.txt > rockyou_500k.txt
sed '1000000,14344399 d' rockyou.txt > rockyou_1m.txt
sed '3000000,14344399 d' rockyou.txt > rockyou_3m.txt
sed '5000000,14344399 d' rockyou.txt > rockyou_5m.txt
sed '8000000,14344399 d' rockyou.txt > rockyou_8m.txt
sed '10000000,14344399 d' rockyou.txt > rockyou_10m.txt
sed '12000000,14344399 d' rockyou.txt > rockyou_12m.txt
sed '14000000,14344399 d' rockyou.txt > rockyou_14m.txt
etc...

Delete the first 1000 rows

sed '1,1000 d' rockyou.txt > rockyou_delf_1000.txt

Delete last 1000 rows

tac rockyou.txt | sed '1,1000 d' | tac > rockyou_dell_1000.txt