This can be easily done in slow/medium pace deliveries. Consider a batsman getting bowled in a no-ball or a free-hit ball and the ball remains near the batsman.
Is it allowed to hit the ball with the bat/leg by the batsman to get runs?
This situation comes under the law 37 (Obstructing the field). (emphasis mine)
Either batsman is out Obstructing the field if he wilfully attempts to obstruct or distract the fielding side by word or action. In particular, but not solely, it shall be regarded as obstruction and either batsman will be out Obstructing the field if while the ball is in play and after the striker has completed the act of playing the ball, as defined in Law 33.1, he wilfully strikes the ball with
(i) a hand not holding the bat, unless this is in order to avoid injury. See also Law 33.2 (Not out Handled the ball).
(ii) any other part of his person or with his bat. See also Law 34 (Hit the ball twice).
So in the given situation once the ball is bowled (here either no ball or free hit), it is in play irrespective of the ball touches the bat until the umpire declares it a dead 1. So if the batsman hit the ball after he gets bowled, he is actually obstructing the field because fielders (mostly the bowler himself in such situations) rush to the ball to take it to prevent batsmen taking runs. So the batsman who is hitting the ball is out Obstructing the field.
1. Normally the ball becomes dead after it is thrown to the keeper and batsmen are into the crease or a batsman is out