Query for recent images across multiple posts

You can use get_posts or create a new WP_Query using the following args (or something similar).

<?php 
$args = array(
   'post_type'      => 'attachment', // attachment post type
   'post_status'    => 'inherit', // all attachments have this post status
   'post_mime_type' => 'image', // make sure you get images only
   'posts_per_page' => 5 // however many images you want
);

When looping through the images, you can use wp_get_attachment_image or wp_get_attachment_image_src to grab the image HTML or image URL respectively.

<?php
$attachments = get_posts($args); // args from above
foreach($attachments as $a)
{
   // replace `thumbnail` with an appropriate image size
   echo wp_get_attachment_image($a->ID, 'thumbnail');
}

You’ll also want to read up the widgets API for creating widget. The codex has a basic example. There’s also quite a few tutorials out there, here’s one I wrote.