REGULAR EXPRESSION WITH GREP – DOT

grep  searches  the  named input FILEs (or standard
input if no files are named, or if a single hyphen-minus
(-) is given as file name) for lines containing a match
to the given PATTERN.  By default, grep prints the matching
lines.

commandline session

$ cat first.txt
name-jeffrin
Age-35
Sex-Male
$ grep 3. first.txt
Age-35
$ grep A. first.txt
Age-35
$ grep A first.txt
Age-35
$ grep . first.txt
name-jeffrin
Age-35
Sex-Male
$ grep x.M first.txt
Sex-Male
$ grep n. first.txt
name-jeffrin
$ grep 5. first.txt
$ grep 5. first.txt
$

google chrome HANGUP .BACKTRACE

commandline session

(gdb) bt
#0  0x00007fd461dbeac3 in *__GI___poll (fds=<optimized out>, nfds=<optimized out>,
timeout=100) at ../sysdeps/unix/sysv/linux/poll.c:87
#1  0x00007fd46643f4d4 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#2  0x00007fd46643f5f4 in g_main_context_iteration ()
from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#3  0x00007fd468940c00 in ?? ()
#4  0x00007fd468918832 in ?? ()
#5  0x00007fd4686349ff in ?? ()
#6  0x00007fd46a2e8811 in ?? ()
#7  0x00007fd46a2ea31d in ?? ()
#8  0x00007fd46a2e84e9 in ?? ()
#9  0x00007fd46888e403 in ?? ()
#10 0x00007fd46888cb51 in ?? ()
#11 0x00007fd46836fb0d in ?? ()
#12 0x00007fd46836fac6 in ?? ()
#13 0x00007fd461d0fead in __libc_start_main (main=<optimized out>, argc=<optimized out>,
ubp_av=<optimized out>, init=<optimized out>, fini=<optimized out>,
rtld_fini=<optimized out>, stack_end=0x7fff388e5b08) at libc-start.c:228
#14 0x00007fd46836f9e9 in ?? ()
#15 0x00007fff388e5b08 in ?? ()
#16 0x000000000000001c in ?? ()
#17 0x0000000000000001 in ?? ()
#18 0x00007fff388e7ae3 in ?? ()
#19 0x0000000000000000 in ?? ()
(gdb)

pstree command in linux I

Commandline Session

$pstree -pA
init(1)-+-/usr/sbin/apach(2306)-+-/usr/sbin/apach(4451)
|                       |-/usr/sbin/apach(4452)
|                       |-/usr/sbin/apach(4453)
|                       |-/usr/sbin/apach(4454)
|                       `-/usr/sbin/apach(4455)
|-NetworkManager(2145)-+-dhclient(4539)
|                      |-{NetworkManager}(2196)
|                      `-{NetworkManager}(4540)
|-accounts-daemon(2233)---{accounts-daemon}(2235)
|-at-spi-bus-laun(3756)-+-dbus-daemon(3761)
|                       |-{at-spi-bus-laun}(3758)
|                       |-{at-spi-bus-laun}(3760)
|                       `-{at-spi-bus-laun}(3762)
|-at-spi2-registr(3764)---{at-spi2-registr}(37100)
|-atd(2334)
|-atop(2361)
|-avahi-daemon(2372)---avahi-daemon(2373)
|-bluetoothd(2399)
|-colord(3919)---{colord}(3928)
|-colord-sane(3931)-+-{colord-sane}(3935)
|                   `-{colord-sane}(4015)
|-console-kit-dae(2237)-+-{console-kit-dae}(2238)
|                       |-{console-kit-dae}(2239)
|                       |-{console-kit-dae}(2240)
|                       |-{console-kit-dae}(2241)
|                       |-{console-kit-dae}(2242)
|                       |-{console-kit-dae}(2243)
|                       |-{console-kit-dae}(2244)
|                       |-{console-kit-dae}(2245)
|                       |-{console-kit-dae}(2246)
|                       |-{console-kit-dae}(2247)
|                       |-{console-kit-dae}(2248)
|                       |-{console-kit-dae}(2249)
|                       |-{console-kit-dae}(2250)
|                       |-{console-kit-dae}(2251)
|                       |-{console-kit-dae}(2252)
|                       |-{console-kit-dae}(2253)
|                       |-{console-kit-dae}(2254)
|                       |-{console-kit-dae}(2255)
|                       |-{console-kit-dae}(2256)
|                       |-{console-kit-dae}(2257)
|                       |-{console-kit-dae}(2258)
|                       |-{console-kit-dae}(2259)
|                       |-{console-kit-dae}(2260)
|                       |-{console-kit-dae}(2261)
|                       |-{console-kit-dae}(2262)
|                       |-{console-kit-dae}(2263)
|                       |-{console-kit-dae}(2264)
|                       |-{console-kit-dae}(22100)
|                       |-{console-kit-dae}(2266)
|                       |-{console-kit-dae}(2267)
|                       |-{console-kit-dae}(2268)
|                       |-{console-kit-dae}(2269)
|                       |-{console-kit-dae}(2270)
|                       |-{console-kit-dae}(2271)
|                       |-{console-kit-dae}(2272)
|                       |-{console-kit-dae}(2273)
|                       |-{console-kit-dae}(2274)
|                       |-{console-kit-dae}(2275)
|                       |-{console-kit-dae}(2276)
|                       |-{console-kit-dae}(2277)
|                       |-{console-kit-dae}(2278)
|                       |-{console-kit-dae}(2279)
|                       |-{console-kit-dae}(2280)
|                       |-{console-kit-dae}(2281)
|                       |-{console-kit-dae}(2282)
|                       |-{console-kit-dae}(2283)
|                       |-{console-kit-dae}(2284)
|                       |-{console-kit-dae}(2285)
|                       |-{console-kit-dae}(2286)
|                       |-{console-kit-dae}(2287)
|                       |-{console-kit-dae}(2288)
|                       |-{console-kit-dae}(2289)
|                       |-{console-kit-dae}(2290)
|                       |-{console-kit-dae}(2291)
|                       |-{console-kit-dae}(2292)
|                       |-{console-kit-dae}(2293)
|                       |-{console-kit-dae}(2294)
|                       |-{console-kit-dae}(2295)
|                       |-{console-kit-dae}(2296)
|                       |-{console-kit-dae}(2297)
|                       |-{console-kit-dae}(2298)
|                       |-{console-kit-dae}(2299)
|                       |-{console-kit-dae}(2301)
|                       `-{console-kit-dae}(2305)
|-cron(2500)
|-dbus-daemon(2120)
|-dbus-daemon(2826)
|-dbus-launch(2674)
|-evolution-addre(4039)-+-{evolution-addre}(4049)
|                       `-{evolution-addre}(4050)
|-evolution-calen(4018)-+-{evolution-calen}(4033)
|                       `-{evolution-calen}(4035)
|-famd(3604)
|-gconfd-2(3964)
|-gdm3(2178)-+-gdm-simple-slav(2199)-+-Xorg(2216)
|            |                       |-gdm-session-wor(2230)-+-gnome-session(2501)+
|            |                       |                       |-{gdm-session-wor}(2+
|            |                       |                       `-{gdm-session-wor}(2+
|            |                       `-{gdm-simple-slav}(2217)
|            `-{gdm3}(2209)
|-getty(3902)
|-getty(3903)
|-getty(3904)
|-getty(3905)
|-getty(3906)
|-getty(3907)
|-gnome-keyring-d(3292)-+-{gnome-keyring-d}(3293)
|                       |-{gnome-keyring-d}(3306)
|                       |-{gnome-keyring-d}(3307)
|                       |-{gnome-keyring-d}(3308)
|                       |-{gnome-keyring-d}(3971)
|                       |-{gnome-keyring-d}(3983)
|                       `-{gnome-keyring-d}(4072)
|-gnome-shell-cal(4064)-+-{gnome-shell-cal}(4068)
|                       `-{gnome-shell-cal}(4069)
|-gnome-volume-ma(3974)
|-goa-daemon(4052)---{goa-daemon}(4054)
|-gpm(2579)
|-gsd-printer(3812)---{gsd-printer}(3825)
|-gvfs-afc-volume(3914)---{gvfs-afc-volume}(3915)
|-gvfs-gdu-volume(38100)
|-gvfs-gphoto2-vo(3917)
|-gvfsd(3395)
|-hald(3977)-+-hald-runner(3978)-+-hald-addon-acpi(4032)
|            |                   |-hald-addon-cpuf(4031)
|            |                   |-hald-addon-inpu(4016)
|            |                   |-hald-addon-rfki(4019)
|            |                   |-hald-addon-stor(4030)
|            |                   `-{hald-runner}(3985)
|            `-{hald}(3981)
|-iscsid(1972)
|-iscsid(1973)
|-libvirtd(2649)-+-{libvirtd}(21000)
|                |-{libvirtd}(21001)
|                |-{libvirtd}(21002)
|                |-{libvirtd}(21003)
|                |-{libvirtd}(21004)
|                |-{libvirtd}(21005)
|                |-{libvirtd}(21006)
|                |-{libvirtd}(21007)
|                |-{libvirtd}(21008)
|                `-{libvirtd}(21009)
|-minissdpd(3868)
|-mission-control(4066)-+-{mission-control}(4071)
|                       `-{mission-control}(4073)
|-modem-manager(2211)
|-mono(4445)-+-{mono}(4446)
|            |-{mono}(4448)
|            |-{mono}(4449)
|            `-{mono}(4450)
|-mysqld_safe(2874)-+-logger(3189)
|                   `-mysqld(3188)-+-{mysqld}(3236)
|                                  |-{mysqld}(3237)
|                                  |-{mysqld}(3238)
|                                  |-{mysqld}(3239)
|                                  |-{mysqld}(3240)
|                                  |-{mysqld}(3241)
|                                  |-{mysqld}(3242)
|                                  |-{mysqld}(3243)
|                                  |-{mysqld}(3244)
|                                  |-{mysqld}(3245)
|                                  |-{mysqld}(3275)
|                                  |-{mysqld}(3276)
|                                  |-{mysqld}(3277)
|                                  |-{mysqld}(3278)
|                                  |-{mysqld}(3309)
|                                  `-{mysqld}(3332)
|-pcscd(3441)---{pcscd}(3445)
|-polkitd(2198)---{polkitd}(2208)
|-pulseaudio(3788)-+-{pulseaudio}(3809)
|                  `-{pulseaudio}(3810)
|-rpcbind(1795)
|-rtkit-daemon(3790)-+-{rtkit-daemon}(3791)
|                    `-{rtkit-daemon}(3792)
|-sshd(3712)
|-udevd(347)-+-udevd(464)
|            `-udevd(4100)
|-udisks-daemon(3874)-+-udisks-daemon(3908)
|                     |-{udisks-daemon}(3909)
|                     `-{udisks-daemon}(4056)
|-upowerd(3311)-+-{upowerd}(3315)
|               `-{upowerd}(3316)
`-wpa_supplicant(2219)
$ 4.2.36 5 505--->

regular expression — PHP

commandline session

<?php
$text = “Hello World”;
if ( preg_match( “/r.*?d/”, $text, $array ) ) {
print “<pre>n”;
print_r( $array );
print “</pre>n”;
}
?>

note: preg_match — Perform a regular expression match
source : www.phpcode.net

OUTPUT

$ 4.2.36 13 513—> php rep.php
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php5/20100525/suhosin.so’ – /usr/lib/php5/20100525/suhosin.so: cannot open shared object file: No such file or directory in Unknown on line 0
<pre>
Array
(
[0] => rld
)
</pre>
$ 4.2.36 14 514—>

Examining /etc/passwd file in Typical Unix-like OS

ABOUT /etc/passwd file

The /etc/passwd file is a text-based database of information about users that may log into the system or other operating system user identities that own running processes.

In many operating systems this file is just one of many possible back-ends for the more general passwd name service.

The file's name originates from one of its initial functions as it contained the data used to verify passwords of user accounts. However, on modern Unix systems the security-sensitive password information is instead often stored in a different file using shadow passwords, or other database implementations.

The /etc/passwd file typically has file system permissions that allow it to be readable by all users of the system (world-readable), although it may only be modified by the superuser or by using a few special purpose privileged commands.

The /etc/passwd file is a text file with one record per line, each describing a user account. Each record consists of seven fields separated by colons. The ordering of the records within the file is generally unimportant.


The fields, in order from left to right, are:

User name: the string a user would type in when logging into the operating system: the logname. Must be unique across users listed in the file.

Information used to validate a user's password; in most modern uses, this field is usually set to "x" (or "*", or some other indicator) with the actual password information being stored in a separate shadow 
password file. On Linux systems, setting this field to an asterisk ("*") is a common way to disable direct logins to an account while still preserving its name, while another possible value is "*NP*" which indicates to use an NIS server to obtain the password.[2] Without password shadowing in effect, this field would typically contain a cryptographic hash of the user's password (in combination with a salt).

user identifier number, used by the operating system for internal purposes. It need not be unique.

group identifier number, which identifies the primary group of the user; all files that are created by this user may initially be accessible to this group.

Gecos field, commentary that describes the person or account. Typically, this is a set of comma-separated values including the user's full name and contact details.

Path to the user's home directory.

Program that is started every time the user logs into the system. For an interactive user, this is usually one of the system's command line interpreters (shells).

RELATED SHELL SESSION EXPOSURE

[bash]
$cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:100534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/bin/sh
man:x:6:12:man:/var/cache/man:/bin/sh
lp:x:7:7:lp:/var/spool/lpd:/bin/sh
mail:x:8:8:mail:/var/mail:/bin/sh
news:x:9:9:news:/var/spool/news:/bin/sh
uucp:x:10:10:uucp:/var/spool/uucp:/bin/sh
proxy:x:13:13:proxy:/bin:/bin/sh
www-data:x:33:33:www-data:/var/www:/bin/sh
backup:x:34:34:backup:/var/backups:/bin/sh
list:x:38:38:Mailing List Manager:/var/list:/bin/sh
irc:x:39:39:ircd:/var/run/ircd:/bin/sh
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/bin/sh
nobody:x:100534:100534:nobody:/nonexistent:/bin/sh
libuuid:x:100:101::/var/lib/libuuid:/bin/sh
jeffrin:x:1000:1000:Jeffrin Jose Thalakkottoor,,,:/home/jeffrin:/bin/bash
messagebus:x:101:103::/var/run/dbus:/bin/false
avahi:x:102:105:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/bin/false
festival:x:103:29::/home/festival:/bin/false
usbmux:x:104:46:usbmux daemon,,,:/home/usbmux:/bin/false
saned:x:106:113::/home/saned:/bin/false
gdm:x:107:114:Gnome Display Manager:/var/lib/gdm:/bin/false
sshd:x:108:100534::/var/run/sshd:/usr/sbin/nologin
haldaemon:x:110:116:Hardware abstraction layer,,,:/var/run/hald:/bin/false
Debian-exim:x:111:118::/var/spool/exim4:/bin/false
mysql:x:112:119:MySQL Server,,,:/var/lib/mysql:/bin/false
pulse:x:109:115:PulseAudio daemon,,,:/var/run/pulse:/bin/false
rtkit:x:113:124:RealtimeKit,,,:/proc:/bin/false
jetty:x:114:125::/usr/share/jetty:/bin/false
klog:x:115:127::/home/klog:/bin/false
syslog:x:116:128::/home/syslog:/bin/false
colord:x:117:129:colord colour management daemon,,,:/var/lib/colord:/bin/false
vde2-net:x:118:132::/var/run/vde2:/bin/false
fetchmail:x:119:100534::/var/lib/fetchmail:/bin/false
libvirt-qemu:x:120:131:Libvirt Qemu,,,:/var/lib/libvirt:/bin/false
speech-dispatcher:x:121:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/sh
Debian-gdm:x:105:111:Gnome Display Manager:/var/lib/gdm3:/bin/false
kdm:x:122:100534::/home/kdm:/bin/false
snmp:x:123:134::/var/lib/snmp:/bin/false
$

[/bash]

RELATED SOURCE CODE EXPOSURE

[code lang=”c”]
/*
* new_password – validate old password and replace with new (both old and
* new in global "char crypt_passwd[128]")
*/
static int new_password (const struct passwd *pw)
{
char *clear; /* Pointer to clear text */
char *cipher; /* Pointer to cipher text */
const char *salt; /* Pointer to new salt */
char *cp; /* Pointer to getpass() response */
char orig[200]; /* Original password */
char pass[200]; /* New password */
int i; /* Counter for retries */
bool warned;
int pass_max_len = -1;
const char *method;

#ifdef HAVE_LIBCRACK_HIST
int HistUpdate (const char *, const char *);
#endif /* HAVE_LIBCRACK_HIST */

/*
* Authenticate the user. The user will be prompted for their own
* password.
*/

if (!amroot && (‘\0’ != crypt_passwd[0])) {
clear = getpass (_("Old password: "));
if (NULL == clear) {
return -1;
}

cipher = pw_encrypt (clear, crypt_passwd);

if (NULL == cipher) {
strzero (clear);
fprintf (stderr,
_("%s: failed to crypt password with previous salt: %s\n"),
Prog, strerror (errno));
SYSLOG ((LOG_INFO,
"Failed to crypt password with previous salt of user ‘%s’",
pw->pw_name));
return -1;
}

if (strcmp (cipher, crypt_passwd) != 0) {
strzero (clear);
strzero (cipher);
SYSLOG ((LOG_WARN, "incorrect password for %s",
pw->pw_name));
(void) sleep (1);
(void) fprintf (stderr,
_("Incorrect password for %s.\n"),
pw->pw_name);
return -1;
}
STRFCPY (orig, clear);
strzero (clear);
strzero (cipher);
} else {
orig[0] = ‘\0’;
}

/*
* Get the new password. The user is prompted for the new password
* and has five tries to get it right. The password will be tested
* for strength, unless it is the root user. This provides an escape
* for initial login passwords.
*/
method = getdef_str ("ENCRYPT_METHOD");
if (NULL == method) {
if (!getdef_bool ("MD5_CRYPT_ENAB")) {
pass_max_len = getdef_num ("PASS_MAX_LEN", 8);
}
} else {
if ( (strcmp (method, "MD5") == 0)
#ifdef USE_SHA_CRYPT
|| (strcmp (method, "SHA256") == 0)
|| (strcmp (method, "SHA512") == 0)
#endif /* USE_SHA_CRYPT */
) {
pass_max_len = -1;
} else {
pass_max_len = getdef_num ("PASS_MAX_LEN", 8);
}
}
if (!qflg) {
if (pass_max_len == -1) {
(void) printf (_(
"Enter the new password (minimum of %d characters)\n"
"Please use a combination of upper and lower case letters and numbers.\n"),
getdef_num ("PASS_MIN_LEN", 5));
} else {
(void) printf (_(
"Enter the new password (minimum of %d, maximum of %d characters)\n"
"Please use a combination of upper and lower case letters and numbers.\n"),
getdef_num ("PASS_MIN_LEN", 5), pass_max_len);
}
}

warned = false;
for (i = getdef_num ("PASS_CHANGE_TRIES", 5); i > 0; i–) {
cp = getpass (_("New password: "));
if (NULL == cp) {
memzero (orig, sizeof orig);
return -1;
}
if (warned && (strcmp (pass, cp) != 0)) {
warned = false;
}
STRFCPY (pass, cp);
strzero (cp);

if (!amroot && (!obscure (orig, pass, pw) || reuse (pass, pw))) {
(void) puts (_("Try again."));
continue;
}

/*
* If enabled, warn about weak passwords even if you are
* root (enter this password again to use it anyway).
* –marekm
*/
if (amroot && !warned && getdef_bool ("PASS_ALWAYS_WARN")
&& (!obscure (orig, pass, pw) || reuse (pass, pw))) {
(void) puts (_("\nWarning: weak password (enter it again to use it anyway)."));
warned = true;
continue;
}
cp = getpass (_("Re-enter new password: "));
if (NULL == cp) {
memzero (orig, sizeof orig);
return -1;
}
if (strcmp (cp, pass) != 0) {
(void) fputs (_("They don’t match; try again.\n"), stderr);
} else {
strzero (cp);
break;
}
}
memzero (orig, sizeof orig);

if (i == 0) {
memzero (pass, sizeof pass);
return -1;
}

/*
* Encrypt the password, then wipe the cleartext password.
*/
salt = crypt_make_salt (NULL, NULL);
cp = pw_encrypt (pass, salt);
memzero (pass, sizeof pass);

if (NULL == cp) {
fprintf (stderr,
_("%s: failed to crypt password with salt ‘%s’: %s\n"),
Prog, salt, strerror (errno));
return -1;
}

#ifdef HAVE_LIBCRACK_HIST
HistUpdate (pw->pw_name, crypt_passwd);
#endif /* HAVE_LIBCRACK_HIST */
STRFCPY (crypt_passwd, cp);
return 0;
}

[/code]

SOURCE CODE FROM DEBIAN SOURECE PACKAGE NAMED “shadow”

LINKS (SOURCE AND OTHER)

https://en.wikipedia.org/wiki/Passwd
https://www.ibm.com/support/knowledgecenter/en/ssw_aix_72/com.ibm.aix.security/passwords_etc_passwd_file.htm
https://www.digitalocean.com/community/tutorials/how-to-use-passwd-and-adduser-to-manage-passwords-on-a-linux-vps

GREP SEARCH STRING USING BACKTICK

$ 4.2.36 7 507---> grep `whoami` algorithm.c
     to jeffrin@rocketmail.com
$ 4.2.36 8 508--->

$ 4.2.36 8 508---> whoami
jeffrin
$ 4.2.36 9 509--->


$ 4.2.36 3 503---> grep ls ls2.wav
Binary file ls2.wav matches
$ 4.2.36 4 504---> grep `ls` ls2.wav
grep: 12: Is a directory
grep: 2008: Is a directory
grep: 2010: Is a directory
grep: 313143-The: No such file or directory
grep: Linux: No such file or directory
grep: Frame: No such file or directory
grep: Buffer: No such file or directory
grep: Device: No such file or directory
grep: Subsystem.pdf: No such file or directory
grep: Academy: No such file or directory
grep: Awards: No such file or directory
grep: 2012: No such file or directory
grep: Road: No such file or directory
grep: to: No such file or directory
grep: the: No such file or directory
grep: Oscars: No such file or directory
grep: IMDb_files: No such file or directory
grep: Academy: No such file or directory
grep: Awards: No such file or directory
grep: 2012: No such file or directory
grep: Road: No such file or directory
grep: to: No such file or directory
grep: the: No such file or directory
grep: Oscars: No such file or directory
grep: --: No such file or directory
grep: IMDb.html: No such file or directory
grep: ai: Is a directory
grep: american.saintb: Is a directory
grep: Aptana: No such file or directory
grep: Studio: No such file or directory
grep: 3: No such file or directory
grep: Workspace: No such file or directory
grep: arduino: Is a directory
grep: Artificial: No such file or directory
grep: Intelligence: No such file or directory
^C
$ 4.2.36 5 505--->

SEARCH AND REPLACE USING SED

commandline session

$ 4.2.36 13 513---> cat math.html
<html>
<body>
<msup>
<mfenced>
<mi>a</mi>
<mo>+</mo>
<mi>b</mi>
</mfenced>
<mn>2</mn>
</msup>
</body>
</html>
$ 4.2.36 14 514---> $ sed "s/html/HTML/g" math.html > math-new.html
bash: $: command not found
$ 4.2.36 15 515---> sed "s/html/HTML/g" math.html > math-new.html
$ 4.2.36 16 516---> cat math-new.html
<HTML>
<body>
<msup>
<mfenced>
<mi>a</mi>
<mo>+</mo>
<mi>b</mi>
</mfenced>
<mn>2</mn>
</msup>
</body>
</HTML>
$ 4.2.36 17 517--->