Sunday, June 28, 2020

Software development process

Waterfall model

   It will be used when there are clear requirements and fixed scope of a project.

   1. Collect & Analyze requirements
        clarify with stakeholders, detailed documented thoroughly
  2. Architecture definition
        - its blue print of a product.
        - which packages and components will form our system
       - what are fundamental types of each component
       - How the interaction with each component
       - is software secure, performance, error cases handled  and robust.
       - Is system design modular for future extension
       - Any third party components will be used, how is there licensing agreement.
  3. Impelementation
       - coding
       - unit testing
  4. Verification
       - All requirements implemented based on requirement agreement.
       - Functional testing
       - Performance validation
       - Security
       - User friendliness.
 5. Maintanence phase
       - Fixing customer bugs, enhancement etc.

 Agile Framework

It will be used when the requirement are unstable and may change frequently.
1. Scrum
2. Kanban
3. Test driven development(TDD) 

Thursday, June 25, 2020

gdb with release binary

debugging stripped binary by using disasamble the assmbly code

no symbols binary debig

Write below code into test.c
//----------------------------------
#include<stdio.h>

void fun(int x)
{
        int a = 10;
        printf("%d\n", a+x);
}
int main()
{
        int x = 5;
        fun(5);
        return 0;
}
//-----------------------------
-> compile with
#gcc -O3 test.c -o test

-> Look for a symbols using nm command
# nm test
0000000000201010 B __bss_start
0000000000201010 b completed.7698
                 w __cxa_finalize@@GLIBC_2.2.5
0000000000201000 D __data_start
0000000000201000 W data_start
00000000000005c0 t deregister_tm_clones
0000000000000650 t __do_global_dtors_aux
0000000000200dc0 t __do_global_dtors_aux_fini_array_entry
0000000000201008 D __dso_handle
0000000000200dc8 d _DYNAMIC
0000000000201010 D _edata
0000000000201018 B _end
0000000000000734 T _fini
0000000000000690 t frame_dummy
0000000000200db8 t __frame_dummy_init_array_entry
00000000000008a4 r __FRAME_END__
00000000000006a0 T fun
0000000000200fb8 d _GLOBAL_OFFSET_TABLE_
                 w __gmon_start__
0000000000000748 r __GNU_EH_FRAME_HDR
0000000000000510 T _init
0000000000200dc0 t __init_array_end
0000000000200db8 t __init_array_start
0000000000000740 R _IO_stdin_used
                 w _ITM_deregisterTMCloneTable
                 w _ITM_registerTMCloneTable
0000000000000730 T __libc_csu_fini
00000000000006c0 T __libc_csu_init
                 U __libc_start_main@@GLIBC_2.2.5
0000000000000560 T main
                 U __printf_chk@@GLIBC_2.3.4
0000000000000600 t register_tm_clones
0000000000000590 T _start
0000000000201010 D __TMC_END__


-> Remove symbols using strip -s
# strip -s test
-> Check for symbols
#nm test
nm: test: no symbols

-> run gdb for test
 #gdb test
GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from test...(no debugging symbols found)...done.
(gdb) b main
Function "main" not defined.

Lets start how to debug

-> Locate entry point with 'nfo file'
    (gdb) info file
Symbols from "/home/bkotha/tt/test".
Local exec file:
        `/home/bkotha/tt/test', file type elf64-x86-64.
        Entry point: 0x590
        ----
(gdb)

-> now set the break point at Entry point address
(gdb) b 0x590
   Breakpoint 1 (0x590)

-> then do the disasamble code
(gdb)disas


GDB

To debug a C or C++ application with gdb, built in debug mode i.e -g compiling option.
gdb commands 


-g in compilation: will enable debug symbols into binary.

Ex: gcc -g mytest.c  or gcc -g  test.c -o test
      g++ -g mytest.cpp or  g++ -g test.cpp -o test
1. start gdb with executable and set the break point and run  :
    #gdb test
    (gdb) b main # to set the break point at main function start
     (gdb) run  # program start executes 
2. start gdb without process and add process with 'file'.
     #gdb
     (gdb) file test # start the test executable for debugging 

3. Passing console arguments to process with run 
     (gdb) run  abc 3 # abc , 3 are command line arguments for test program.  

Back trace / stack frames : using bt
4. On break point / core parser gdb running out we can see current stack trace
       (gdb)bt
      It will list stack frames with frame id for each stack frame.
4.1  list each frame with f num
     (gdb) f 4 # here 4 is 4th stack frame listed in bt

Break Points: b , break, br any of this keywords can be used to set the break points
5.  Adding break point with filename with line number
     (gdb) b test.c:10  # break point at line number 10
6. Adding breakpoint with function names
      (gdb) break fun1   #fun1 is function in test.c
     (gdb) b myclass::fun2   #fun2 is myclass member function
6.1  break with memory address
       (gdb)b *(memoryAddress)  # debug symbol address instead variable or function.
7. List all break points
      (gdb) info break  # list all break points with break point numbers in sequence.
8. Delete/Remove breakpoint using d
      (gdb)d 3  #here 3 is the 3rd break point
9. traverse to next step or next break point &  step in  using n, c & s
      (gdb) s
      (gdb) n
      (gdb) c
10.  Print the values with p or print keyword
      (gdb) print iVar   #iVar is the variable
      (gdb) p fVal    #fVal is a variable
11. To set the values for variables using 'set'
       (gdb)set iVar=20
       (gdb)p iVar  # iVar will print 20
12. Execute the global functions after breakpoint hit
       (gdb)p myglobalFun  #myglobalFun is a global function can be run here
13. Listing the source code after some line number or function content  using 'list'
      (gdb)list 10
      (gdb)list myglobalFun
14.  Print the current debug code line numbers using 'frame'
      (gdb)frame
15. Quit from debug console qith q or quit key word
      (gdb)quit

x Command: ' x/FMT Address '
16. x command list the region of memory with specified address content in specified format.
     (gdb)x/100i $sp   # $sp is current stack pointer address, 100i - denotes the 100 address spaces code with disassemble code.
     (gdb)x/20s 0x435281720   # 20 lines code from address with code in string format
      (gdb)x/x  display in hexadecimal
      (gdb)x/d  display in decimal format
      (gdb)x/c display with charectors format
  help for x u can check in gdb
        (gdb) help x

Multithreading debug:
In multi threading  debugging mostly thread will share code, data segment from process space only thread specific it will be having stack content, so needs to debug only stack data.
17. To list the threads info using 'info threads'
     (gdb)info threads   # which will list all threads with thread id
18. To check all threads stack traces ' thread apply all bt '
      (gdb) thread apply all bt
19.  To check particular thread stack trace first set the treat using 'thread <tread id>' listed with 'info threads' the do bt for stack trace of that thread
      (gdb)thread 0x12463097   #0x12463097 thread id 
      (gdb) bt 


debug for release/ stripped / no symbols binary using gdb

20. With gdb will do 'info file', it lists Entry point address for program. set the break point at entry point address,  then do the 'disas' will list assembly code will be having main function address.

with assembly code try to under stand or match ur function names and data to under stand the flow.
more info click on link debug for release/ stripped / no symbols binary using gdb with more links in it



Port forwarding issues and port collusion by more then one process

Port forwarding script to identify collusions  Identifying local and remote port forwarding processes, as well as checking for potential col...